github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/aws/resource_aws_proxy_protocol_policy_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  func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:     func() { testAccPreCheck(t) },
    14  		Providers:    testAccProviders,
    15  		CheckDestroy: testAccCheckProxyProtocolPolicyDestroy,
    16  		Steps: []resource.TestStep{
    17  			resource.TestStep{
    18  				Config: testAccProxyProtocolPolicyConfig,
    19  				Check: resource.ComposeTestCheckFunc(
    20  					resource.TestCheckResourceAttr(
    21  						"aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"),
    22  					resource.TestCheckResourceAttr(
    23  						"aws_proxy_protocol_policy.smtp", "instance_ports.#", "1"),
    24  					resource.TestCheckResourceAttr(
    25  						"aws_proxy_protocol_policy.smtp", "instance_ports.4196041389", "25"),
    26  				),
    27  			},
    28  			resource.TestStep{
    29  				Config: testAccProxyProtocolPolicyConfigUpdate,
    30  				Check: resource.ComposeTestCheckFunc(
    31  					resource.TestCheckResourceAttr(
    32  						"aws_proxy_protocol_policy.smtp", "load_balancer", "test-lb"),
    33  					resource.TestCheckResourceAttr(
    34  						"aws_proxy_protocol_policy.smtp", "instance_ports.#", "2"),
    35  					resource.TestCheckResourceAttr(
    36  						"aws_proxy_protocol_policy.smtp", "instance_ports.4196041389", "25"),
    37  					resource.TestCheckResourceAttr(
    38  						"aws_proxy_protocol_policy.smtp", "instance_ports.1925441437", "587"),
    39  				),
    40  			},
    41  		},
    42  	})
    43  }
    44  
    45  func testAccCheckProxyProtocolPolicyDestroy(s *terraform.State) error {
    46  	if len(s.RootModule().Resources) > 0 {
    47  		return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
    48  	}
    49  
    50  	return nil
    51  }
    52  
    53  const testAccProxyProtocolPolicyConfig = `
    54  resource "aws_elb" "lb" {
    55  	name = "test-lb"
    56  	availability_zones = ["us-west-2a"]
    57  
    58  	listener {
    59  		instance_port = 25
    60  		instance_protocol = "tcp"
    61  		lb_port = 25
    62  		lb_protocol = "tcp"
    63  	}
    64  
    65  	listener {
    66  		instance_port = 587
    67  		instance_protocol = "tcp"
    68  		lb_port = 587
    69  		lb_protocol = "tcp"
    70  	}
    71  }
    72  
    73  resource "aws_proxy_protocol_policy" "smtp" {
    74  	load_balancer = "${aws_elb.lb.name}"
    75  	instance_ports = ["25"]
    76  }
    77  `
    78  
    79  const testAccProxyProtocolPolicyConfigUpdate = `
    80  resource "aws_elb" "lb" {
    81  	name = "test-lb"
    82  	availability_zones = ["us-west-2a"]
    83  
    84  	listener {
    85  		instance_port = 25
    86  		instance_protocol = "tcp"
    87  		lb_port = 25
    88  		lb_protocol = "tcp"
    89  	}
    90  
    91  	listener {
    92  		instance_port = 587
    93  		instance_protocol = "tcp"
    94  		lb_port = 587
    95  		lb_protocol = "tcp"
    96  	}
    97  }
    98  
    99  resource "aws_proxy_protocol_policy" "smtp" {
   100  	load_balancer = "${aws_elb.lb.name}"
   101  	instance_ports = ["25", "587"]
   102  }
   103  `