From b7d4767dd679ff81cfdf53c2cc5d8eeabab9112c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 May 2016 13:10:30 -0700 Subject: [PATCH 01/24] helper/schema: pass through import state func --- helper/schema/resource_importer.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/helper/schema/resource_importer.go b/helper/schema/resource_importer.go index 69d66afd9..5dada3caf 100644 --- a/helper/schema/resource_importer.go +++ b/helper/schema/resource_importer.go @@ -43,3 +43,10 @@ type StateFunc func(*ResourceData, interface{}) ([]*ResourceData, error) func (r *ResourceImporter) InternalValidate() error { return nil } + +// ImportStatePassthrough is an implementation of StateFunc that can be +// used to simply pass the ID directly through. This should be used only +// in the case that an ID-only refresh is possible. +func ImportStatePassthrough(d *ResourceData, m interface{}) ([]*ResourceData, error) { + return []*ResourceData{d}, nil +} From 420e13d2f29eb24e31606864a556a9825f44c213 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 11 May 2016 13:10:36 -0700 Subject: [PATCH 02/24] providers/aws: eip uses passthrough importstate --- builtin/providers/aws/resource_aws_eip.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/builtin/providers/aws/resource_aws_eip.go b/builtin/providers/aws/resource_aws_eip.go index 819c4a49f..89b0094fd 100644 --- a/builtin/providers/aws/resource_aws_eip.go +++ b/builtin/providers/aws/resource_aws_eip.go @@ -20,7 +20,7 @@ func resourceAwsEip() *schema.Resource { Update: resourceAwsEipUpdate, Delete: resourceAwsEipDelete, Importer: &schema.ResourceImporter{ - State: resourceAwsEipImportState, + State: schema.ImportStatePassthrough, }, Schema: map[string]*schema.Schema{ @@ -292,12 +292,6 @@ func resourceAwsEipDelete(d *schema.ResourceData, meta interface{}) error { }) } -func resourceAwsEipImportState( - d *schema.ResourceData, - meta interface{}) ([]*schema.ResourceData, error) { - return []*schema.ResourceData{d}, nil -} - func resourceAwsEipDomain(d *schema.ResourceData) string { if v, ok := d.GetOk("domain"); ok { return v.(string) From da353c3637cff90a0dbd4f9905cef537f3bae45f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 May 2016 17:57:12 -0700 Subject: [PATCH 03/24] aws/aws_vpc: import --- builtin/providers/aws/import_aws_vpc_test.go | 28 ++++++++++++++++++++ builtin/providers/aws/resource_aws_vpc.go | 3 +++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_vpc_test.go diff --git a/builtin/providers/aws/import_aws_vpc_test.go b/builtin/providers/aws/import_aws_vpc_test.go new file mode 100644 index 000000000..e940b3ddc --- /dev/null +++ b/builtin/providers/aws/import_aws_vpc_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSVpc_importBasic(t *testing.T) { + resourceName := "aws_vpc.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccVpcConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index e6e3b94a5..caf39f267 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -18,6 +18,9 @@ func resourceAwsVpc() *schema.Resource { Read: resourceAwsVpcRead, Update: resourceAwsVpcUpdate, Delete: resourceAwsVpcDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "cidr_block": &schema.Schema{ From b75d5bb46d2353bc17064d6c1c77675094c2eb4d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 May 2016 18:06:07 -0700 Subject: [PATCH 04/24] providers/aws: vpc dhcp options --- .../aws/import_aws_vpc_dhcp_options_test.go | 27 +++++++++++++++++++ .../aws/resource_aws_vpc_dhcp_options.go | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 builtin/providers/aws/import_aws_vpc_dhcp_options_test.go diff --git a/builtin/providers/aws/import_aws_vpc_dhcp_options_test.go b/builtin/providers/aws/import_aws_vpc_dhcp_options_test.go new file mode 100644 index 000000000..e0f605f28 --- /dev/null +++ b/builtin/providers/aws/import_aws_vpc_dhcp_options_test.go @@ -0,0 +1,27 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSDHCPOptions_importBasic(t *testing.T) { + resourceName := "aws_vpc_dhcp_options.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDHCPOptionsConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go index 156654b49..16c33fd4d 100644 --- a/builtin/providers/aws/resource_aws_vpc_dhcp_options.go +++ b/builtin/providers/aws/resource_aws_vpc_dhcp_options.go @@ -19,6 +19,9 @@ func resourceAwsVpcDhcpOptions() *schema.Resource { Read: resourceAwsVpcDhcpOptionsRead, Update: resourceAwsVpcDhcpOptionsUpdate, Delete: resourceAwsVpcDhcpOptionsDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "domain_name": &schema.Schema{ From 91938cf55f6f915e4ccdf4d0c5689022ae1a2465 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 12 May 2016 18:15:29 -0700 Subject: [PATCH 05/24] providers/aws: resource aws_subnet import --- .../providers/aws/import_aws_subnet_test.go | 28 +++++++++++++++++++ builtin/providers/aws/resource_aws_subnet.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_subnet_test.go diff --git a/builtin/providers/aws/import_aws_subnet_test.go b/builtin/providers/aws/import_aws_subnet_test.go new file mode 100644 index 000000000..c08e4f7ed --- /dev/null +++ b/builtin/providers/aws/import_aws_subnet_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSSubnet_importBasic(t *testing.T) { + resourceName := "aws_subnet.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckSubnetDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccSubnetConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_subnet.go b/builtin/providers/aws/resource_aws_subnet.go index 34937c3c0..b9d6c42ed 100644 --- a/builtin/providers/aws/resource_aws_subnet.go +++ b/builtin/providers/aws/resource_aws_subnet.go @@ -18,6 +18,9 @@ func resourceAwsSubnet() *schema.Resource { Read: resourceAwsSubnetRead, Update: resourceAwsSubnetUpdate, Delete: resourceAwsSubnetDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "vpc_id": &schema.Schema{ From 830708a882c86fd157cb8395f1b884806e0462d1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 11:13:47 -0700 Subject: [PATCH 06/24] providers/aws: elb --- builtin/providers/aws/import_aws_elb_test.go | 28 ++++++++++++++++++++ builtin/providers/aws/resource_aws_elb.go | 3 +++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_elb_test.go diff --git a/builtin/providers/aws/import_aws_elb_test.go b/builtin/providers/aws/import_aws_elb_test.go new file mode 100644 index 000000000..8a9f2a27c --- /dev/null +++ b/builtin/providers/aws/import_aws_elb_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSELB_importBasic(t *testing.T) { + resourceName := "aws_subnet.bar" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSELBDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSELBConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_elb.go b/builtin/providers/aws/resource_aws_elb.go index 0042f5c06..332d112fe 100644 --- a/builtin/providers/aws/resource_aws_elb.go +++ b/builtin/providers/aws/resource_aws_elb.go @@ -22,6 +22,9 @@ func resourceAwsElb() *schema.Resource { Read: resourceAwsElbRead, Update: resourceAwsElbUpdate, Delete: resourceAwsElbDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ From 884980da1ab8d39196239f009a6c4efdc55d9337 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 11:27:23 -0700 Subject: [PATCH 07/24] providers/aws: instance, nat, internet gateway --- .../providers/aws/import_aws_instance_test.go | 29 +++++++++++++++++++ .../aws/import_aws_internet_gateway_test.go | 28 ++++++++++++++++++ .../aws/import_aws_nat_gateway_test.go | 28 ++++++++++++++++++ .../providers/aws/resource_aws_instance.go | 3 ++ .../aws/resource_aws_internet_gateway.go | 3 ++ .../providers/aws/resource_aws_nat_gateway.go | 3 ++ helper/resource/testing.go | 7 ++++- helper/resource/testing_import_state.go | 18 +++++++++++- 8 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 builtin/providers/aws/import_aws_instance_test.go create mode 100644 builtin/providers/aws/import_aws_internet_gateway_test.go create mode 100644 builtin/providers/aws/import_aws_nat_gateway_test.go diff --git a/builtin/providers/aws/import_aws_instance_test.go b/builtin/providers/aws/import_aws_instance_test.go new file mode 100644 index 000000000..cf1eea524 --- /dev/null +++ b/builtin/providers/aws/import_aws_instance_test.go @@ -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"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/import_aws_internet_gateway_test.go b/builtin/providers/aws/import_aws_internet_gateway_test.go new file mode 100644 index 000000000..561a730b2 --- /dev/null +++ b/builtin/providers/aws/import_aws_internet_gateway_test.go @@ -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, + }, + }, + }) +} diff --git a/builtin/providers/aws/import_aws_nat_gateway_test.go b/builtin/providers/aws/import_aws_nat_gateway_test.go new file mode 100644 index 000000000..1c1ef196e --- /dev/null +++ b/builtin/providers/aws/import_aws_nat_gateway_test.go @@ -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, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index e62df1cf3..cc44e7328 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -24,6 +24,9 @@ func resourceAwsInstance() *schema.Resource { Read: resourceAwsInstanceRead, Update: resourceAwsInstanceUpdate, Delete: resourceAwsInstanceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, SchemaVersion: 1, MigrateState: resourceAwsInstanceMigrateState, diff --git a/builtin/providers/aws/resource_aws_internet_gateway.go b/builtin/providers/aws/resource_aws_internet_gateway.go index dacb02a56..338ab0833 100644 --- a/builtin/providers/aws/resource_aws_internet_gateway.go +++ b/builtin/providers/aws/resource_aws_internet_gateway.go @@ -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{ diff --git a/builtin/providers/aws/resource_aws_nat_gateway.go b/builtin/providers/aws/resource_aws_nat_gateway.go index c57fb9f64..4ad23ad8f 100644 --- a/builtin/providers/aws/resource_aws_nat_gateway.go +++ b/builtin/providers/aws/resource_aws_nat_gateway.go @@ -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{ diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 17358f93d..f3de5fee1 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -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. diff --git a/helper/resource/testing_import_state.go b/helper/resource/testing_import_state.go index c110ec950..f16f17130 100644 --- a/helper/resource/testing_import_state.go +++ b/helper/resource/testing_import_state.go @@ -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)) } From 9cdbed11fff2cd5d9edecc6126d775b39f76107a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 11:39:08 -0700 Subject: [PATCH 08/24] providers/aws: ebs volume and autoscaling group --- .../aws/import_aws_autoscaling_group_test.go | 33 +++++++++++++++++++ .../aws/import_aws_ebs_volume_test.go | 27 +++++++++++++++ .../aws/resource_aws_autoscaling_group.go | 3 ++ .../providers/aws/resource_aws_ebs_volume.go | 3 ++ 4 files changed, 66 insertions(+) create mode 100644 builtin/providers/aws/import_aws_autoscaling_group_test.go create mode 100644 builtin/providers/aws/import_aws_ebs_volume_test.go diff --git a/builtin/providers/aws/import_aws_autoscaling_group_test.go b/builtin/providers/aws/import_aws_autoscaling_group_test.go new file mode 100644 index 000000000..920df152c --- /dev/null +++ b/builtin/providers/aws/import_aws_autoscaling_group_test.go @@ -0,0 +1,33 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSAutoScalingGroup_importBasic(t *testing.T) { + resourceName := "aws_autoscaling_group.bar" + randName := fmt.Sprintf("terraform-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSAutoScalingGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSAutoScalingGroupConfig(randName), + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "force_delete", "metrics_granularity", "wait_for_capacity_timeout"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/import_aws_ebs_volume_test.go b/builtin/providers/aws/import_aws_ebs_volume_test.go new file mode 100644 index 000000000..fd15bc241 --- /dev/null +++ b/builtin/providers/aws/import_aws_ebs_volume_test.go @@ -0,0 +1,27 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSEBSVolume_importBasic(t *testing.T) { + resourceName := "aws_ebs_volume.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAwsEbsVolumeConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_autoscaling_group.go b/builtin/providers/aws/resource_aws_autoscaling_group.go index 795d59ea3..06036b248 100644 --- a/builtin/providers/aws/resource_aws_autoscaling_group.go +++ b/builtin/providers/aws/resource_aws_autoscaling_group.go @@ -21,6 +21,9 @@ func resourceAwsAutoscalingGroup() *schema.Resource { Read: resourceAwsAutoscalingGroupRead, Update: resourceAwsAutoscalingGroupUpdate, Delete: resourceAwsAutoscalingGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ diff --git a/builtin/providers/aws/resource_aws_ebs_volume.go b/builtin/providers/aws/resource_aws_ebs_volume.go index 8dfbd0cf3..43914ef6b 100644 --- a/builtin/providers/aws/resource_aws_ebs_volume.go +++ b/builtin/providers/aws/resource_aws_ebs_volume.go @@ -19,6 +19,9 @@ func resourceAwsEbsVolume() *schema.Resource { Read: resourceAwsEbsVolumeRead, Update: resourceAWSEbsVolumeUpdate, Delete: resourceAwsEbsVolumeDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "availability_zone": &schema.Schema{ From a4e48b19c0e1f76e783d105076cc6659a9e62a89 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 11:41:50 -0700 Subject: [PATCH 09/24] providers/aws ENI import --- .../aws/import_aws_network_interface_test.go | 28 +++++++++++++++++++ .../aws/resource_aws_network_interface.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_network_interface_test.go diff --git a/builtin/providers/aws/import_aws_network_interface_test.go b/builtin/providers/aws/import_aws_network_interface_test.go new file mode 100644 index 000000000..08f22c16f --- /dev/null +++ b/builtin/providers/aws/import_aws_network_interface_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSENI_importBasic(t *testing.T) { + resourceName := "aws_network_interface.bar" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSENIDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSENIConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_network_interface.go b/builtin/providers/aws/resource_aws_network_interface.go index 7e139ea52..ccfdbfc8e 100644 --- a/builtin/providers/aws/resource_aws_network_interface.go +++ b/builtin/providers/aws/resource_aws_network_interface.go @@ -21,6 +21,9 @@ func resourceAwsNetworkInterface() *schema.Resource { Read: resourceAwsNetworkInterfaceRead, Update: resourceAwsNetworkInterfaceUpdate, Delete: resourceAwsNetworkInterfaceDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ From 08b7f672277e326f4821b28c045703bd6b518570 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 11:52:52 -0700 Subject: [PATCH 10/24] providers/aws: route table import --- .../providers/aws/import_aws_route_table.go | 46 +++++++++++++++++++ .../aws/import_aws_route_table_test.go | 37 +++++++++++++++ .../providers/aws/resource_aws_route_table.go | 3 ++ 3 files changed, 86 insertions(+) create mode 100644 builtin/providers/aws/import_aws_route_table.go create mode 100644 builtin/providers/aws/import_aws_route_table_test.go diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go new file mode 100644 index 000000000..0c877b3ef --- /dev/null +++ b/builtin/providers/aws/import_aws_route_table.go @@ -0,0 +1,46 @@ +package aws + +import ( + "fmt" + + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/schema" +) + +// Route table import also imports all the rules +func resourceAwsRouteTableImportState( + d *schema.ResourceData, + meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*AWSClient).ec2conn + + // First query the resource itself + id := d.Id() + resp, err := conn.DescribeRouteTables(&ec2.DescribeRouteTablesInput{ + RouteTableIds: []*string{&id}, + }) + if err != nil { + return nil, err + } + if len(resp.RouteTables) < 1 || resp.RouteTables[0] == nil { + return nil, fmt.Errorf("route table %s is not found", id) + } + table := resp.RouteTables[0] + + // Start building our results + results := make([]*schema.ResourceData, 1, 1+len(table.Routes)) + results[0] = d + + // Construct the routes + subResource := resourceAwsRoute() + for _, route := range table.Routes { + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_route") + d.Set("route_table_id", id) + d.Set("destination_cidr_block", route.DestinationCidrBlock) + d.SetId(routeIDHash(d, route)) + results = append(results, d) + } + + return results, nil +} diff --git a/builtin/providers/aws/import_aws_route_table_test.go b/builtin/providers/aws/import_aws_route_table_test.go new file mode 100644 index 000000000..c0a9537b9 --- /dev/null +++ b/builtin/providers/aws/import_aws_route_table_test.go @@ -0,0 +1,37 @@ +package aws + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAWSRouteTable_importBasic(t *testing.T) { + checkFn := func(s []*terraform.InstanceState) error { + // Expect 2: group, 1 rules + if len(s) != 3 { + return fmt.Errorf("bad states: %#v", s) + } + + return nil + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRouteTableDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRouteTableConfig, + }, + + resource.TestStep{ + ResourceName: "aws_route_table.foo", + ImportState: true, + ImportStateCheck: checkFn, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 477172c42..218c39bbc 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -20,6 +20,9 @@ func resourceAwsRouteTable() *schema.Resource { Read: resourceAwsRouteTableRead, Update: resourceAwsRouteTableUpdate, Delete: resourceAwsRouteTableDelete, + Importer: &schema.ResourceImporter{ + State: resourceAwsRouteTableImportState, + }, Schema: map[string]*schema.Schema{ "vpc_id": &schema.Schema{ From a1035804d433ef648ee39f680751fc1585068d6e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 12:16:03 -0700 Subject: [PATCH 11/24] providers/aws: route table import should ignore default rule --- builtin/providers/aws/import_aws_route_table.go | 5 +++++ builtin/providers/aws/import_aws_route_table_test.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go index 0c877b3ef..a1a897fa3 100644 --- a/builtin/providers/aws/import_aws_route_table.go +++ b/builtin/providers/aws/import_aws_route_table.go @@ -33,6 +33,11 @@ func resourceAwsRouteTableImportState( // Construct the routes subResource := resourceAwsRoute() for _, route := range table.Routes { + // Ignore the local/default route + if route.GatewayId != nil && *route.GatewayId == "local" { + continue + } + // Minimal data for route d := subResource.Data(nil) d.SetType("aws_route") diff --git a/builtin/providers/aws/import_aws_route_table_test.go b/builtin/providers/aws/import_aws_route_table_test.go index c0a9537b9..43727b7bb 100644 --- a/builtin/providers/aws/import_aws_route_table_test.go +++ b/builtin/providers/aws/import_aws_route_table_test.go @@ -11,7 +11,7 @@ import ( func TestAccAWSRouteTable_importBasic(t *testing.T) { checkFn := func(s []*terraform.InstanceState) error { // Expect 2: group, 1 rules - if len(s) != 3 { + if len(s) != 2 { return fmt.Errorf("bad states: %#v", s) } From ab7b5dab2dd8b0e1c8c846f7433bf3440ba98da1 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 12:26:18 -0700 Subject: [PATCH 12/24] providers/aws: route tables import assocations --- .../providers/aws/import_aws_route_table.go | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go index a1a897fa3..c6e694773 100644 --- a/builtin/providers/aws/import_aws_route_table.go +++ b/builtin/providers/aws/import_aws_route_table.go @@ -27,24 +27,45 @@ func resourceAwsRouteTableImportState( table := resp.RouteTables[0] // Start building our results - results := make([]*schema.ResourceData, 1, 1+len(table.Routes)) + results := make([]*schema.ResourceData, 1, + 1+len(table.Associations)+len(table.Routes)) results[0] = d - // Construct the routes - subResource := resourceAwsRoute() - for _, route := range table.Routes { - // Ignore the local/default route - if route.GatewayId != nil && *route.GatewayId == "local" { - continue - } + { + // Construct the routes + subResource := resourceAwsRoute() + for _, route := range table.Routes { + // Ignore the local/default route + if route.GatewayId != nil && *route.GatewayId == "local" { + continue + } - // Minimal data for route - d := subResource.Data(nil) - d.SetType("aws_route") - d.Set("route_table_id", id) - d.Set("destination_cidr_block", route.DestinationCidrBlock) - d.SetId(routeIDHash(d, route)) - results = append(results, d) + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_route") + d.Set("route_table_id", id) + d.Set("destination_cidr_block", route.DestinationCidrBlock) + d.SetId(routeIDHash(d, route)) + results = append(results, d) + } + } + + { + // Construct the associations + subResource := resourceAwsRouteTableAssociation() + for _, assoc := range table.Associations { + if *assoc.Main { + // Ignore + continue + } + + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_route_table_association") + d.Set("route_table_id", assoc.RouteTableId) + d.SetId(*assoc.RouteTableAssociationId) + results = append(results, d) + } } return results, nil From 2d5745328b51b82571252579b699eecdccbad90f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 12:33:05 -0700 Subject: [PATCH 13/24] providers/aws: import main route table association --- .../providers/aws/import_aws_route_table.go | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go index c6e694773..a226f7578 100644 --- a/builtin/providers/aws/import_aws_route_table.go +++ b/builtin/providers/aws/import_aws_route_table.go @@ -28,7 +28,7 @@ func resourceAwsRouteTableImportState( // Start building our results results := make([]*schema.ResourceData, 1, - 1+len(table.Associations)+len(table.Routes)) + 2+len(table.Associations)+len(table.Routes)) results[0] = d { @@ -68,5 +68,25 @@ func resourceAwsRouteTableImportState( } } + { + // Construct the main associations. We could do this above but + // I keep this as a separate section since it is a separate resource. + subResource := resourceAwsMainRouteTableAssociation() + for _, assoc := range table.Associations { + if !*assoc.Main { + // Ignore + continue + } + + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_main_route_table_association") + d.Set("route_table_id", id) + d.Set("vpc_id", table.VpcId) + d.SetId(*assoc.RouteTableAssociationId) + results = append(results, d) + } + } + return results, nil } From f6b77a6c02682f082499d2e7de787a9305cbe669 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 13:01:05 -0700 Subject: [PATCH 14/24] providers/aws: import network ACLs --- .../providers/aws/import_aws_network_acl.go | 95 +++++++++++++++++++ .../aws/import_aws_network_acl_test.go | 37 ++++++++ .../providers/aws/resource_aws_network_acl.go | 3 + 3 files changed, 135 insertions(+) create mode 100644 builtin/providers/aws/import_aws_network_acl.go create mode 100644 builtin/providers/aws/import_aws_network_acl_test.go diff --git a/builtin/providers/aws/import_aws_network_acl.go b/builtin/providers/aws/import_aws_network_acl.go new file mode 100644 index 000000000..bcc221d0e --- /dev/null +++ b/builtin/providers/aws/import_aws_network_acl.go @@ -0,0 +1,95 @@ +package aws + +import ( + "fmt" + + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/ec2" + "github.com/hashicorp/terraform/helper/schema" +) + +// Network ACLs import their rules and associations +func resourceAwsNetworkAclImportState( + d *schema.ResourceData, + meta interface{}) ([]*schema.ResourceData, error) { + conn := meta.(*AWSClient).ec2conn + + // First query the resource itself + resp, err := conn.DescribeNetworkAcls(&ec2.DescribeNetworkAclsInput{ + NetworkAclIds: []*string{aws.String(d.Id())}, + }) + if err != nil { + return nil, err + } + if resp == nil || len(resp.NetworkAcls) < 1 || resp.NetworkAcls[0] == nil { + return nil, fmt.Errorf("network ACL %s is not found", d.Id()) + } + acl := resp.NetworkAcls[0] + + // Start building our results + results := make([]*schema.ResourceData, 1, + 2+len(acl.Associations)+len(acl.Entries)) + results[0] = d + + /* + { + // Construct the entries + subResource := resourceAwsNetworkAclRule() + for _, entry := range acl.Entries { + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_network_acl_rule") + d.Set("network_acl_id", acl.NetworkAclId) + d.Set("rule_number", entry.RuleNumber) + d.Set("egress", entry.Egress) + d.Set("protocol", entry.Protocol) + d.SetId(networkAclIdRuleNumberEgressHash( + d.Get("network_acl_id").(string), + d.Get("rule_number").(int), + d.Get("egress").(bool), + d.Get("protocol").(string))) + results = append(results, d) + } + } + + { + // Construct the associations + subResource := resourceAwsRouteTableAssociation() + for _, assoc := range table.Associations { + if *assoc.Main { + // Ignore + continue + } + + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_route_table_association") + d.Set("route_table_id", assoc.RouteTableId) + d.SetId(*assoc.RouteTableAssociationId) + results = append(results, d) + } + } + + { + // Construct the main associations. We could do this above but + // I keep this as a separate section since it is a separate resource. + subResource := resourceAwsMainRouteTableAssociation() + for _, assoc := range table.Associations { + if !*assoc.Main { + // Ignore + continue + } + + // Minimal data for route + d := subResource.Data(nil) + d.SetType("aws_main_route_table_association") + d.Set("route_table_id", id) + d.Set("vpc_id", table.VpcId) + d.SetId(*assoc.RouteTableAssociationId) + results = append(results, d) + } + } + */ + + return results, nil +} diff --git a/builtin/providers/aws/import_aws_network_acl_test.go b/builtin/providers/aws/import_aws_network_acl_test.go new file mode 100644 index 000000000..407d3e45e --- /dev/null +++ b/builtin/providers/aws/import_aws_network_acl_test.go @@ -0,0 +1,37 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSNetworkAcl_importBasic(t *testing.T) { + /* + checkFn := func(s []*terraform.InstanceState) error { + // Expect 2: acl, 2 rules + if len(s) != 3 { + return fmt.Errorf("bad states: %#v", s) + } + + return nil + } + */ + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSNetworkAclDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSNetworkAclEgressNIngressConfig, + }, + + resource.TestStep{ + ResourceName: "aws_network_acl.bar", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_network_acl.go b/builtin/providers/aws/resource_aws_network_acl.go index e946bb932..b0a3340fc 100644 --- a/builtin/providers/aws/resource_aws_network_acl.go +++ b/builtin/providers/aws/resource_aws_network_acl.go @@ -23,6 +23,9 @@ func resourceAwsNetworkAcl() *schema.Resource { Read: resourceAwsNetworkAclRead, Delete: resourceAwsNetworkAclDelete, Update: resourceAwsNetworkAclUpdate, + Importer: &schema.ResourceImporter{ + State: resourceAwsNetworkAclImportState, + }, Schema: map[string]*schema.Schema{ "vpc_id": &schema.Schema{ From 2a30178413350f4d454209216e965ebfba484161 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 13:05:11 -0700 Subject: [PATCH 15/24] providers/aws: flow log import --- .../providers/aws/import_aws_flow_log_test.go | 28 +++++++++++++++++++ .../providers/aws/resource_aws_flow_log.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_flow_log_test.go diff --git a/builtin/providers/aws/import_aws_flow_log_test.go b/builtin/providers/aws/import_aws_flow_log_test.go new file mode 100644 index 000000000..141877b83 --- /dev/null +++ b/builtin/providers/aws/import_aws_flow_log_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSFlowLog_importBasic(t *testing.T) { + resourceName := "aws_flow_log.test_flow_log" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckFlowLogDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccFlowLogConfig_basic, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_flow_log.go b/builtin/providers/aws/resource_aws_flow_log.go index c02868f1d..a95a016a8 100644 --- a/builtin/providers/aws/resource_aws_flow_log.go +++ b/builtin/providers/aws/resource_aws_flow_log.go @@ -15,6 +15,9 @@ func resourceAwsFlowLog() *schema.Resource { Create: resourceAwsLogFlowCreate, Read: resourceAwsLogFlowRead, Delete: resourceAwsLogFlowDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "iam_role_arn": &schema.Schema{ From 4e3488afb880680f35d6dc8c35de4ef51a357349 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 May 2016 13:07:36 -0700 Subject: [PATCH 16/24] providers/aws: customer gateway import --- .../aws/import_aws_customer_gateway_test.go | 28 +++++++++++++++++++ .../aws/resource_aws_customer_gateway.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_customer_gateway_test.go diff --git a/builtin/providers/aws/import_aws_customer_gateway_test.go b/builtin/providers/aws/import_aws_customer_gateway_test.go new file mode 100644 index 000000000..37662760d --- /dev/null +++ b/builtin/providers/aws/import_aws_customer_gateway_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSCustomerGateway_importBasic(t *testing.T) { + resourceName := "aws_customer_gateway.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckCustomerGatewayDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCustomerGatewayConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_customer_gateway.go b/builtin/providers/aws/resource_aws_customer_gateway.go index e98dcaf75..c7e386161 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway.go +++ b/builtin/providers/aws/resource_aws_customer_gateway.go @@ -20,6 +20,9 @@ func resourceAwsCustomerGateway() *schema.Resource { Read: resourceAwsCustomerGatewayRead, Update: resourceAwsCustomerGatewayUpdate, Delete: resourceAwsCustomerGatewayDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "bgp_asn": &schema.Schema{ From a992860b8d4e312a4b7997a651ef791beb2f6472 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 May 2016 10:13:20 -0700 Subject: [PATCH 17/24] providers/aws: key_pair import --- .../providers/aws/import_aws_key_pair_test.go | 29 +++++++++++++++++++ .../providers/aws/resource_aws_key_pair.go | 3 ++ 2 files changed, 32 insertions(+) create mode 100644 builtin/providers/aws/import_aws_key_pair_test.go diff --git a/builtin/providers/aws/import_aws_key_pair_test.go b/builtin/providers/aws/import_aws_key_pair_test.go new file mode 100644 index 000000000..312d800d5 --- /dev/null +++ b/builtin/providers/aws/import_aws_key_pair_test.go @@ -0,0 +1,29 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSKeyPair_importBasic(t *testing.T) { + resourceName := "aws_key_pair.a_key_pair" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSKeyPairDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSKeyPairConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"public_key"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_key_pair.go b/builtin/providers/aws/resource_aws_key_pair.go index 0d6c51fcf..670ff4ac6 100644 --- a/builtin/providers/aws/resource_aws_key_pair.go +++ b/builtin/providers/aws/resource_aws_key_pair.go @@ -18,6 +18,9 @@ func resourceAwsKeyPair() *schema.Resource { Read: resourceAwsKeyPairRead, Update: nil, Delete: resourceAwsKeyPairDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, SchemaVersion: 1, MigrateState: resourceAwsKeyPairMigrateState, From 519f0ae4d6e3c9c7e83d9dc9e743127d6841db06 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 May 2016 10:26:49 -0700 Subject: [PATCH 18/24] providers/aws: launch configuration import --- .../import_aws_launch_configuration_test.go | 29 +++++++++++++++++++ .../aws/resource_aws_launch_configuration.go | 6 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 builtin/providers/aws/import_aws_launch_configuration_test.go diff --git a/builtin/providers/aws/import_aws_launch_configuration_test.go b/builtin/providers/aws/import_aws_launch_configuration_test.go new file mode 100644 index 000000000..f0a721a89 --- /dev/null +++ b/builtin/providers/aws/import_aws_launch_configuration_test.go @@ -0,0 +1,29 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSLaunchConfiguration_importBasic(t *testing.T) { + resourceName := "aws_launch_configuration.bar" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSLaunchConfigurationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSLaunchConfigurationNoNameConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"user_data"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index 55256b9de..0dcbaaf70 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -24,6 +24,9 @@ func resourceAwsLaunchConfiguration() *schema.Resource { Create: resourceAwsLaunchConfigurationCreate, Read: resourceAwsLaunchConfigurationRead, Delete: resourceAwsLaunchConfigurationDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ @@ -110,8 +113,8 @@ func resourceAwsLaunchConfiguration() *schema.Resource { "associate_public_ip_address": &schema.Schema{ Type: schema.TypeBool, Optional: true, + Computed: true, ForceNew: true, - Default: false, }, "spot_price": &schema.Schema{ @@ -495,6 +498,7 @@ func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{} d.Set("instance_type", lc.InstanceType) d.Set("name", lc.LaunchConfigurationName) + d.Set("associate_public_ip_address", lc.AssociatePublicIpAddress) d.Set("iam_instance_profile", lc.IamInstanceProfile) d.Set("ebs_optimized", lc.EbsOptimized) d.Set("spot_price", lc.SpotPrice) From dc3163c4648d67864d2277a51ad8a150b907ddbd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 May 2016 10:35:44 -0700 Subject: [PATCH 19/24] providers/aws: placement group import --- .../aws/import_aws_placement_group_test.go | 28 +++++++++++++++++++ .../aws/resource_aws_placement_group.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_placement_group_test.go diff --git a/builtin/providers/aws/import_aws_placement_group_test.go b/builtin/providers/aws/import_aws_placement_group_test.go new file mode 100644 index 000000000..95b3c88b7 --- /dev/null +++ b/builtin/providers/aws/import_aws_placement_group_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSPlacementGroup_importBasic(t *testing.T) { + resourceName := "aws_placement_group.pg" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSPlacementGroupDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccAWSPlacementGroupConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_placement_group.go b/builtin/providers/aws/resource_aws_placement_group.go index fcc8cc95c..9a6c3016f 100644 --- a/builtin/providers/aws/resource_aws_placement_group.go +++ b/builtin/providers/aws/resource_aws_placement_group.go @@ -17,6 +17,9 @@ func resourceAwsPlacementGroup() *schema.Resource { Create: resourceAwsPlacementGroupCreate, Read: resourceAwsPlacementGroupRead, Delete: resourceAwsPlacementGroupDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ From f64f47080746f154af186ae1e0501549b023abc0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 16 May 2016 10:38:53 -0700 Subject: [PATCH 20/24] providers/aws: fix placement group import --- builtin/providers/aws/resource_aws_placement_group.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_placement_group.go b/builtin/providers/aws/resource_aws_placement_group.go index 9a6c3016f..e5da78c9e 100644 --- a/builtin/providers/aws/resource_aws_placement_group.go +++ b/builtin/providers/aws/resource_aws_placement_group.go @@ -88,7 +88,7 @@ func resourceAwsPlacementGroupCreate(d *schema.ResourceData, meta interface{}) e func resourceAwsPlacementGroupRead(d *schema.ResourceData, meta interface{}) error { conn := meta.(*AWSClient).ec2conn input := ec2.DescribePlacementGroupsInput{ - GroupNames: []*string{aws.String(d.Get("name").(string))}, + GroupNames: []*string{aws.String(d.Id())}, } out, err := conn.DescribePlacementGroups(&input) if err != nil { From 1c0a6bc6d3b10113594a15199f26b9470c470b12 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 18 May 2016 13:09:56 -0600 Subject: [PATCH 21/24] providers/aws: basic route 53 zone import --- .../aws/import_aws_route53_zone_test.go | 28 +++++++++++++++++++ .../aws/resource_aws_route53_zone.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_route53_zone_test.go diff --git a/builtin/providers/aws/import_aws_route53_zone_test.go b/builtin/providers/aws/import_aws_route53_zone_test.go new file mode 100644 index 000000000..f2ad82f3f --- /dev/null +++ b/builtin/providers/aws/import_aws_route53_zone_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSRoute53Zone_importBasic(t *testing.T) { + resourceName := "aws_route53_zone.main" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53ZoneDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53ZoneConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index 4cbd24d2d..52a7976c0 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -21,6 +21,9 @@ func resourceAwsRoute53Zone() *schema.Resource { Read: resourceAwsRoute53ZoneRead, Update: resourceAwsRoute53ZoneUpdate, Delete: resourceAwsRoute53ZoneDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ From 801d3424964e513155d921484842dbfd0956c764 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 18 May 2016 13:15:59 -0600 Subject: [PATCH 22/24] providers/aws: route53 health check import --- .../import_aws_route53_health_check_test.go | 28 +++++++++++++++++++ .../aws/resource_aws_route53_health_check.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_route53_health_check_test.go diff --git a/builtin/providers/aws/import_aws_route53_health_check_test.go b/builtin/providers/aws/import_aws_route53_health_check_test.go new file mode 100644 index 000000000..683b8fa89 --- /dev/null +++ b/builtin/providers/aws/import_aws_route53_health_check_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSRoute53HealthCheck_importBasic(t *testing.T) { + resourceName := "aws_route53_health_check.foo" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckRoute53HealthCheckDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53HealthCheckConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_route53_health_check.go b/builtin/providers/aws/resource_aws_route53_health_check.go index 479dc32fc..0c16770ae 100644 --- a/builtin/providers/aws/resource_aws_route53_health_check.go +++ b/builtin/providers/aws/resource_aws_route53_health_check.go @@ -19,6 +19,9 @@ func resourceAwsRoute53HealthCheck() *schema.Resource { Read: resourceAwsRoute53HealthCheckRead, Update: resourceAwsRoute53HealthCheckUpdate, Delete: resourceAwsRoute53HealthCheckDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "type": &schema.Schema{ From 4967f3ff0841a2356ecf1620f72cfabf27dad34b Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 18 May 2016 13:26:52 -0600 Subject: [PATCH 23/24] providers/aws: route53 delegation set import --- .../import_aws_route53_delegation_set_test.go | 28 +++++++++++++++++++ .../resource_aws_route53_delegation_set.go | 3 ++ 2 files changed, 31 insertions(+) create mode 100644 builtin/providers/aws/import_aws_route53_delegation_set_test.go diff --git a/builtin/providers/aws/import_aws_route53_delegation_set_test.go b/builtin/providers/aws/import_aws_route53_delegation_set_test.go new file mode 100644 index 000000000..d3895b9da --- /dev/null +++ b/builtin/providers/aws/import_aws_route53_delegation_set_test.go @@ -0,0 +1,28 @@ +package aws + +import ( + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestAccAWSRoute53DelegationSet_importBasic(t *testing.T) { + resourceName := "aws_route53_delegation_set.test" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccRoute53DelegationSetConfig, + }, + + resource.TestStep{ + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"reference_name"}, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_route53_delegation_set.go b/builtin/providers/aws/resource_aws_route53_delegation_set.go index cd1980091..34f96ddf5 100644 --- a/builtin/providers/aws/resource_aws_route53_delegation_set.go +++ b/builtin/providers/aws/resource_aws_route53_delegation_set.go @@ -17,6 +17,9 @@ func resourceAwsRoute53DelegationSet() *schema.Resource { Create: resourceAwsRoute53DelegationSetCreate, Read: resourceAwsRoute53DelegationSetRead, Delete: resourceAwsRoute53DelegationSetDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, Schema: map[string]*schema.Schema{ "reference_name": &schema.Schema{ From 24c0adb2d40b5b9ed05ebf55b4d428d50acda4ca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 18 May 2016 15:28:01 -0600 Subject: [PATCH 24/24] providers/aws: revert LC change --- builtin/providers/aws/import_aws_launch_configuration_test.go | 2 +- builtin/providers/aws/resource_aws_launch_configuration.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/import_aws_launch_configuration_test.go b/builtin/providers/aws/import_aws_launch_configuration_test.go index f0a721a89..2117327c1 100644 --- a/builtin/providers/aws/import_aws_launch_configuration_test.go +++ b/builtin/providers/aws/import_aws_launch_configuration_test.go @@ -22,7 +22,7 @@ func TestAccAWSLaunchConfiguration_importBasic(t *testing.T) { ResourceName: resourceName, ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"user_data"}, + ImportStateVerifyIgnore: []string{"associate_public_ip_address", "user_data"}, }, }, }) diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index 0dcbaaf70..536acfc76 100644 --- a/builtin/providers/aws/resource_aws_launch_configuration.go +++ b/builtin/providers/aws/resource_aws_launch_configuration.go @@ -113,8 +113,8 @@ func resourceAwsLaunchConfiguration() *schema.Resource { "associate_public_ip_address": &schema.Schema{ Type: schema.TypeBool, Optional: true, - Computed: true, ForceNew: true, + Default: false, }, "spot_price": &schema.Schema{ @@ -498,7 +498,6 @@ func resourceAwsLaunchConfigurationRead(d *schema.ResourceData, meta interface{} d.Set("instance_type", lc.InstanceType) d.Set("name", lc.LaunchConfigurationName) - d.Set("associate_public_ip_address", lc.AssociatePublicIpAddress) d.Set("iam_instance_profile", lc.IamInstanceProfile) d.Set("ebs_optimized", lc.EbsOptimized) d.Set("spot_price", lc.SpotPrice)