Merge branch 'import-opsworks-stacks' of https://github.com/DJRH/terraform into DJRH-import-opsworks-stacks

This commit is contained in:
stack72 2016-10-03 16:23:03 +01:00
commit 2f81f47d49
No known key found for this signature in database
GPG Key ID: 8619A619B085CB16
4 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package aws
import (
"os"
"testing"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)
func TestAccAWSOpsWorksStack_importBasic(t *testing.T) {
oldvar := os.Getenv("AWS_DEFAULT_REGION")
os.Setenv("AWS_DEFAULT_REGION", "us-west-2")
defer os.Setenv("AWS_DEFAULT_REGION", oldvar)
name := acctest.RandString(10)
resourceName := "aws_opsworks_stack.tf-acc"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsOpsworksStackDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccAwsOpsworksStackConfigVpcCreate(name),
},
resource.TestStep{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

View File

@ -20,6 +20,9 @@ func resourceAwsOpsworksStack() *schema.Resource {
Read: resourceAwsOpsworksStackRead,
Update: resourceAwsOpsworksStackUpdate,
Delete: resourceAwsOpsworksStackDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"agent_version": &schema.Schema{
@ -283,6 +286,9 @@ func resourceAwsOpsworksStackRead(d *schema.ResourceData, meta interface{}) erro
d.Set("default_subnet_id", stack.DefaultSubnetId)
d.Set("hostname_theme", stack.HostnameTheme)
d.Set("use_custom_cookbooks", stack.UseCustomCookbooks)
if stack.CustomJson != nil {
d.Set("custom_json", stack.CustomJson)
}
d.Set("use_opsworks_security_groups", stack.UseOpsworksSecurityGroups)
d.Set("vpc_id", stack.VpcId)
if color, ok := stack.Attributes["Color"]; ok {

View File

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

View File

@ -76,3 +76,12 @@ The `custom_cookbooks_source` block supports the following arguments:
The following attributes are exported:
* `id` - The id of the stack.
## Import
OpsWorks stacks can be imported using the `id`, e.g.
```
$ terraform import aws_opsworks_stack.bar 00000000-0000-0000-0000-000000000000
```