@@ -173,12 +173,13 @@ func TestAccAWSInstanceDataSource_privateIP(t *testing.T) {
173173}
174174
175175func TestAccAWSInstanceDataSource_keyPair (t * testing.T ) {
176+ rName := fmt .Sprintf ("tf-test-key-%d" , acctest .RandInt ())
176177 resource .Test (t , resource.TestCase {
177178 PreCheck : func () { testAccPreCheck (t ) },
178179 Providers : testAccProviders ,
179180 Steps : []resource.TestStep {
180181 {
181- Config : testAccInstanceDataSourceConfig_keyPair ,
182+ Config : testAccInstanceDataSourceConfig_keyPair ( rName ) ,
182183 Check : resource .ComposeTestCheckFunc (
183184 resource .TestCheckResourceAttr (
184185 "data.aws_instance.foo" , "ami" , "ami-408c7f28" ),
@@ -187,7 +188,7 @@ func TestAccAWSInstanceDataSource_keyPair(t *testing.T) {
187188 resource .TestCheckResourceAttr (
188189 "data.aws_instance.foo" , "tags.#" , "1" ),
189190 resource .TestCheckResourceAttr (
190- "data.aws_instance.foo" , "key_name" , "tmp-key" ),
191+ "data.aws_instance.foo" , "key_name" , rName ),
191192 ),
192193 },
193194 },
@@ -415,13 +416,14 @@ data "aws_instance" "foo" {
415416}
416417`
417418
418- const testAccInstanceDataSourceConfig_keyPair = `
419+ func testAccInstanceDataSourceConfig_keyPair (rName string ) string {
420+ return fmt .Sprintf (`
419421provider "aws" {
420422 region = "us-east-1"
421423}
422424
423425resource "aws_key_pair" "debugging" {
424- key_name = "tmp-key "
426+ key_name = "%s "
425427 public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
426428}
427429
@@ -443,8 +445,8 @@ data "aws_instance" "foo" {
443445 name = "key-name"
444446 values = ["${aws_instance.foo.key_name}"]
445447 }
448+ }` , rName )
446449}
447- `
448450
449451const testAccInstanceDataSourceConfig_VPC = `
450452resource "aws_vpc" "foo" {
0 commit comments