Add ability to import AWS OpsWorks Custom Layers
This commit is contained in:
parent
843db01d17
commit
56f35dd67d
|
@ -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,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
|
@ -251,6 +251,9 @@ func (lt *opsworksLayerType) SchemaResource() *schema.Resource {
|
||||||
client := meta.(*AWSClient).opsworksconn
|
client := meta.(*AWSClient).opsworksconn
|
||||||
return lt.Delete(d, client)
|
return lt.Delete(d, client)
|
||||||
},
|
},
|
||||||
|
Importer: &schema.ResourceImporter{
|
||||||
|
State: schema.ImportStatePassthrough,
|
||||||
|
},
|
||||||
|
|
||||||
Schema: resourceSchema,
|
Schema: resourceSchema,
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ func TestAccAWSOpsworksCustomLayer(t *testing.T) {
|
||||||
CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy,
|
CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
resource.TestStep{
|
||||||
Config: testAccAwsOpsworksCustomLayerConfigCreate(stackName),
|
Config: testAccAwsOpsworksCustomLayerConfigNoVpcCreate(stackName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_opsworks_custom_layer.tf-acc", "name", stackName,
|
"aws_opsworks_custom_layer.tf-acc", "name", stackName,
|
||||||
|
@ -187,7 +187,7 @@ resource "aws_security_group" "tf-ops-acc-layer2" {
|
||||||
}`, name, name)
|
}`, name, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccAwsOpsworksCustomLayerConfigCreate(name string) string {
|
func testAccAwsOpsworksCustomLayerConfigNoVpcCreate(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-east-1"
|
region = "us-east-1"
|
||||||
|
@ -224,6 +224,43 @@ resource "aws_opsworks_custom_layer" "tf-acc" {
|
||||||
`, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name))
|
`, 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 {
|
func testAccAwsOpsworksCustomLayerConfigUpdate(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
|
|
|
@ -338,6 +338,9 @@ func resourceAwsOpsworksStackCreate(d *schema.ResourceData, meta interface{}) er
|
||||||
if defaultAvailabilityZone, ok := d.GetOk("default_availability_zone"); ok {
|
if defaultAvailabilityZone, ok := d.GetOk("default_availability_zone"); ok {
|
||||||
req.DefaultAvailabilityZone = aws.String(defaultAvailabilityZone.(string))
|
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)
|
log.Printf("[DEBUG] Creating OpsWorks stack: %s", req)
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ To make a resource importable, please see the
|
||||||
* aws_nat_gateway
|
* aws_nat_gateway
|
||||||
* aws_network_acl
|
* aws_network_acl
|
||||||
* aws_network_interface
|
* aws_network_interface
|
||||||
|
* aws_opsworks_custom_layer
|
||||||
* aws_opsworks_stack
|
* aws_opsworks_stack
|
||||||
* aws_placement_group
|
* aws_placement_group
|
||||||
* aws_rds_cluster
|
* aws_rds_cluster
|
||||||
|
|
|
@ -65,3 +65,12 @@ An `ebs_volume` block supports the following arguments:
|
||||||
The following attributes are exported:
|
The following attributes are exported:
|
||||||
|
|
||||||
* `id` - The id of the layer.
|
* `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
|
||||||
|
```
|
Loading…
Reference in New Issue