github.com/andresvia/terraform@v0.6.15-0.20160412045437-d51c75946785/builtin/providers/aws/resource_aws_opsworks_custom_layer_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/awserr" 9 "github.com/aws/aws-sdk-go/service/opsworks" 10 "github.com/hashicorp/terraform/helper/acctest" 11 "github.com/hashicorp/terraform/helper/resource" 12 "github.com/hashicorp/terraform/terraform" 13 ) 14 15 // These tests assume the existence of predefined Opsworks IAM roles named `aws-opsworks-ec2-role` 16 // and `aws-opsworks-service-role`. 17 18 func TestAccAWSOpsworksCustomLayer(t *testing.T) { 19 stackName := fmt.Sprintf("tf-%d", acctest.RandInt()) 20 resource.Test(t, resource.TestCase{ 21 PreCheck: func() { testAccPreCheck(t) }, 22 Providers: testAccProviders, 23 CheckDestroy: testAccCheckAwsOpsworksCustomLayerDestroy, 24 Steps: []resource.TestStep{ 25 resource.TestStep{ 26 Config: testAccAwsOpsworksCustomLayerConfigCreate(stackName), 27 Check: resource.ComposeTestCheckFunc( 28 resource.TestCheckResourceAttr( 29 "aws_opsworks_custom_layer.tf-acc", "name", stackName, 30 ), 31 resource.TestCheckResourceAttr( 32 "aws_opsworks_custom_layer.tf-acc", "auto_assign_elastic_ips", "false", 33 ), 34 resource.TestCheckResourceAttr( 35 "aws_opsworks_custom_layer.tf-acc", "auto_healing", "true", 36 ), 37 resource.TestCheckResourceAttr( 38 "aws_opsworks_custom_layer.tf-acc", "drain_elb_on_shutdown", "true", 39 ), 40 resource.TestCheckResourceAttr( 41 "aws_opsworks_custom_layer.tf-acc", "instance_shutdown_timeout", "300", 42 ), 43 resource.TestCheckResourceAttr( 44 "aws_opsworks_custom_layer.tf-acc", "custom_security_group_ids.#", "2", 45 ), 46 resource.TestCheckResourceAttr( 47 "aws_opsworks_custom_layer.tf-acc", "system_packages.#", "2", 48 ), 49 resource.TestCheckResourceAttr( 50 "aws_opsworks_custom_layer.tf-acc", "system_packages.1368285564", "git", 51 ), 52 resource.TestCheckResourceAttr( 53 "aws_opsworks_custom_layer.tf-acc", "system_packages.2937857443", "golang", 54 ), 55 resource.TestCheckResourceAttr( 56 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.#", "1", 57 ), 58 resource.TestCheckResourceAttr( 59 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.type", "gp2", 60 ), 61 resource.TestCheckResourceAttr( 62 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.number_of_disks", "2", 63 ), 64 resource.TestCheckResourceAttr( 65 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.mount_point", "/home", 66 ), 67 resource.TestCheckResourceAttr( 68 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.size", "100", 69 ), 70 ), 71 }, 72 resource.TestStep{ 73 Config: testAccAwsOpsworksCustomLayerConfigUpdate(stackName), 74 Check: resource.ComposeTestCheckFunc( 75 resource.TestCheckResourceAttr( 76 "aws_opsworks_custom_layer.tf-acc", "name", stackName, 77 ), 78 resource.TestCheckResourceAttr( 79 "aws_opsworks_custom_layer.tf-acc", "drain_elb_on_shutdown", "false", 80 ), 81 resource.TestCheckResourceAttr( 82 "aws_opsworks_custom_layer.tf-acc", "instance_shutdown_timeout", "120", 83 ), 84 resource.TestCheckResourceAttr( 85 "aws_opsworks_custom_layer.tf-acc", "custom_security_group_ids.#", "3", 86 ), 87 resource.TestCheckResourceAttr( 88 "aws_opsworks_custom_layer.tf-acc", "system_packages.#", "3", 89 ), 90 resource.TestCheckResourceAttr( 91 "aws_opsworks_custom_layer.tf-acc", "system_packages.1368285564", "git", 92 ), 93 resource.TestCheckResourceAttr( 94 "aws_opsworks_custom_layer.tf-acc", "system_packages.2937857443", "golang", 95 ), 96 resource.TestCheckResourceAttr( 97 "aws_opsworks_custom_layer.tf-acc", "system_packages.4101929740", "subversion", 98 ), 99 resource.TestCheckResourceAttr( 100 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.#", "2", 101 ), 102 resource.TestCheckResourceAttr( 103 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.type", "gp2", 104 ), 105 resource.TestCheckResourceAttr( 106 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.number_of_disks", "2", 107 ), 108 resource.TestCheckResourceAttr( 109 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.mount_point", "/home", 110 ), 111 resource.TestCheckResourceAttr( 112 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.3575749636.size", "100", 113 ), 114 resource.TestCheckResourceAttr( 115 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.type", "io1", 116 ), 117 resource.TestCheckResourceAttr( 118 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.number_of_disks", "4", 119 ), 120 resource.TestCheckResourceAttr( 121 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.mount_point", "/var", 122 ), 123 resource.TestCheckResourceAttr( 124 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.size", "100", 125 ), 126 resource.TestCheckResourceAttr( 127 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.raid_level", "1", 128 ), 129 resource.TestCheckResourceAttr( 130 "aws_opsworks_custom_layer.tf-acc", "ebs_volume.1266957920.iops", "3000", 131 ), 132 ), 133 }, 134 }, 135 }) 136 } 137 138 func testAccCheckAwsOpsworksCustomLayerDestroy(s *terraform.State) error { 139 opsworksconn := testAccProvider.Meta().(*AWSClient).opsworksconn 140 for _, rs := range s.RootModule().Resources { 141 if rs.Type != "aws_opsworks_custom_layer" { 142 continue 143 } 144 req := &opsworks.DescribeLayersInput{ 145 LayerIds: []*string{ 146 aws.String(rs.Primary.ID), 147 }, 148 } 149 150 _, err := opsworksconn.DescribeLayers(req) 151 if err != nil { 152 if awserr, ok := err.(awserr.Error); ok { 153 if awserr.Code() == "ResourceNotFoundException" { 154 // not found, good to go 155 return nil 156 } 157 } 158 return err 159 } 160 } 161 162 return fmt.Errorf("Fall through error on OpsWorks custom layer test") 163 } 164 165 func testAccAwsOpsworksCustomLayerSecurityGroups(name string) string { 166 return fmt.Sprintf(` 167 resource "aws_security_group" "tf-ops-acc-layer1" { 168 name = "%s-layer1" 169 ingress { 170 from_port = 8 171 to_port = -1 172 protocol = "icmp" 173 cidr_blocks = ["0.0.0.0/0"] 174 } 175 } 176 resource "aws_security_group" "tf-ops-acc-layer2" { 177 name = "%s-layer2" 178 ingress { 179 from_port = 8 180 to_port = -1 181 protocol = "icmp" 182 cidr_blocks = ["0.0.0.0/0"] 183 } 184 }`, name, name) 185 } 186 187 func testAccAwsOpsworksCustomLayerConfigCreate(name string) string { 188 return fmt.Sprintf(` 189 provider "aws" { 190 region = "us-east-1" 191 } 192 193 resource "aws_opsworks_custom_layer" "tf-acc" { 194 stack_id = "${aws_opsworks_stack.tf-acc.id}" 195 name = "%s" 196 short_name = "tf-ops-acc-custom-layer" 197 auto_assign_public_ips = true 198 custom_security_group_ids = [ 199 "${aws_security_group.tf-ops-acc-layer1.id}", 200 "${aws_security_group.tf-ops-acc-layer2.id}", 201 ] 202 drain_elb_on_shutdown = true 203 instance_shutdown_timeout = 300 204 system_packages = [ 205 "git", 206 "golang", 207 ] 208 ebs_volume { 209 type = "gp2" 210 number_of_disks = 2 211 mount_point = "/home" 212 size = 100 213 raid_level = 0 214 } 215 } 216 217 %s 218 219 %s 220 221 `, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name)) 222 } 223 224 func testAccAwsOpsworksCustomLayerConfigUpdate(name string) string { 225 return fmt.Sprintf(` 226 provider "aws" { 227 region = "us-east-1" 228 } 229 230 resource "aws_security_group" "tf-ops-acc-layer3" { 231 name = "tf-ops-acc-layer3" 232 ingress { 233 from_port = 8 234 to_port = -1 235 protocol = "icmp" 236 cidr_blocks = ["0.0.0.0/0"] 237 } 238 } 239 resource "aws_opsworks_custom_layer" "tf-acc" { 240 stack_id = "${aws_opsworks_stack.tf-acc.id}" 241 name = "%s" 242 short_name = "tf-ops-acc-custom-layer" 243 auto_assign_public_ips = true 244 custom_security_group_ids = [ 245 "${aws_security_group.tf-ops-acc-layer1.id}", 246 "${aws_security_group.tf-ops-acc-layer2.id}", 247 "${aws_security_group.tf-ops-acc-layer3.id}", 248 ] 249 drain_elb_on_shutdown = false 250 instance_shutdown_timeout = 120 251 system_packages = [ 252 "git", 253 "golang", 254 "subversion", 255 ] 256 ebs_volume { 257 type = "gp2" 258 number_of_disks = 2 259 mount_point = "/home" 260 size = 100 261 raid_level = 0 262 } 263 ebs_volume { 264 type = "io1" 265 number_of_disks = 4 266 mount_point = "/var" 267 size = 100 268 raid_level = 1 269 iops = 3000 270 } 271 } 272 273 %s 274 275 %s 276 277 `, name, testAccAwsOpsworksStackConfigNoVpcCreate(name), testAccAwsOpsworksCustomLayerSecurityGroups(name)) 278 }