From 145fa084f95577bc46cf8609f7dfae54580dc89f Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 11 May 2017 14:06:06 +0200 Subject: [PATCH] provider/aws: Randomize key pair name for EC2 instance test (#14389) --- .../providers/aws/resource_aws_instance_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index a88fc8fdeb..e8f93547e1 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -860,6 +860,8 @@ func TestAccAWSInstance_keyPairCheck(t *testing.T) { } } + keyPairName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5)) + resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, IDRefreshName: "aws_instance.foo", @@ -868,10 +870,10 @@ func TestAccAWSInstance_keyPairCheck(t *testing.T) { CheckDestroy: testAccCheckInstanceDestroy, Steps: []resource.TestStep{ { - Config: testAccInstanceConfigKeyPair, + Config: testAccInstanceConfigKeyPair(keyPairName), Check: resource.ComposeTestCheckFunc( testAccCheckInstanceExists("aws_instance.foo", &v), - testCheckKeyPair("tmp-key"), + testCheckKeyPair(keyPairName), ), }, }, @@ -1852,13 +1854,14 @@ resource "aws_eip" "foo_eip" { } ` -const testAccInstanceConfigKeyPair = ` +func testAccInstanceConfigKeyPair(keyPairName string) string { + return fmt.Sprintf(` provider "aws" { region = "us-east-1" } resource "aws_key_pair" "debugging" { - key_name = "tmp-key" + key_name = "%s" public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com" } @@ -1870,7 +1873,8 @@ resource "aws_instance" "foo" { Name = "testAccInstanceConfigKeyPair_TestAMI" } } -` +`, keyPairName) +} const testAccInstanceConfigRootBlockDeviceMismatch = ` resource "aws_vpc" "foo" {