providers/aws: instance, nat, internet gateway

This commit is contained in:
Mitchell Hashimoto 2016-05-13 11:27:23 -07:00
parent 830708a882
commit 884980da1a
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
8 changed files with 117 additions and 2 deletions

View File

@ -0,0 +1,29 @@
package aws
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSInstance_importBasic(t *testing.T) {
resourceName := "aws_instance.foo"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccInstanceConfigVPC,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"associate_public_ip_address", "user_data"},
},
},
})
}

View File

@ -0,0 +1,28 @@
package aws
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSInternetGateway_importBasic(t *testing.T) {
resourceName := "aws_internet_gateway.foo"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInternetGatewayDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccInternetGatewayConfig,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -0,0 +1,28 @@
package aws
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSNatGateway_importBasic(t *testing.T) {
resourceName := "aws_nat_gateway.gateway"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNatGatewayDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNatGatewayConfig,
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -24,6 +24,9 @@ func resourceAwsInstance() *schema.Resource {
Read: resourceAwsInstanceRead,
Update: resourceAwsInstanceUpdate,
Delete: resourceAwsInstanceDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
SchemaVersion: 1,
MigrateState: resourceAwsInstanceMigrateState,

View File

@ -18,6 +18,9 @@ func resourceAwsInternetGateway() *schema.Resource {
Read: resourceAwsInternetGatewayRead,
Update: resourceAwsInternetGatewayUpdate,
Delete: resourceAwsInternetGatewayDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"vpc_id": &schema.Schema{

View File

@ -18,6 +18,9 @@ func resourceAwsNatGateway() *schema.Resource {
Create: resourceAwsNatGatewayCreate,
Read: resourceAwsNatGatewayRead,
Delete: resourceAwsNatGatewayDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"allocation_id": &schema.Schema{

View File

@ -153,7 +153,12 @@ type TestStep struct {
// ImportStateVerify, if true, will also check that the state values
// that are finally put into the state after import match for all the
// IDs returned by the Import.
ImportStateVerify bool
//
// ImportStateVerifyIgnore are fields that should not be verified to
// be equal. These can be set to ephemeral fields or fields that can't
// be refreshed and don't matter.
ImportStateVerify bool
ImportStateVerifyIgnore []string
}
// Test performs an acceptance test on a resource.

View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"github.com/davecgh/go-spew/spew"
"github.com/hashicorp/terraform/terraform"
@ -91,6 +92,21 @@ func testStepImportState(
// Compare their attributes
actual := r.Primary.Attributes
expected := oldR.Primary.Attributes
// Remove fields we're ignoring
for _, v := range step.ImportStateVerifyIgnore {
for k, _ := range actual {
if strings.HasPrefix(k, v) {
delete(actual, k)
}
}
for k, _ := range expected {
if strings.HasPrefix(k, v) {
delete(expected, k)
}
}
}
if !reflect.DeepEqual(actual, expected) {
// Determine only the different attributes
for k, v := range expected {
@ -103,7 +119,7 @@ func testStepImportState(
spewConf := spew.NewDefaultConfig()
spewConf.SortKeys = true
return state, fmt.Errorf(
"Attributes not equivalent. Difference is shown below. Top is actual, bottom is expected."+
"ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected."+
"\n\n%s\n\n%s",
spewConf.Sdump(actual), spewConf.Sdump(expected))
}