@@ -11,19 +11,21 @@ import (
1111)
1212
1313func TestAccAWSKmsAlias_basic (t * testing.T ) {
14+ rInt := acctest .RandInt ()
15+ kmsAliasTimestamp := time .Now ().Format (time .RFC1123 )
1416 resource .Test (t , resource.TestCase {
1517 PreCheck : func () { testAccPreCheck (t ) },
1618 Providers : testAccProviders ,
1719 CheckDestroy : testAccCheckAWSKmsAliasDestroy ,
1820 Steps : []resource.TestStep {
19- resource. TestStep {
20- Config : testAccAWSKmsSingleAlias ,
21+ {
22+ Config : testAccAWSKmsSingleAlias ( rInt , kmsAliasTimestamp ) ,
2123 Check : resource .ComposeTestCheckFunc (
2224 testAccCheckAWSKmsAliasExists ("aws_kms_alias.single" ),
2325 ),
2426 },
25- resource. TestStep {
26- Config : testAccAWSKmsSingleAlias_modified ,
27+ {
28+ Config : testAccAWSKmsSingleAlias_modified ( rInt , kmsAliasTimestamp ) ,
2729 Check : resource .ComposeTestCheckFunc (
2830 testAccCheckAWSKmsAliasExists ("aws_kms_alias.single" ),
2931 ),
@@ -33,13 +35,15 @@ func TestAccAWSKmsAlias_basic(t *testing.T) {
3335}
3436
3537func TestAccAWSKmsAlias_name_prefix (t * testing.T ) {
38+ rInt := acctest .RandInt ()
39+ kmsAliasTimestamp := time .Now ().Format (time .RFC1123 )
3640 resource .Test (t , resource.TestCase {
3741 PreCheck : func () { testAccPreCheck (t ) },
3842 Providers : testAccProviders ,
3943 CheckDestroy : testAccCheckAWSKmsAliasDestroy ,
4044 Steps : []resource.TestStep {
41- resource. TestStep {
42- Config : testAccAWSKmsSingleAlias ,
45+ {
46+ Config : testAccAWSKmsSingleAlias ( rInt , kmsAliasTimestamp ) ,
4347 Check : resource .ComposeTestCheckFunc (
4448 testAccCheckAWSKmsAliasExists ("aws_kms_alias.name_prefix" ),
4549 ),
@@ -49,13 +53,15 @@ func TestAccAWSKmsAlias_name_prefix(t *testing.T) {
4953}
5054
5155func TestAccAWSKmsAlias_no_name (t * testing.T ) {
56+ rInt := acctest .RandInt ()
57+ kmsAliasTimestamp := time .Now ().Format (time .RFC1123 )
5258 resource .Test (t , resource.TestCase {
5359 PreCheck : func () { testAccPreCheck (t ) },
5460 Providers : testAccProviders ,
5561 CheckDestroy : testAccCheckAWSKmsAliasDestroy ,
5662 Steps : []resource.TestStep {
57- resource. TestStep {
58- Config : testAccAWSKmsSingleAlias ,
63+ {
64+ Config : testAccAWSKmsSingleAlias ( rInt , kmsAliasTimestamp ) ,
5965 Check : resource .ComposeTestCheckFunc (
6066 testAccCheckAWSKmsAliasExists ("aws_kms_alias.nothing" ),
6167 ),
@@ -65,13 +71,15 @@ func TestAccAWSKmsAlias_no_name(t *testing.T) {
6571}
6672
6773func TestAccAWSKmsAlias_multiple (t * testing.T ) {
74+ rInt := acctest .RandInt ()
75+ kmsAliasTimestamp := time .Now ().Format (time .RFC1123 )
6876 resource .Test (t , resource.TestCase {
6977 PreCheck : func () { testAccPreCheck (t ) },
7078 Providers : testAccProviders ,
7179 CheckDestroy : testAccCheckAWSKmsAliasDestroy ,
7280 Steps : []resource.TestStep {
73- resource. TestStep {
74- Config : testAccAWSKmsMultipleAliases ,
81+ {
82+ Config : testAccAWSKmsMultipleAliases ( rInt , kmsAliasTimestamp ) ,
7583 Check : resource .ComposeTestCheckFunc (
7684 testAccCheckAWSKmsAliasExists ("aws_kms_alias.one" ),
7785 testAccCheckAWSKmsAliasExists ("aws_kms_alias.two" ),
@@ -114,8 +122,8 @@ func testAccCheckAWSKmsAliasExists(name string) resource.TestCheckFunc {
114122 }
115123}
116124
117- var kmsAliasTimestamp = time . Now (). Format ( time . RFC1123 )
118- var testAccAWSKmsSingleAlias = fmt .Sprintf (`
125+ func testAccAWSKmsSingleAlias ( rInt int , timestamp string ) string {
126+ return fmt .Sprintf (`
119127resource "aws_kms_key" "one" {
120128 description = "Terraform acc test One %s"
121129 deletion_window_in_days = 7
@@ -126,7 +134,7 @@ resource "aws_kms_key" "two" {
126134}
127135
128136resource "aws_kms_alias" "name_prefix" {
129- name_prefix = "alias/tf-acc-key-alias"
137+ name_prefix = "alias/tf-acc-key-alias-%d "
130138 target_key_id = "${aws_kms_key.one.key_id}"
131139}
132140
@@ -135,11 +143,13 @@ resource "aws_kms_alias" "nothing" {
135143}
136144
137145resource "aws_kms_alias" "single" {
138- name = "alias/tf-acc-key-alias"
146+ name = "alias/tf-acc-key-alias-%d "
139147 target_key_id = "${aws_kms_key.one.key_id}"
140- }` , kmsAliasTimestamp , kmsAliasTimestamp )
148+ }` , timestamp , timestamp , rInt , rInt )
149+ }
141150
142- var testAccAWSKmsSingleAlias_modified = fmt .Sprintf (`
151+ func testAccAWSKmsSingleAlias_modified (rInt int , timestamp string ) string {
152+ return fmt .Sprintf (`
143153resource "aws_kms_key" "one" {
144154 description = "Terraform acc test One %s"
145155 deletion_window_in_days = 7
@@ -150,21 +160,24 @@ resource "aws_kms_key" "two" {
150160}
151161
152162resource "aws_kms_alias" "single" {
153- name = "alias/tf-acc-key-alias"
163+ name = "alias/tf-acc-key-alias-%d "
154164 target_key_id = "${aws_kms_key.two.key_id}"
155- }` , kmsAliasTimestamp , kmsAliasTimestamp )
165+ }` , timestamp , timestamp , rInt )
166+ }
156167
157- var testAccAWSKmsMultipleAliases = fmt .Sprintf (`
168+ func testAccAWSKmsMultipleAliases (rInt int , timestamp string ) string {
169+ return fmt .Sprintf (`
158170resource "aws_kms_key" "single" {
159171 description = "Terraform acc test One %s"
160172 deletion_window_in_days = 7
161173}
162174
163175resource "aws_kms_alias" "one" {
164- name = "alias/tf-acc-key- alias-%s "
176+ name = "alias/tf-acc-alias-one-%d "
165177 target_key_id = "${aws_kms_key.single.key_id}"
166178}
167179resource "aws_kms_alias" "two" {
168- name = "alias/tf-acc-key- alias-%s "
180+ name = "alias/tf-acc-alias-two-%d "
169181 target_key_id = "${aws_kms_key.single.key_id}"
170- }` , kmsAliasTimestamp , acctest .RandString (5 ), acctest .RandString (5 ))
182+ }` , timestamp , rInt , rInt )
183+ }
0 commit comments