github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/data_source_aws_cloudformation_stack_test.go (about) 1 package aws 2 3 import ( 4 "regexp" 5 "testing" 6 7 "github.com/hashicorp/terraform/helper/resource" 8 ) 9 10 func TestAccAWSCloudFormationStack_dataSource_basic(t *testing.T) { 11 resource.Test(t, resource.TestCase{ 12 PreCheck: func() { testAccPreCheck(t) }, 13 Providers: testAccProviders, 14 Steps: []resource.TestStep{ 15 resource.TestStep{ 16 Config: testAccCheckAwsCloudFormationStackDataSourceConfig_basic, 17 Check: resource.ComposeTestCheckFunc( 18 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "outputs.%", "1"), 19 resource.TestMatchResourceAttr("data.aws_cloudformation_stack.network", "outputs.VPCId", 20 regexp.MustCompile("^vpc-[a-z0-9]{8}$")), 21 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "capabilities.#", "0"), 22 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "disable_rollback", "false"), 23 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "notification_arns.#", "0"), 24 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "parameters.%", "1"), 25 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "parameters.CIDR", "10.10.10.0/24"), 26 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "timeout_in_minutes", "6"), 27 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.%", "2"), 28 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.Name", "Form the Cloud"), 29 resource.TestCheckResourceAttr("data.aws_cloudformation_stack.network", "tags.Second", "meh"), 30 ), 31 }, 32 }, 33 }) 34 } 35 36 const testAccCheckAwsCloudFormationStackDataSourceConfig_basic = ` 37 resource "aws_cloudformation_stack" "cfs" { 38 name = "tf-acc-ds-networking-stack" 39 parameters { 40 CIDR = "10.10.10.0/24" 41 } 42 timeout_in_minutes = 6 43 template_body = <<STACK 44 { 45 "Parameters": { 46 "CIDR": { 47 "Type": "String" 48 } 49 }, 50 "Resources" : { 51 "myvpc": { 52 "Type" : "AWS::EC2::VPC", 53 "Properties" : { 54 "CidrBlock" : { "Ref" : "CIDR" }, 55 "Tags" : [ 56 {"Key": "Name", "Value": "Primary_CF_VPC"} 57 ] 58 } 59 } 60 }, 61 "Outputs" : { 62 "VPCId" : { 63 "Value" : { "Ref" : "myvpc" }, 64 "Description" : "VPC ID" 65 } 66 } 67 } 68 STACK 69 tags { 70 Name = "Form the Cloud" 71 Second = "meh" 72 } 73 } 74 75 data "aws_cloudformation_stack" "network" { 76 name = "${aws_cloudformation_stack.cfs.name}" 77 } 78 `