mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/aws: fix testAccInstanceDataSourceConfig_keyPair from possibly leaking instances if tmp-key already existed
This commit is contained in:
parent
767764ff10
commit
86bf9fde83
@ -173,12 +173,13 @@ func TestAccAWSInstanceDataSource_privateIP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccAWSInstanceDataSource_keyPair(t *testing.T) {
|
func TestAccAWSInstanceDataSource_keyPair(t *testing.T) {
|
||||||
|
rName := fmt.Sprintf("tf-test-key-%d", acctest.RandInt())
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
{
|
{
|
||||||
Config: testAccInstanceDataSourceConfig_keyPair,
|
Config: testAccInstanceDataSourceConfig_keyPair(rName),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"data.aws_instance.foo", "ami", "ami-408c7f28"),
|
"data.aws_instance.foo", "ami", "ami-408c7f28"),
|
||||||
@ -187,7 +188,7 @@ func TestAccAWSInstanceDataSource_keyPair(t *testing.T) {
|
|||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"data.aws_instance.foo", "tags.#", "1"),
|
"data.aws_instance.foo", "tags.#", "1"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"data.aws_instance.foo", "key_name", "tmp-key"),
|
"data.aws_instance.foo", "key_name", rName),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -415,13 +416,14 @@ data "aws_instance" "foo" {
|
|||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
const testAccInstanceDataSourceConfig_keyPair = `
|
func testAccInstanceDataSourceConfig_keyPair(rName string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
provider "aws" {
|
provider "aws" {
|
||||||
region = "us-east-1"
|
region = "us-east-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_key_pair" "debugging" {
|
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"
|
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 phodgson@thoughtworks.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -443,8 +445,8 @@ data "aws_instance" "foo" {
|
|||||||
name = "key-name"
|
name = "key-name"
|
||||||
values = ["${aws_instance.foo.key_name}"]
|
values = ["${aws_instance.foo.key_name}"]
|
||||||
}
|
}
|
||||||
|
}`, rName)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
||||||
const testAccInstanceDataSourceConfig_VPC = `
|
const testAccInstanceDataSourceConfig_VPC = `
|
||||||
resource "aws_vpc" "foo" {
|
resource "aws_vpc" "foo" {
|
||||||
|
Loading…
Reference in New Issue
Block a user