github.com/wangzhucn/terraform@v0.6.7-0.20151109233120-4eea011b56b3/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  	opsiam := testAccAwsOpsworksStackIam{}
    16  	testAccAwsOpsworksStackPopulateIam(t, &opsiam)
    17  
    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: fmt.Sprintf(testAccAwsOpsworksCustomLayerConfigCreate, opsiam.ServiceRoleArn, opsiam.InstanceProfileArn),
    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: fmt.Sprintf(testAccAwsOpsworksCustomLayerConfigUpdate, opsiam.ServiceRoleArn, opsiam.InstanceProfileArn),
    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  	if len(s.RootModule().Resources) > 0 {
   138  		return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
   139  	}
   140  
   141  	return nil
   142  }
   143  
   144  var testAccAwsOpsworksCustomLayerSecurityGroups = `
   145  resource "aws_security_group" "tf-ops-acc-layer1" {
   146    name = "tf-ops-acc-layer1"
   147    ingress {
   148      from_port = 8
   149      to_port = -1
   150      protocol = "icmp"
   151      cidr_blocks = ["0.0.0.0/0"]
   152    }
   153  }
   154  resource "aws_security_group" "tf-ops-acc-layer2" {
   155    name = "tf-ops-acc-layer2"
   156    ingress {
   157      from_port = 8
   158      to_port = -1
   159      protocol = "icmp"
   160      cidr_blocks = ["0.0.0.0/0"]
   161    }
   162  }
   163  `
   164  
   165  var testAccAwsOpsworksCustomLayerConfigCreate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + `
   166  resource "aws_opsworks_custom_layer" "tf-acc" {
   167    stack_id = "${aws_opsworks_stack.tf-acc.id}"
   168    name = "tf-ops-acc-custom-layer"
   169    short_name = "tf-ops-acc-custom-layer"
   170    auto_assign_public_ips = true
   171    custom_security_group_ids = [
   172      "${aws_security_group.tf-ops-acc-layer1.id}",
   173      "${aws_security_group.tf-ops-acc-layer2.id}",
   174    ]
   175    drain_elb_on_shutdown = true
   176    instance_shutdown_timeout = 300
   177    system_packages = [
   178      "git",
   179      "golang",
   180    ]
   181    ebs_volume {
   182      type = "gp2"
   183      number_of_disks = 2
   184      mount_point = "/home"
   185      size = 100
   186      raid_level = 0
   187    }
   188  }
   189  `
   190  
   191  var testAccAwsOpsworksCustomLayerConfigUpdate = testAccAwsOpsworksStackConfigNoVpcCreate + testAccAwsOpsworksCustomLayerSecurityGroups + `
   192  resource "aws_security_group" "tf-ops-acc-layer3" {
   193    name = "tf-ops-acc-layer3"
   194    ingress {
   195      from_port = 8
   196      to_port = -1
   197      protocol = "icmp"
   198      cidr_blocks = ["0.0.0.0/0"]
   199    }
   200  }
   201  resource "aws_opsworks_custom_layer" "tf-acc" {
   202    stack_id = "${aws_opsworks_stack.tf-acc.id}"
   203    name = "tf-ops-acc-custom-layer"
   204    short_name = "tf-ops-acc-custom-layer"
   205    auto_assign_public_ips = true
   206    custom_security_group_ids = [
   207      "${aws_security_group.tf-ops-acc-layer1.id}",
   208      "${aws_security_group.tf-ops-acc-layer2.id}",
   209      "${aws_security_group.tf-ops-acc-layer3.id}",
   210    ]
   211    drain_elb_on_shutdown = false
   212    instance_shutdown_timeout = 120
   213    system_packages = [
   214      "git",
   215      "golang",
   216      "subversion",
   217    ]
   218    ebs_volume {
   219      type = "gp2"
   220      number_of_disks = 2
   221      mount_point = "/home"
   222      size = 100
   223      raid_level = 0
   224    }
   225    ebs_volume {
   226      type = "io1"
   227      number_of_disks = 4
   228      mount_point = "/var"
   229      size = 100
   230      raid_level = 1
   231      iops = 3000
   232    }
   233  }
   234  `