Add ability to import AWS OpsWorks Custom Layers

This commit is contained in:
DJ Home 2016-10-06 13:30:06 +01:00 committed by stack72
parent 843db01d17
commit 56f35dd67d
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
6 changed files with 86 additions and 2 deletions

View File

@ -0,0 +1,31 @@
package aws
import (
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSOpsworksCustomLayerImportBasic(t *testing.T) {
name := acctest.RandString(10)
resourceName := "aws_opsworks_custom_layer.tf-acc"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsOpsworksCustomLayerConfigVpcCreate(name),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -251,6 +251,9 @@ func (lt *opsworksLayerType) SchemaResource() *schema.Resource {
client := meta.(*AWSClient).opsworksconn
return lt.Delete(d, client)
},
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: resourceSchema,
}

View File

@ -23,7 +23,7 @@ func TestAccAWSOpsworksCustomLayer(t *testing.T) {
CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsOpsworksCustomLayerConfigCreate(stackName),
Config: testAccAwsOpsworksCustomLayerConfigNoVpcCreate(stackName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"aws_opsworks_custom_layer.tf-acc", "name", stackName,
@ -187,7 +187,7 @@ resource "aws_security_group" "tf-ops-acc-layer2" {
}`, name, name)
}
func testAccAwsOpsworksCustomLayerConfigCreate(name string) string {
func testAccAwsOpsworksCustomLayerConfigNoVpcCreate(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
@ -224,6 +224,43 @@ resource "aws_opsworks_custom_layer" "tf-acc" {
`, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name))
}
func testAccAwsOpsworksCustomLayerConfigVpcCreate(name string) string {
return fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
}
resource "aws_opsworks_custom_layer" "tf-acc" {
stack_id = "${aws_opsworks_stack.tf-acc.id}"
name = "%s"
short_name = "tf-ops-acc-custom-layer"
auto_assign_public_ips = false
custom_security_group_ids = [
"${aws_security_group.tf-ops-acc-layer1.id}",
"${aws_security_group.tf-ops-acc-layer2.id}",
]
drain_elb_on_shutdown = true
instance_shutdown_timeout = 300
system_packages = [
"git",
"golang",
]
ebs_volume {
type = "gp2"
number_of_disks = 2
mount_point = "/home"
size = 100
raid_level = 0
}
}
%s
%s
`, name, testAccAwsOpsworksStackConfigVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name))
}
func testAccAwsOpsworksCustomLayerConfigUpdate(name string) string {
return fmt.Sprintf(`
provider "aws" {

View File

@ -338,6 +338,9 @@ func resourceAwsOpsworksStackCreate(d *schema.ResourceData, meta interface{}) er
if defaultAvailabilityZone, ok := d.GetOk("default_availability_zone"); ok {
req.DefaultAvailabilityZone = aws.String(defaultAvailabilityZone.(string))
}
if defaultRootDeviceType, ok := d.GetOk("default_root_device_type"); ok {
req.DefaultRootDeviceType = aws.String(defaultRootDeviceType.(string))
}
log.Printf("[DEBUG] Creating OpsWorks stack: %s", req)

View File

@ -68,6 +68,7 @@ To make a resource importable, please see the
* aws_nat_gateway
* aws_network_acl
* aws_network_interface
* aws_opsworks_custom_layer
* aws_opsworks_stack
* aws_placement_group
* aws_rds_cluster

View File

@ -65,3 +65,12 @@ An `ebs_volume` block supports the following arguments:
The following attributes are exported:
* `id` - The id of the layer.
## Import
OpsWorks Custom Layers can be imported using the `id`, e.g.
```
$ terraform import aws_opsworks_custom_layer.bar 00000000-0000-0000-0000-000000000000
```