Skip to content
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

Security Groups with name or name_prefix starting with "terraform-" get recreated every time #17017

Closed
crubier opened this issue Jan 8, 2021 · 4 comments · Fixed by #17030
Closed
Assignees
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Milestone

Comments

@crubier
Copy link

crubier commented Jan 8, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

  • terraform v1.12 and up
  • terraform-provider-aws v2.50 and up

Affected Resource(s)

  • aws_security_group
  • potentially any other resource that uses the name / name_prefix API pattern

Terraform Configuration Files

Minimum reproduction:

resource "aws_security_group" "foobar" {
  count       = 1
  name_prefix = "terraform-baz"
  description = "Security group."
  vpc_id      = var.vpc_id
}

This is used for example in terraform-aws-eks in two places:

Debug Output

Panic Output

Expected Behavior

  • First apply: Create the security group
  • Subsequent apply: Nothing to change

Actual Behavior

  • First apply: Create the security group
  • Subsequent apply: Recreate the security group
+/- resource "aws_security_group" "foobar" {
    ...
     + name_prefix            = "terraform-baz" # forces replacement
  }

Steps to Reproduce

  1. terraform apply

Important Factoids

References

@ghost ghost added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 8, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jan 8, 2021
@bflad bflad self-assigned this Jan 8, 2021
@bflad bflad added bug Addresses a defect in current functionality. service/cloudwatchevents and removed needs-triage Waiting for first response or review from a maintainer. labels Jan 8, 2021
@bflad
Copy link
Contributor

bflad commented Jan 8, 2021

Thank you for reporting this issue, @crubier, as this is certainly unexpected behavior. Please note that the naming package is currently only in use in two resources right now with this functionality, so these resources should be the only ones affected at the moment:

  • aws_cloudwatch_event_rule
  • aws_security_group

The fix in this case should be fairly straightforward and I will try to get that submitted along with covering testing (and contributing guide documentation) later today.

bflad added a commit that referenced this issue Jan 8, 2021
Reference: #17017

Changes:

```
* resource/aws_cloudwatch_event_rule: Prevent perpetual differences with `name_prefix` argument values beginning with `terraform-`
* resource/aws_security_group: Prevent perpetual differences with `name_prefix` argument values beginning with `terraform-`
```

Output from acceptance testing:

