github.com/tam7t/terraform@v0.7.0-rc2.0.20160705125922-be2469a05c5e/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/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/service/elb" 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAWSProxyProtocolPolicy_basic(t *testing.T) { 15 lbName := fmt.Sprintf("tf-test-lb-%s", acctest.RandString(5)) 16 resource.Test(t, resource.TestCase{ 17 PreCheck: func() { testAccPreCheck(t) }, 18 Providers: testAccProviders, 19 CheckDestroy: testAccCheckProxyProtocolPolicyDestroy, 20 Steps: []resource.TestStep{ 21 resource.TestStep{ 22 Config: testAccProxyProtocolPolicyConfig(lbName), 23 Check: resource.ComposeTestCheckFunc( 24 resource.TestCheckResourceAttr( 25 "aws_proxy_protocol_policy.smtp", "load_balancer", lbName), 26 resource.TestCheckResourceAttr( 27 "aws_proxy_protocol_policy.smtp", "instance_ports.#", "1"), 28 resource.TestCheckResourceAttr( 29 "aws_proxy_protocol_policy.smtp", "instance_ports.4196041389", "25"), 30 ), 31 }, 32 resource.TestStep{ 33 Config: testAccProxyProtocolPolicyConfigUpdate(lbName), 34 Check: resource.ComposeTestCheckFunc( 35 resource.TestCheckResourceAttr( 36 "aws_proxy_protocol_policy.smtp", "load_balancer", lbName), 37 resource.TestCheckResourceAttr( 38 "aws_proxy_protocol_policy.smtp", "instance_ports.#", "2"), 39 resource.TestCheckResourceAttr( 40 "aws_proxy_protocol_policy.smtp", "instance_ports.4196041389", "25"), 41 resource.TestCheckResourceAttr( 42 "aws_proxy_protocol_policy.smtp", "instance_ports.1925441437", "587"), 43 ), 44 }, 45 }, 46 }) 47 } 48 49 func testAccCheckProxyProtocolPolicyDestroy(s *terraform.State) error { 50 conn := testAccProvider.Meta().(*AWSClient).elbconn 51 52 for _, rs := range s.RootModule().Resources { 53 if rs.Type != "aws_placement_group" { 54 continue 55 } 56 57 req := &elb.DescribeLoadBalancersInput{ 58 LoadBalancerNames: []*string{ 59 aws.String(rs.Primary.Attributes["load_balancer"])}, 60 } 61 _, err := conn.DescribeLoadBalancers(req) 62 if err != nil { 63 // Verify the error is what we want 64 if isLoadBalancerNotFound(err) { 65 continue 66 } 67 return err 68 } 69 70 return fmt.Errorf("still exists") 71 } 72 return nil 73 } 74 75 func testAccProxyProtocolPolicyConfig(rName string) string { 76 return fmt.Sprintf(` 77 resource "aws_elb" "lb" { 78 name = "%s" 79 availability_zones = ["us-west-2a"] 80 81 listener { 82 instance_port = 25 83 instance_protocol = "tcp" 84 lb_port = 25 85 lb_protocol = "tcp" 86 } 87 88 listener { 89 instance_port = 587 90 instance_protocol = "tcp" 91 lb_port = 587 92 lb_protocol = "tcp" 93 } 94 } 95 96 resource "aws_proxy_protocol_policy" "smtp" { 97 load_balancer = "${aws_elb.lb.name}" 98 instance_ports = ["25"] 99 }`, rName) 100 } 101 102 func testAccProxyProtocolPolicyConfigUpdate(rName string) string { 103 return fmt.Sprintf(` 104 resource "aws_elb" "lb" { 105 name = "%s" 106 availability_zones = ["us-west-2a"] 107 108 listener { 109 instance_port = 25 110 instance_protocol = "tcp" 111 lb_port = 25 112 lb_protocol = "tcp" 113 } 114 115 listener { 116 instance_port = 587 117 instance_protocol = "tcp" 118 lb_port = 587 119 lb_protocol = "tcp" 120 } 121 } 122 123 resource "aws_proxy_protocol_policy" "smtp" { 124 load_balancer = "${aws_elb.lb.name}" 125 instance_ports = ["25", "587"] 126 }`, rName) 127 }