github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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  `
    79  
    80  func TestAccAWSCloudFormationStack_dataSource_yaml(t *testing.T) {
    81  	resource.Test(t, resource.TestCase{
    82  		PreCheck:  func() { testAccPreCheck(t) },
    83  		Providers: testAccProviders,
    84  		Steps: []resource.TestStep{
    85  			resource.TestStep{
    86  				Config: testAccCheckAwsCloudFormationStackDataSourceConfig_yaml,
    87  				Check: resource.ComposeTestCheckFunc(
    88  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "outputs.%", "1"),
    89  					resource.TestMatchResourceAttr("data.aws_cloudformation_stack.yaml", "outputs.VPCId",
    90  						regexp.MustCompile("^vpc-[a-z0-9]{8}$")),
    91  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "capabilities.#", "0"),
    92  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "disable_rollback", "false"),
    93  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "notification_arns.#", "0"),
    94  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "parameters.%", "1"),
    95  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "parameters.CIDR", "10.10.10.0/24"),
    96  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "timeout_in_minutes", "6"),
    97  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "tags.%", "2"),
    98  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "tags.Name", "Form the Cloud"),
    99  					resource.TestCheckResourceAttr("data.aws_cloudformation_stack.yaml", "tags.Second", "meh"),
   100  				),
   101  			},
   102  		},
   103  	})
   104  }
   105  
   106  const testAccCheckAwsCloudFormationStackDataSourceConfig_yaml = `
   107  resource "aws_cloudformation_stack" "yaml" {
   108    name = "tf-acc-ds-yaml-stack"
   109    parameters {
   110      CIDR = "10.10.10.0/24"
   111    }
   112    timeout_in_minutes = 6
   113    template_body = <<STACK
   114  Parameters:
   115    CIDR:
   116      Type: String
   117  
   118  Resources:
   119    myvpc:
   120      Type: AWS::EC2::VPC
   121      Properties:
   122        CidrBlock: !Ref CIDR
   123        Tags:
   124          -
   125            Key: Name
   126            Value: Primary_CF_VPC
   127  
   128  Outputs:
   129    VPCId:
   130      Value: !Ref myvpc
   131      Description: VPC ID
   132  STACK
   133    tags {
   134      Name = "Form the Cloud"
   135      Second = "meh"
   136    }
   137  }
   138  
   139  data "aws_cloudformation_stack" "yaml" {
   140    name = "${aws_cloudformation_stack.yaml.name}"
   141  }
   142  `