```
--- PASS: TestAccAWSCloudWatchEventRule_basic (70.77s)
--- PASS: TestAccAWSCloudWatchEventRule_description (52.06s)
--- PASS: TestAccAWSCloudWatchEventRule_EventBusName (75.08s)
--- PASS: TestAccAWSCloudWatchEventRule_IsEnabled (68.71s)
--- PASS: TestAccAWSCloudWatchEventRule_Name_Generated (33.92s)
--- PASS: TestAccAWSCloudWatchEventRule_NamePrefix (33.93s)
--- PASS: TestAccAWSCloudWatchEventRule_pattern (50.64s)
--- PASS: TestAccAWSCloudWatchEventRule_role (48.35s)
--- PASS: TestAccAWSCloudWatchEventRule_ScheduleAndPattern (33.93s)
--- PASS: TestAccAWSCloudWatchEventRule_tags (83.41s)

--- PASS: TestAccAWSSecurityGroup_allowAll (39.02s)
--- PASS: TestAccAWSSecurityGroup_basic (38.37s)
--- PASS: TestAccAWSSecurityGroup_change (82.06s)
--- PASS: TestAccAWSSecurityGroup_CIDRandGroups (55.51s)
--- PASS: TestAccAWSSecurityGroup_defaultEgressClassic (13.81s)
--- PASS: TestAccAWSSecurityGroup_defaultEgressVPC (49.44s)
--- PASS: TestAccAWSSecurityGroup_drift (19.07s)
--- PASS: TestAccAWSSecurityGroup_driftComplex (49.44s)
--- PASS: TestAccAWSSecurityGroup_egressConfigMode (74.91s)
--- PASS: TestAccAWSSecurityGroup_egressWithPrefixList (53.22s)
--- PASS: TestAccAWSSecurityGroup_failWithDiffMismatch (39.04s)
--- PASS: TestAccAWSSecurityGroup_forceRevokeRulesFalse (682.76s)
--- PASS: TestAccAWSSecurityGroup_forceRevokeRulesTrue (737.58s)
--- PASS: TestAccAWSSecurityGroup_ingressConfigMode (73.28s)
--- PASS: TestAccAWSSecurityGroup_ingressWithCidrAndSGsClassic (14.36s)
--- PASS: TestAccAWSSecurityGroup_ingressWithCidrAndSGsVPC (39.61s)
--- PASS: TestAccAWSSecurityGroup_ingressWithPrefixList (56.36s)
--- PASS: TestAccAWSSecurityGroup_invalidCIDRBlock (6.52s)
--- PASS: TestAccAWSSecurityGroup_IPRangeAndSecurityGroupWithSameRules (48.10s)
--- PASS: TestAccAWSSecurityGroup_IPRangesWithSameRules (35.83s)
--- PASS: TestAccAWSSecurityGroup_ipv4andipv6Egress (35.09s)
--- PASS: TestAccAWSSecurityGroup_ipv6 (46.26s)
--- PASS: TestAccAWSSecurityGroup_multiIngress (45.44s)
--- PASS: TestAccAWSSecurityGroup_Name_Generated (32.72s)
--- PASS: TestAccAWSSecurityGroup_Name_TerraformPrefix (32.03s)
--- PASS: TestAccAWSSecurityGroup_NamePrefix (34.45s)
--- PASS: TestAccAWSSecurityGroup_NamePrefix_TerraformPrefix (32.44s)
--- PASS: TestAccAWSSecurityGroup_ruleDescription (112.40s)
--- PASS: TestAccAWSSecurityGroup_ruleGathering (57.85s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitCidrBlockExceededAppend (71.38s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededAllNew (88.92s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededAppend (81.66s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededPrepend (72.60s)
--- PASS: TestAccAWSSecurityGroup_rulesDropOnError (72.96s)
--- PASS: TestAccAWSSecurityGroup_self (39.48s)
--- PASS: TestAccAWSSecurityGroup_sourceSecurityGroup (31.15s)
--- PASS: TestAccAWSSecurityGroup_tags (76.38s)
--- PASS: TestAccAWSSecurityGroup_vpc (39.96s)
--- PASS: TestAccAWSSecurityGroup_vpcNegOneIngress (45.88s)
--- PASS: TestAccAWSSecurityGroup_vpcProtoNumIngress (37.04s)
```
@bflad
Copy link
Contributor

bflad commented Jan 8, 2021

Pull request submitted here: #17030

bflad added a commit that referenced this issue Feb 2, 2021
…7030)

Reference: #17017

Changes:

```
* resource/aws_cloudwatch_event_rule: Prevent perpetual differences with `name_prefix` argument values beginning with `terraform-`
* resource/aws_security_group: Prevent perpetual differences with `name_prefix` argument values beginning with `terraform-`
```

Output from acceptance testing:

