Merge branch 'f-aws-import'

This commit is contained in:
Mitchell Hashimoto 2016-05-18 15:28:12 -06:00
commit 55583baa7e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
46 changed files with 863 additions and 10 deletions

View File

@ -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"},
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

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

View File

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

View File

@ -0,0 +1,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"},
},
},
})
}

View File

@ -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"},
},
},
})
}

View File

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

View File

@ -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
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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"},
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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,
},
},
})
}

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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)

View File

@ -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{

View File

@ -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{

View File

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

View File

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

View File

@ -18,6 +18,9 @@ func resourceAwsKeyPair() *schema.Resource {
Read: resourceAwsKeyPairRead,
Update: nil,
Delete: resourceAwsKeyPairDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
SchemaVersion: 1,
MigrateState: resourceAwsKeyPairMigrateState,

View File

@ -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{

View File

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

View File

@ -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{

View File

@ -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{

View File

@ -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 {

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

@ -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{

View File

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

View File

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

View File

@ -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
}