@@ -10,18 +10,20 @@ import (
1010 "github.com/aws/aws-sdk-go/aws/awserr"
1111 "github.com/aws/aws-sdk-go/service/elb"
1212
13+ "github.com/hashicorp/terraform/helper/acctest"
1314 "github.com/hashicorp/terraform/helper/resource"
1415 "github.com/hashicorp/terraform/terraform"
1516)
1617
1718func TestAccAWSLoadBalancerPolicy_basic (t * testing.T ) {
19+ rInt := acctest .RandInt ()
1820 resource .Test (t , resource.TestCase {
1921 PreCheck : func () { testAccPreCheck (t ) },
2022 Providers : testAccProviders ,
2123 CheckDestroy : testAccCheckAWSLoadBalancerPolicyDestroy ,
2224 Steps : []resource.TestStep {
23- resource. TestStep {
24- Config : testAccAWSLoadBalancerPolicyConfig_basic ,
25+ {
26+ Config : testAccAWSLoadBalancerPolicyConfig_basic ( rInt ) ,
2527 Check : resource .ComposeTestCheckFunc (
2628 testAccCheckAWSLoadBalancerPolicyState ("aws_elb.test-lb" , "aws_load_balancer_policy.test-policy" ),
2729 ),
@@ -31,19 +33,20 @@ func TestAccAWSLoadBalancerPolicy_basic(t *testing.T) {
3133}
3234
3335func TestAccAWSLoadBalancerPolicy_updateWhileAssigned (t * testing.T ) {
36+ rInt := acctest .RandInt ()
3437 resource .Test (t , resource.TestCase {
3538 PreCheck : func () { testAccPreCheck (t ) },
3639 Providers : testAccProviders ,
3740 CheckDestroy : testAccCheckAWSLoadBalancerPolicyDestroy ,
3841 Steps : []resource.TestStep {
39- resource. TestStep {
40- Config : testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0 ,
42+ {
43+ Config : testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0 ( rInt ) ,
4144 Check : resource .ComposeTestCheckFunc (
4245 testAccCheckAWSLoadBalancerPolicyState ("aws_elb.test-lb" , "aws_load_balancer_policy.test-policy" ),
4346 ),
4447 },
45- resource. TestStep {
46- Config : testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1 ,
48+ {
49+ Config : testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1 ( rInt ) ,
4750 Check : resource .ComposeTestCheckFunc (
4851 testAccCheckAWSLoadBalancerPolicyState ("aws_elb.test-lb" , "aws_load_balancer_policy.test-policy" ),
4952 ),
@@ -139,102 +142,105 @@ func testAccCheckAWSLoadBalancerPolicyState(elbResource string, policyResource s
139142 }
140143}
141144
142- const testAccAWSLoadBalancerPolicyConfig_basic = `
143- resource "aws_elb" "test-lb" {
144- name = "test-aws-policies-lb"
145- availability_zones = ["us-west-2a"]
146-
147- listener {
148- instance_port = 80
149- instance_protocol = "http"
150- lb_port = 80
151- lb_protocol = "http"
152- }
153-
154- tags {
155- Name = "tf-acc-test"
156- }
157- }
145+ func testAccAWSLoadBalancerPolicyConfig_basic (rInt int ) string {
146+ return fmt .Sprintf (`
147+ resource "aws_elb" "test-lb" {
148+ name = "test-lb-%d"
149+ availability_zones = ["us-west-2a"]
150+
151+ listener {
152+ instance_port = 80
153+ instance_protocol = "http"
154+ lb_port = 80
155+ lb_protocol = "http"
156+ }
158157
159- resource "aws_load_balancer_policy" "test-policy" {
160- load_balancer_name = "${aws_elb.test-lb.name}"
161- policy_name = "test-policy-policy"
162- policy_type_name = "AppCookieStickinessPolicyType"
163- policy_attribute = {
164- name = "CookieName"
165- value = "magic_cookie"
166- }
167- }
168- `
169-
170- const testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0 = `
171- resource "aws_elb" "test-lb" {
172- name = "test-aws-policies-lb"
173- availability_zones = ["us-west-2a"]
174-
175- listener {
176- instance_port = 80
177- instance_protocol = "http"
178- lb_port = 80
179- lb_protocol = "http"
180- }
181-
182- tags {
183- Name = "tf-acc-test"
184- }
185- }
158+ tags {
159+ Name = "tf-acc-test"
160+ }
161+ }
186162
187- resource "aws_load_balancer_policy" "test-policy" {
188- load_balancer_name = "${aws_elb.test-lb.name}"
189- policy_name = "test-policy-policy"
190- policy_type_name = "AppCookieStickinessPolicyType"
191- policy_attribute = {
192- name = "CookieName"
193- value = "magic_cookie"
194- }
163+ resource "aws_load_balancer_policy" "test-policy" {
164+ load_balancer_name = "${aws_elb.test-lb.name}"
165+ policy_name = "test-policy-%d"
166+ policy_type_name = "AppCookieStickinessPolicyType"
167+ policy_attribute = {
168+ name = "CookieName"
169+ value = "magic_cookie"
170+ }
171+ }` , rInt , rInt )
195172}
196173
197- resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
198- load_balancer_name = "${aws_elb.test-lb.name}"
199- load_balancer_port = 80
200- policy_names = [
201- "${aws_load_balancer_policy.test-policy.policy_name}"
202- ]
203- }
204- `
205-
206- const testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1 = `
207- resource "aws_elb" "test-lb" {
208- name = "test-aws-policies-lb"
209- availability_zones = ["us-west-2a"]
210-
211- listener {
212- instance_port = 80
213- instance_protocol = "http"
214- lb_port = 80
215- lb_protocol = "http"
216- }
217-
218- tags {
219- Name = "tf-acc-test"
220- }
221- }
174+ func testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned0 (rInt int ) string {
175+ return fmt .Sprintf (`
176+ resource "aws_elb" "test-lb" {
177+ name = "test-lb-%d"
178+ availability_zones = ["us-west-2a"]
179+
180+ listener {
181+ instance_port = 80
182+ instance_protocol = "http"
183+ lb_port = 80
184+ lb_protocol = "http"
185+ }
186+
187+ tags {
188+ Name = "tf-acc-test"
189+ }
190+ }
191+
192+ resource "aws_load_balancer_policy" "test-policy" {
193+ load_balancer_name = "${aws_elb.test-lb.name}"
194+ policy_name = "test-policy-%d"
195+ policy_type_name = "AppCookieStickinessPolicyType"
196+ policy_attribute = {
197+ name = "CookieName"
198+ value = "magic_cookie"
199+ }
200+ }
222201
223- resource "aws_load_balancer_policy" "test-policy" {
224- load_balancer_name = "${aws_elb.test-lb.name}"
225- policy_name = "test-policy-policy"
226- policy_type_name = "AppCookieStickinessPolicyType"
227- policy_attribute = {
228- name = "CookieName"
229- value = "unicorn_cookie"
230- }
202+ resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
203+ load_balancer_name = "${aws_elb.test-lb.name}"
204+ load_balancer_port = 80
205+ policy_names = [
206+ "${aws_load_balancer_policy.test-policy.policy_name}"
207+ ]
208+ }` , rInt , rInt )
231209}
232210
233- resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
234- load_balancer_name = "${aws_elb.test-lb.name}"
235- load_balancer_port = 80
236- policy_names = [
237- "${aws_load_balancer_policy.test-policy.policy_name}"
238- ]
211+ func testAccAWSLoadBalancerPolicyConfig_updateWhileAssigned1 (rInt int ) string {
212+ return fmt .Sprintf (`
213+ resource "aws_elb" "test-lb" {
214+ name = "test-lb-%d"
215+ availability_zones = ["us-west-2a"]
216+
217+ listener {
218+ instance_port = 80
219+ instance_protocol = "http"
220+ lb_port = 80
221+ lb_protocol = "http"
222+ }
223+
224+ tags {
225+ Name = "tf-acc-test"
226+ }
227+ }
228+
229+ resource "aws_load_balancer_policy" "test-policy" {
230+ load_balancer_name = "${aws_elb.test-lb.name}"
231+ policy_name = "test-policy-%d"
232+ policy_type_name = "AppCookieStickinessPolicyType"
233+ policy_attribute = {
234+ name = "CookieName"
235+ value = "unicorn_cookie"
236+ }
237+ }
238+
239+ resource "aws_load_balancer_listener_policy" "test-lb-test-policy-80" {
240+ load_balancer_name = "${aws_elb.test-lb.name}"
241+ load_balancer_port = 80
242+ policy_names = [
243+ "${aws_load_balancer_policy.test-policy.policy_name}"
244+ ]
245+ }` , rInt , rInt )
239246}
240- `
0 commit comments