From f147993162834d200712269c366b39e3bb898efd Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 16 Aug 2017 14:03:29 +0300 Subject: [PATCH] resource/aws_cloudformation_stack: Add support for Import Fixes: #1331 ``` % make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudFormation_' ==> Checking that code complies with gofmt requirements... TF_ACC=1 go test ./aws -v -run=TestAccAWSCloudFormation_ -timeout 120m === RUN TestAccAWSCloudFormation_importBasic --- PASS: TestAccAWSCloudFormation_importBasic (89.21s) === RUN TestAccAWSCloudFormation_basic --- PASS: TestAccAWSCloudFormation_basic (85.71s) === RUN TestAccAWSCloudFormation_yaml --- PASS: TestAccAWSCloudFormation_yaml (85.08s) === RUN TestAccAWSCloudFormation_defaultParams --- PASS: TestAccAWSCloudFormation_defaultParams (86.75s) === RUN TestAccAWSCloudFormation_allAttributes --- PASS: TestAccAWSCloudFormation_allAttributes (154.23s) === RUN TestAccAWSCloudFormation_withParams --- PASS: TestAccAWSCloudFormation_withParams (158.42s) ``` --- aws/resource_aws_cloudformation_stack.go | 4 ++++ aws/resource_aws_cloudformation_stack_test.go | 22 +++++++++++++++++++ .../docs/r/cloudformation_stack.html.markdown | 9 ++++++++ 3 files changed, 35 insertions(+) diff --git a/aws/resource_aws_cloudformation_stack.go b/aws/resource_aws_cloudformation_stack.go index 7f3a61db13d..f5490b2a5d3 100644 --- a/aws/resource_aws_cloudformation_stack.go +++ b/aws/resource_aws_cloudformation_stack.go @@ -21,6 +21,10 @@ func resourceAwsCloudFormationStack() *schema.Resource { Update: resourceAwsCloudFormationStackUpdate, Delete: resourceAwsCloudFormationStackDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + Timeouts: &schema.ResourceTimeout{ Create: schema.DefaultTimeout(30 * time.Minute), Update: schema.DefaultTimeout(30 * time.Minute), diff --git a/aws/resource_aws_cloudformation_stack_test.go b/aws/resource_aws_cloudformation_stack_test.go index 67b0344bea2..174dd6293b8 100644 --- a/aws/resource_aws_cloudformation_stack_test.go +++ b/aws/resource_aws_cloudformation_stack_test.go @@ -11,6 +11,28 @@ import ( "github.com/hashicorp/terraform/terraform" ) +func TestAccAWSCloudFormation_importBasic(t *testing.T) { + stackName := fmt.Sprintf("tf-acc-test-basic-%s", acctest.RandString(10)) + + resourceName := "aws_cloudformation_stack.network" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckAWSCloudFormationDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAWSCloudFormationConfig(stackName), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAWSCloudFormation_basic(t *testing.T) { var stack cloudformation.Stack stackName := fmt.Sprintf("tf-acc-test-basic-%s", acctest.RandString(10)) diff --git a/website/docs/r/cloudformation_stack.html.markdown b/website/docs/r/cloudformation_stack.html.markdown index 38c34ad646e..4422e62f2e1 100644 --- a/website/docs/r/cloudformation_stack.html.markdown +++ b/website/docs/r/cloudformation_stack.html.markdown @@ -76,6 +76,15 @@ The following attributes are exported: * `outputs` - A map of outputs from the stack. +## Import + +Cloudformation Stacks can be imported using the `name`, e.g. + +``` +$ terraform import aws_cloudformation_stack.stack networking-stack +``` + + ## Timeouts