providers/aws: instance, nat, internet gateway
This commit is contained in:
parent
830708a882
commit
884980da1a
|
@ -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"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -24,6 +24,9 @@ func resourceAwsInstance() *schema.Resource {
|
||||||
Read: resourceAwsInstanceRead,
|
Read: resourceAwsInstanceRead,
|
||||||
Update: resourceAwsInstanceUpdate,
|
Update: resourceAwsInstanceUpdate,
|
||||||
Delete: resourceAwsInstanceDelete,
|
Delete: resourceAwsInstanceDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
SchemaVersion: 1,
|
SchemaVersion: 1,
|
||||||
MigrateState: resourceAwsInstanceMigrateState,
|
MigrateState: resourceAwsInstanceMigrateState,
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceAwsInternetGateway() *schema.Resource {
|
||||||
Read: resourceAwsInternetGatewayRead,
|
Read: resourceAwsInternetGatewayRead,
|
||||||
Update: resourceAwsInternetGatewayUpdate,
|
Update: resourceAwsInternetGatewayUpdate,
|
||||||
Delete: resourceAwsInternetGatewayDelete,
|
Delete: resourceAwsInternetGatewayDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"vpc_id": &schema.Schema{
|
"vpc_id": &schema.Schema{
|
||||||
|
|
|
@ -18,6 +18,9 @@ func resourceAwsNatGateway() *schema.Resource {
|
||||||
Create: resourceAwsNatGatewayCreate,
|
Create: resourceAwsNatGatewayCreate,
|
||||||
Read: resourceAwsNatGatewayRead,
|
Read: resourceAwsNatGatewayRead,
|
||||||
Delete: resourceAwsNatGatewayDelete,
|
Delete: resourceAwsNatGatewayDelete,
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"allocation_id": &schema.Schema{
|
"allocation_id": &schema.Schema{
|
||||||
|
|
|
@ -153,7 +153,12 @@ type TestStep struct {
|
||||||
// ImportStateVerify, if true, will also check that the state values
|
// ImportStateVerify, if true, will also check that the state values
|
||||||
// that are finally put into the state after import match for all the
|
// that are finally put into the state after import match for all the
|
||||||
// IDs returned by the Import.
|
// 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.
|
// Test performs an acceptance test on a resource.
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
@ -91,6 +92,21 @@ func testStepImportState(
|
||||||
// Compare their attributes
|
// Compare their attributes
|
||||||
actual := r.Primary.Attributes
|
actual := r.Primary.Attributes
|
||||||
expected := oldR.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) {
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
// Determine only the different attributes
|
// Determine only the different attributes
|
||||||
for k, v := range expected {
|
for k, v := range expected {
|
||||||
|
@ -103,7 +119,7 @@ func testStepImportState(
|
||||||
spewConf := spew.NewDefaultConfig()
|
spewConf := spew.NewDefaultConfig()
|
||||||
spewConf.SortKeys = true
|
spewConf.SortKeys = true
|
||||||
return state, fmt.Errorf(
|
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",
|
"\n\n%s\n\n%s",
|
||||||
spewConf.Sdump(actual), spewConf.Sdump(expected))
|
spewConf.Sdump(actual), spewConf.Sdump(expected))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue