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

r/aws_appautoscaling_target: Skip ListTags/UpdateTags for existing resources with no assigned ARN #31214

Merged
merged 7 commits into from
May 5, 2023

Conversation

ewbankkit
Copy link
Contributor

@ewbankkit ewbankkit commented May 5, 2023

Description

Older aws_appautoscaling_targets have no ARN assigned by AWS. This causes errors when making the ListTags call to get any resource tags.
Skip the call if no ARN (or more generally, no identifier value) is present.
The same logic applies to UpdateTags (e.g. when using default_tags).

Maintainer Instructions

In the main test account, with this configuration:

provider "aws" {}

resource "aws_appautoscaling_target" "test" {
  service_namespace  = "ecs"
  resource_id        = "service/cluster-8xupcpmfyu/foobar"
  scalable_dimension = "ecs:service:DesiredCount"
  min_capacity       = 1
  max_capacity       = 3
}
% git checkout v4.65.0
% make
% terraform import aws_appautoscaling_target.test ecs/service/cluster-8xupcpmfyu/foobar/ecs:service:DesiredCount
aws_appautoscaling_target.test: Importing from ID "ecs/service/cluster-8xupcpmfyu/foobar/ecs:service:DesiredCount"...
aws_appautoscaling_target.test: Import prepared!
  Prepared aws_appautoscaling_target for import
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

% terraform plan 
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

No changes. Your infrastructure matches the configuration.

% git checkout v4.66.0
% make
% terraform plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

│ Error: listing tags for Application Auto Scaling Target (): InvalidParameter: 1 validation error(s) found.
│ - minimum field size of 1, ListTagsForResourceInput.ResourceARN.


│   with aws_appautoscaling_target.test,
│   on main.tf line 3, in resource "aws_appautoscaling_target" "test":
│    3: resource "aws_appautoscaling_target" "test" {



% git checkout deaacb40f009007e9bdacfb8c40344438d8d5b3a
% make
% terraform plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # aws_appautoscaling_target.test has been changed
  ~ resource "aws_appautoscaling_target" "test" {
        id                 = "service/cluster-8xupcpmfyu/foobar"
      + tags               = {}
      + tags_all           = {}
        # (6 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the
following plan may include actions to undo or respond to these changes.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

No changes. Your infrastructure matches the configuration.

Your configuration already matches the changes detected above. If you'd like to update the Terraform state to match, create and
apply a refresh-only plan:
  terraform apply -refresh-only

If we then add some default tags:

provider "aws" {
  default_tags {
    tags = {
      Environment = "Test"
      Name        = "Provider Tag"
    }
  }
}

resource "aws_appautoscaling_target" "test" {
  service_namespace  = "ecs"
  resource_id        = "service/cluster-8xupcpmfyu/foobar"
  scalable_dimension = "ecs:service:DesiredCount"
  min_capacity       = 1
  max_capacity       = 3
}
% terraform apply
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_appautoscaling_target.test will be updated in-place
  ~ resource "aws_appautoscaling_target" "test" {
        id                 = "service/cluster-8xupcpmfyu/foobar"
        tags               = {}
      ~ tags_all           = {
          + "Environment" = "Test"
          + "Name"        = "Provider Tag"
        }
        # (6 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_appautoscaling_target.test: Modifying... [id=service/cluster-8xupcpmfyu/foobar]

│ Error: updating tags for Application Auto Scaling Target (): tagging resource (): InvalidParameter: 1 validation error(s) found.
│ - minimum field size of 1, TagResourceInput.ResourceARN.


│   with aws_appautoscaling_target.test,
│   on main.tf line 10, in resource "aws_appautoscaling_target" "test":
│   10: resource "aws_appautoscaling_target" "test" {



% git checkout 379529d9df8eda142cc5d61d5d1dd903aaf5d615
% make
% terraform apply                                                    
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Note: Objects have changed outside of Terraform

Terraform detected the following changes made outside of Terraform since the last "terraform apply":

  # aws_appautoscaling_target.test has been changed
  ~ resource "aws_appautoscaling_target" "test" {
        id                 = "service/cluster-8xupcpmfyu/foobar"
        tags               = {}
      ~ tags_all           = {
          - "Environment" = "Test" -> null
          - "Name"        = "Provider Tag" -> null
        }
        # (6 unchanged attributes hidden)
    }

Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the
following plan may include actions to undo or respond to these changes.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_appautoscaling_target.test will be updated in-place
  ~ resource "aws_appautoscaling_target" "test" {
        id                 = "service/cluster-8xupcpmfyu/foobar"
        tags               = {}
      ~ tags_all           = {
          + "Environment" = "Test"
          + "Name"        = "Provider Tag"
        }
        # (6 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_appautoscaling_target.test: Modifying... [id=service/cluster-8xupcpmfyu/foobar]
aws_appautoscaling_target.test: Modifications complete after 1s [id=service/cluster-8xupcpmfyu/foobar]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

% terraform plan 
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_appautoscaling_target.test will be updated in-place
  ~ resource "aws_appautoscaling_target" "test" {
        id                 = "service/cluster-8xupcpmfyu/foobar"
        tags               = {}
      ~ tags_all           = {
          + "Environment" = "Test"
          + "Name"        = "Provider Tag"
        }
        # (6 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run
"terraform apply" now.

The "permadiff" can be suppressed via a lifecycle.ignore_changes meta-argument.

provider "aws" {
  default_tags {
    tags = {
      Environment = "Test"
      Name        = "Provider Tag"
    }
  }
}

resource "aws_appautoscaling_target" "test" {
  service_namespace  = "ecs"
  resource_id        = "service/cluster-8xupcpmfyu/foobar"
  scalable_dimension = "ecs:service:DesiredCount"
  min_capacity       = 1
  max_capacity       = 3

  lifecycle {
    ignore_changes = [
      tags_all,
    ]
  }
}
% terraform plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

Relations

Closes #31180.
Relates #30172.
Relates #28391.

Output from Acceptance Testing

% make testacc TESTARGS='-run=TestAccAppAutoScalingTarget_basic$$\|TestAccAppAutoScalingTarget_tags$$' PKG=appautoscaling
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/appautoscaling/... -v -count 1 -parallel 20  -run=TestAccAppAutoScalingTarget_basic$\|TestAccAppAutoScalingTarget_tags$ -timeout 180m
=== RUN   TestAccAppAutoScalingTarget_basic
=== PAUSE TestAccAppAutoScalingTarget_basic
=== RUN   TestAccAppAutoScalingTarget_tags
=== PAUSE TestAccAppAutoScalingTarget_tags
=== CONT  TestAccAppAutoScalingTarget_basic
=== CONT  TestAccAppAutoScalingTarget_tags
--- PASS: TestAccAppAutoScalingTarget_tags (54.10s)
--- PASS: TestAccAppAutoScalingTarget_basic (90.32s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling	95.864s

@github-actions
Copy link

github-actions bot commented May 5, 2023

Community Note

Voting for Prioritization

  • Please vote on this pull request by adding a 👍 reaction to the original post to help the community and maintainers prioritize this pull request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

For Submitters

  • Review the contribution guide relating to the type of change you are making to ensure all of the necessary steps have been taken.
  • For new resources and data sources, use skaff to generate scaffolding with comments detailing common expectations.
  • Whether or not the branch has been rebased will not impact prioritization, but doing so is always a welcome surprise.

@github-actions github-actions bot added provider Pertains to the provider itself, rather than any interaction with AWS. size/M Managed by automation to categorize the size of a PR. and removed provider Pertains to the provider itself, rather than any interaction with AWS. labels May 5, 2023
@github-actions github-actions bot added the provider Pertains to the provider itself, rather than any interaction with AWS. label May 5, 2023
@ewbankkit ewbankkit added bug Addresses a defect in current functionality. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. tags Pertains to resource tagging. labels May 5, 2023
@ewbankkit ewbankkit changed the title r/aws_appautoscaling_target: Skip ListTags for existing resources with no assigned ARN r/aws_appautoscaling_target: Skip ListTags/UpdateTags for existing resources with no assigned ARN May 5, 2023
Copy link
Member

@jar-b jar-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

v4.65.0

➜  make import
aws_appautoscaling_target.test: Importing from ID "ecs/service/cluster-8xupcpmfyu/foobar/ecs:service:DesiredCount"...
aws_appautoscaling_target.test: Import prepared!
  Prepared aws_appautoscaling_target for import
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

➜  make plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

No changes. Your infrastructure matches the configuration.

v4.66.0

➜  make plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: listing tags for Application Auto Scaling Target (): InvalidParameter: 1 validation error(s) found.
│ - minimum field size of 1, ListTagsForResourceInput.ResourceARN.
│
│
│   with aws_appautoscaling_target.test,
│   on main.tf line 13, in resource "aws_appautoscaling_target" "test":
│   13: resource "aws_appautoscaling_target" "test" {
│

patch branch:

➜ make plan
aws_appautoscaling_target.test: Refreshing state... [id=service/cluster-8xupcpmfyu/foobar]

No changes. Your infrastructure matches the configuration.

@github-actions github-actions bot added size/L Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. and removed size/M Managed by automation to categorize the size of a PR. tags Pertains to resource tagging. labels May 5, 2023
Copy link
Member

@justinretzolk justinretzolk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

Add link to related feature GA
@ewbankkit ewbankkit merged commit 5e3cfe5 into main May 5, 2023
@ewbankkit ewbankkit deleted the b-aws_appautoscaling_policy-ListTags branch May 5, 2023 15:15
@github-actions github-actions bot added this to the v4.67.0 milestone May 5, 2023
github-actions bot pushed a commit that referenced this pull request May 5, 2023
@ewbankkit ewbankkit modified the milestones: v4.67.0, v4.66.1 May 5, 2023
@coolbananas118
Copy link

coolbananas118 commented May 5, 2023

We got around this bug in the end by forcing our provider back to 4.65.0. Hopefully 4.67.0 will prove to be stable and we can revert to using the latest minor/patch version below 5.0 🤞

@ewbankkit
Copy link
Contributor Author

The fix is available in v4.66.1 of the Terraform AWS Provider: https://registry.terraform.io/providers/hashicorp/aws/4.66.1.

@github-actions
Copy link

github-actions bot commented May 5, 2023

This functionality has been released in v4.66.1 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. Thank you!

@coolbananas118
Copy link

We switched back to 4.66.1 and everything is fixed now. Thanks @ewbankkit 🙇

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2023
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. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. regression Pertains to a degraded workflow resulting from an upstream patch or internal enhancement. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Error upon plan/apply of aws_appautoscaling_target on v4.66.0
4 participants