From 1bc154535f5aeba42d61d7520464dbebc1642556 Mon Sep 17 00:00:00 2001 From: DJ Home Date: Thu, 29 Sep 2016 11:44:58 +0100 Subject: [PATCH 1/4] Add ability to import OpsWorks stacks --- .../aws/import_aws_opsworks_stack_test.go | 36 +++++++++++++++++++ .../aws/resource_aws_opsworks_stack.go | 3 ++ .../source/docs/import/importability.html.md | 1 + .../aws/r/opsworks_stack.html.markdown | 9 +++++ 4 files changed, 49 insertions(+) create mode 100644 builtin/providers/aws/import_aws_opsworks_stack_test.go diff --git a/builtin/providers/aws/import_aws_opsworks_stack_test.go b/builtin/providers/aws/import_aws_opsworks_stack_test.go new file mode 100644 index 000000000..44f1c0e95 --- /dev/null +++ b/builtin/providers/aws/import_aws_opsworks_stack_test.go @@ -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-east-1") + defer os.Setenv("AWS_DEFAULT_REGION", oldvar) + + name := acctest.RandString(10) + + resourceName := "aws_opsworks_stack.bar" + + 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, + }, + }, + }) +} diff --git a/builtin/providers/aws/resource_aws_opsworks_stack.go b/builtin/providers/aws/resource_aws_opsworks_stack.go index 2d59e0734..4794d19c6 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack.go @@ -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{ diff --git a/website/source/docs/import/importability.html.md b/website/source/docs/import/importability.html.md index d08fb6b67..9032250ad 100644 --- a/website/source/docs/import/importability.html.md +++ b/website/source/docs/import/importability.html.md @@ -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 diff --git a/website/source/docs/providers/aws/r/opsworks_stack.html.markdown b/website/source/docs/providers/aws/r/opsworks_stack.html.markdown index f1c6f978a..84e33c3d4 100644 --- a/website/source/docs/providers/aws/r/opsworks_stack.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_stack.html.markdown @@ -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 +``` \ No newline at end of file From 979afcecdcce18fa6d96f60c9710704f3372dae3 Mon Sep 17 00:00:00 2001 From: DJ Home Date: Thu, 29 Sep 2016 13:00:52 +0100 Subject: [PATCH 2/4] Fix acceptance tests --- builtin/providers/aws/import_aws_opsworks_stack_test.go | 2 +- builtin/providers/aws/resource_aws_opsworks_stack.go | 3 +++ builtin/providers/aws/resource_aws_opsworks_stack_test.go | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/import_aws_opsworks_stack_test.go b/builtin/providers/aws/import_aws_opsworks_stack_test.go index 44f1c0e95..5bd304e19 100644 --- a/builtin/providers/aws/import_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/import_aws_opsworks_stack_test.go @@ -15,7 +15,7 @@ func TestAccAWSOpsWorksStack_importBasic(t *testing.T) { name := acctest.RandString(10) - resourceName := "aws_opsworks_stack.bar" + resourceName := "aws_opsworks_stack.tf-acc" resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/builtin/providers/aws/resource_aws_opsworks_stack.go b/builtin/providers/aws/resource_aws_opsworks_stack.go index 4794d19c6..a49e7cce2 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack.go @@ -286,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 { diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index 1bb9bba14..77de2fc29 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -411,11 +411,11 @@ resource "aws_vpc" "tf-acc" { resource "aws_subnet" "tf-acc" { vpc_id = "${aws_vpc.tf-acc.id}" cidr_block = "${aws_vpc.tf-acc.cidr_block}" - availability_zone = "us-west-2a" + availability_zone = "us-east-1a" } resource "aws_opsworks_stack" "tf-acc" { name = "%s" - region = "us-west-2" + region = "us-east-1" vpc_id = "${aws_vpc.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}" service_role_arn = "${aws_iam_role.opsworks_service.arn}" From 73f20ec88dc40862c9345fffc40307d3dbf7f729 Mon Sep 17 00:00:00 2001 From: DJ Home Date: Fri, 30 Sep 2016 13:33:00 +0100 Subject: [PATCH 3/4] Revert region to us-west-2 (and set us-west-2 as default region in acceptance test class) --- builtin/providers/aws/import_aws_opsworks_stack_test.go | 2 +- builtin/providers/aws/resource_aws_opsworks_stack_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/import_aws_opsworks_stack_test.go b/builtin/providers/aws/import_aws_opsworks_stack_test.go index 5bd304e19..1bc7d7b02 100644 --- a/builtin/providers/aws/import_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/import_aws_opsworks_stack_test.go @@ -10,7 +10,7 @@ import ( func TestAccAWSOpsWorksStack_importBasic(t *testing.T) { oldvar := os.Getenv("AWS_DEFAULT_REGION") - os.Setenv("AWS_DEFAULT_REGION", "us-east-1") + os.Setenv("AWS_DEFAULT_REGION", "us-west-2") defer os.Setenv("AWS_DEFAULT_REGION", oldvar) name := acctest.RandString(10) diff --git a/builtin/providers/aws/resource_aws_opsworks_stack_test.go b/builtin/providers/aws/resource_aws_opsworks_stack_test.go index 77de2fc29..1bb9bba14 100644 --- a/builtin/providers/aws/resource_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_stack_test.go @@ -411,11 +411,11 @@ resource "aws_vpc" "tf-acc" { resource "aws_subnet" "tf-acc" { vpc_id = "${aws_vpc.tf-acc.id}" cidr_block = "${aws_vpc.tf-acc.cidr_block}" - availability_zone = "us-east-1a" + availability_zone = "us-west-2a" } resource "aws_opsworks_stack" "tf-acc" { name = "%s" - region = "us-east-1" + region = "us-west-2" vpc_id = "${aws_vpc.tf-acc.id}" default_subnet_id = "${aws_subnet.tf-acc.id}" service_role_arn = "${aws_iam_role.opsworks_service.arn}" From fa3051a42b3c8a4b5b4b804555b16ae4d0f191dd Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 3 Oct 2016 16:45:02 +0100 Subject: [PATCH 4/4] provider/aws: Rename the Import aws_opsworks_stack import test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The casing on the test name was causing it not to run with the entire test suite ``` % make testacc TEST=./builtin/providers/aws % TESTARGS='-run=TestAccAWSOpsworksStack' 2 ↵ ✹ ==> Checking that code complies with gofmt requirements... go generate $(go list ./... | grep -v /terraform/vendor/) 2016/10/03 16:43:07 Generated command/internal_plugin_list.go TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSOpsworksStack -timeout 120m === RUN TestAccAWSOpsworksStackImportBasic --- PASS: TestAccAWSOpsworksStackImportBasic (49.00s) === RUN TestAccAWSOpsworksStackNoVpc --- PASS: TestAccAWSOpsworksStackNoVpc (36.10s) === RUN TestAccAWSOpsworksStackVpc --- PASS: TestAccAWSOpsworksStackVpc (73.27s) PASS ok github.com/hashicorp/terraform/builtin/providers/aws158.385s ``` --- builtin/providers/aws/import_aws_opsworks_stack_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builtin/providers/aws/import_aws_opsworks_stack_test.go b/builtin/providers/aws/import_aws_opsworks_stack_test.go index 1bc7d7b02..40959346f 100644 --- a/builtin/providers/aws/import_aws_opsworks_stack_test.go +++ b/builtin/providers/aws/import_aws_opsworks_stack_test.go @@ -1,18 +1,13 @@ 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) - +func TestAccAWSOpsworksStackImportBasic(t *testing.T) { name := acctest.RandString(10) resourceName := "aws_opsworks_stack.tf-acc"