```
--- PASS: TestAccAWSCloudWatchEventRule_basic (70.77s)
--- PASS: TestAccAWSCloudWatchEventRule_description (52.06s)
--- PASS: TestAccAWSCloudWatchEventRule_EventBusName (75.08s)
--- PASS: TestAccAWSCloudWatchEventRule_IsEnabled (68.71s)
--- PASS: TestAccAWSCloudWatchEventRule_Name_Generated (33.92s)
--- PASS: TestAccAWSCloudWatchEventRule_NamePrefix (33.93s)
--- PASS: TestAccAWSCloudWatchEventRule_pattern (50.64s)
--- PASS: TestAccAWSCloudWatchEventRule_role (48.35s)
--- PASS: TestAccAWSCloudWatchEventRule_ScheduleAndPattern (33.93s)
--- PASS: TestAccAWSCloudWatchEventRule_tags (83.41s)

--- PASS: TestAccAWSSecurityGroup_allowAll (39.02s)
--- PASS: TestAccAWSSecurityGroup_basic (38.37s)
--- PASS: TestAccAWSSecurityGroup_change (82.06s)
--- PASS: TestAccAWSSecurityGroup_CIDRandGroups (55.51s)
--- PASS: TestAccAWSSecurityGroup_defaultEgressClassic (13.81s)
--- PASS: TestAccAWSSecurityGroup_defaultEgressVPC (49.44s)
--- PASS: TestAccAWSSecurityGroup_drift (19.07s)
--- PASS: TestAccAWSSecurityGroup_driftComplex (49.44s)
--- PASS: TestAccAWSSecurityGroup_egressConfigMode (74.91s)
--- PASS: TestAccAWSSecurityGroup_egressWithPrefixList (53.22s)
--- PASS: TestAccAWSSecurityGroup_failWithDiffMismatch (39.04s)
--- PASS: TestAccAWSSecurityGroup_forceRevokeRulesFalse (682.76s)
--- PASS: TestAccAWSSecurityGroup_forceRevokeRulesTrue (737.58s)
--- PASS: TestAccAWSSecurityGroup_ingressConfigMode (73.28s)
--- PASS: TestAccAWSSecurityGroup_ingressWithCidrAndSGsClassic (14.36s)
--- PASS: TestAccAWSSecurityGroup_ingressWithCidrAndSGsVPC (39.61s)
--- PASS: TestAccAWSSecurityGroup_ingressWithPrefixList (56.36s)
--- PASS: TestAccAWSSecurityGroup_invalidCIDRBlock (6.52s)
--- PASS: TestAccAWSSecurityGroup_IPRangeAndSecurityGroupWithSameRules (48.10s)
--- PASS: TestAccAWSSecurityGroup_IPRangesWithSameRules (35.83s)
--- PASS: TestAccAWSSecurityGroup_ipv4andipv6Egress (35.09s)
--- PASS: TestAccAWSSecurityGroup_ipv6 (46.26s)
--- PASS: TestAccAWSSecurityGroup_multiIngress (45.44s)
--- PASS: TestAccAWSSecurityGroup_Name_Generated (32.72s)
--- PASS: TestAccAWSSecurityGroup_Name_TerraformPrefix (32.03s)
--- PASS: TestAccAWSSecurityGroup_NamePrefix (34.45s)
--- PASS: TestAccAWSSecurityGroup_NamePrefix_TerraformPrefix (32.44s)
--- PASS: TestAccAWSSecurityGroup_ruleDescription (112.40s)
--- PASS: TestAccAWSSecurityGroup_ruleGathering (57.85s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitCidrBlockExceededAppend (71.38s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededAllNew (88.92s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededAppend (81.66s)
--- PASS: TestAccAWSSecurityGroup_ruleLimitExceededPrepend (72.60s)
--- PASS: TestAccAWSSecurityGroup_rulesDropOnError (72.96s)
--- PASS: TestAccAWSSecurityGroup_self (39.48s)
--- PASS: TestAccAWSSecurityGroup_sourceSecurityGroup (31.15s)
--- PASS: TestAccAWSSecurityGroup_tags (76.38s)
--- PASS: TestAccAWSSecurityGroup_vpc (39.96s)
--- PASS: TestAccAWSSecurityGroup_vpcNegOneIngress (45.88s)
--- PASS: TestAccAWSSecurityGroup_vpcProtoNumIngress (37.04s)
```
@github-actions github-actions bot added this to the v3.27.0 milestone Feb 2, 2021
@ghost
Copy link

ghost commented Feb 5, 2021

This has been released in version 3.27.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Mar 5, 2021

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!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants