github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/data_source_aws_alb_test.go (about)

     1  package aws
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/acctest"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccDataSourceAWSALB_basic(t *testing.T) {
    12  	albName := fmt.Sprintf("testaccawsalb-basic-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
    13  
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:  func() { testAccPreCheck(t) },
    16  		Providers: testAccProviders,
    17  		Steps: []resource.TestStep{
    18  			{
    19  				Config: testAccDataSourceAWSALBConfigBasic(albName),
    20  				Check: resource.ComposeAggregateTestCheckFunc(
    21  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "name", albName),
    22  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "internal", "false"),
    23  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "subnets.#", "2"),
    24  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "security_groups.#", "1"),
    25  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "tags.%", "1"),
    26  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "tags.TestName", "TestAccAWSALB_basic"),
    27  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "enable_deletion_protection", "false"),
    28  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_arn", "idle_timeout", "30"),
    29  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "vpc_id"),
    30  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "zone_id"),
    31  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "dns_name"),
    32  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_arn", "arn"),
    33  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "name", albName),
    34  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "internal", "false"),
    35  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "subnets.#", "2"),
    36  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "security_groups.#", "1"),
    37  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "tags.%", "1"),
    38  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "tags.TestName", "TestAccAWSALB_basic"),
    39  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "enable_deletion_protection", "false"),
    40  					resource.TestCheckResourceAttr("data.aws_alb.alb_test_with_name", "idle_timeout", "30"),
    41  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_name", "vpc_id"),
    42  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_name", "zone_id"),
    43  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_name", "dns_name"),
    44  					resource.TestCheckResourceAttrSet("data.aws_alb.alb_test_with_name", "arn"),
    45  				),
    46  			},
    47  		},
    48  	})
    49  }
    50  
    51  func testAccDataSourceAWSALBConfigBasic(albName string) string {
    52  	return fmt.Sprintf(`resource "aws_alb" "alb_test" {
    53    name            = "%s"
    54    internal        = false
    55    security_groups = ["${aws_security_group.alb_test.id}"]
    56    subnets         = ["${aws_subnet.alb_test.*.id}"]
    57  
    58    idle_timeout = 30
    59    enable_deletion_protection = false
    60  
    61    tags {
    62      TestName = "TestAccAWSALB_basic"
    63    }
    64  }
    65  
    66  variable "subnets" {
    67    default = ["10.0.1.0/24", "10.0.2.0/24"]
    68    type    = "list"
    69  }
    70  
    71  data "aws_availability_zones" "available" {}
    72  
    73  resource "aws_vpc" "alb_test" {
    74    cidr_block = "10.0.0.0/16"
    75  
    76    tags {
    77      TestName = "TestAccAWSALB_basic"
    78    }
    79  }
    80  
    81  resource "aws_subnet" "alb_test" {
    82    count                   = 2
    83    vpc_id                  = "${aws_vpc.alb_test.id}"
    84    cidr_block              = "${element(var.subnets, count.index)}"
    85    map_public_ip_on_launch = true
    86    availability_zone       = "${element(data.aws_availability_zones.available.names, count.index)}"
    87  
    88    tags {
    89      TestName = "TestAccAWSALB_basic"
    90    }
    91  }
    92  
    93  resource "aws_security_group" "alb_test" {
    94    name        = "allow_all_alb_test"
    95    description = "Used for ALB Testing"
    96    vpc_id      = "${aws_vpc.alb_test.id}"
    97  
    98    ingress {
    99      from_port   = 0
   100      to_port     = 0
   101      protocol    = "-1"
   102      cidr_blocks = ["0.0.0.0/0"]
   103    }
   104  
   105    egress {
   106      from_port   = 0
   107      to_port     = 0
   108      protocol    = "-1"
   109      cidr_blocks = ["0.0.0.0/0"]
   110    }
   111  
   112    tags {
   113      TestName = "TestAccAWSALB_basic"
   114    }
   115  }
   116  
   117  data "aws_alb" "alb_test_with_arn" {
   118  	arn = "${aws_alb.alb_test.arn}"
   119  }
   120  
   121  data "aws_alb" "alb_test_with_name" {
   122  	name = "${aws_alb.alb_test.name}"
   123  }`, albName)
   124  }