-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
resource/aws_instance: Ignore change of user_data from omission to empty #5467
Conversation
@zehua can you please provide a previously failing acceptance test or configuration for this behavior so we can ensure we don't create a regression in the future? Thanks. |
@bflad I don't think there is an acceptance test that covers this. To demonstrate the bug, use the example tf file from https://www.terraform.io/docs/providers/aws/r/instance.html
init, plan and apply this to create a t2.micro instance. Then update the tf file to include an empty
Now run plan, expected output is no changes, but actual output is:
Running plan with a build from this branch produced the correct expected output. |
I've updated #4954 where i'm running into inconsistencies across MacOS and RHEL 7.5 |
ping @bflad |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the extra information, @zehua -- I was able to implement acceptance testing to cover this:
func TestAccAWSInstance_UserData_EmptyStringToUnspecified(t *testing.T) {
var instance ec2.Instance
rInt := acctest.RandInt()
resourceName := "aws_instance.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_UserData_EmptyString(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(resourceName, &instance),
),
},
// Switching should show no difference
{
Config: testAccInstanceConfig_UserData_Unspecified(rInt),
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})
}
func TestAccAWSInstance_UserData_UnspecifiedToEmptyString(t *testing.T) {
var instance ec2.Instance
rInt := acctest.RandInt()
resourceName := "aws_instance.test"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccInstanceConfig_UserData_Unspecified(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckInstanceExists(resourceName, &instance),
),
},
// Switching should show no difference
{
Config: testAccInstanceConfig_UserData_EmptyString(rInt),
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})
}
func testAccInstanceConfig_UserData_Base(rInt int) string {
return fmt.Sprintf(`
data "aws_ami" "amzn-ami-minimal-hvm-ebs" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn-ami-minimal-hvm-*"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}
resource "aws_vpc" "test" {
cidr_block = "172.16.0.0/16"
tags {
Name = "tf-acctest-%d"
}
}
resource "aws_subnet" "test" {
vpc_id = "${aws_vpc.test.id}"
cidr_block = "172.16.0.0/24"
tags {
Name = "tf-acctest-%d"
}
}
`, rInt, rInt)
}
func testAccInstanceConfig_UserData_Unspecified(rInt int) string {
return testAccInstanceConfig_UserData_Base(rInt) + `
resource "aws_instance" "test" {
ami = "${data.aws_ami.amzn-ami-minimal-hvm-ebs.id}"
instance_type = "t2.micro"
subnet_id = "${aws_subnet.test.id}"
}
`
}
func testAccInstanceConfig_UserData_EmptyString(rInt int) string {
return testAccInstanceConfig_UserData_Base(rInt) + `
resource "aws_instance" "test" {
ami = "${data.aws_ami.amzn-ami-minimal-hvm-ebs.id}"
instance_type = "t2.micro"
subnet_id = "${aws_subnet.test.id}"
user_data = ""
}
`
}
Before 66f2cbc:
--- FAIL: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (124.83s)
testing.go:527: Step 1 error: After applying this step, the plan was not empty:
DIFF:
DESTROY/CREATE: aws_instance.test
...
user_data: "" => "da39a3ee5e6b4b0d3255bfef95601890afd80709" (forces new resource)
After:
--- PASS: TestAccAWSInstance_UserData_EmptyStringToUnspecified (125.19s)
--- PASS: TestAccAWSInstance_UserData_UnspecifiedToEmptyString (145.57s)
This has been released in version 1.33.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #4954
https://github.com/terraform-providers/terraform-provider-aws/pull/4991/files#r208085096 fixed the issue when changing from empty
user_data
to omitting the field. But the other way is also a valid case that we should ignore, i.e., changing from omitting theuser_data
field to giving it an empty value.Changes proposed in this pull request:
Did not run acceptance testing. But I've tested it locally.