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_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/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/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/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/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_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/import_aws_launch_configuration_test.go b/builtin/providers/aws/import_aws_launch_configuration_test.go new file mode 100644 index 000000000..2117327c1 --- /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{"associate_public_ip_address", "user_data"}, + }, + }, + }) +} 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/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/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/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/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/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/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/import_aws_route_table.go b/builtin/providers/aws/import_aws_route_table.go new file mode 100644 index 000000000..a226f7578 --- /dev/null +++ b/builtin/providers/aws/import_aws_route_table.go @@ -0,0 +1,92 @@ +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, + 2+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 + } + + // 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) + } + } + + { + // 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_route_table_test.go b/builtin/providers/aws/import_aws_route_table_test.go new file mode 100644 index 000000000..43727b7bb --- /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) != 2 { + 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/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/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/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_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_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{ 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{ 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) 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{ 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{ 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_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, diff --git a/builtin/providers/aws/resource_aws_launch_configuration.go b/builtin/providers/aws/resource_aws_launch_configuration.go index 55256b9de..536acfc76 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{ 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/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{ 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{ diff --git a/builtin/providers/aws/resource_aws_placement_group.go b/builtin/providers/aws/resource_aws_placement_group.go index fcc8cc95c..e5da78c9e 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{ @@ -85,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 { 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{ 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{ 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{ 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{ 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{ 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{ 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{ diff --git a/helper/resource/testing.go b/helper/resource/testing.go index a6ceec140..619a6747b 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)) } 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 +}