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