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