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_policy:Enable Metric Math support for TargetTrackingPolicy in Application Au… #30172

Conversation

snghffc
Copy link
Contributor

@snghffc snghffc commented Mar 22, 2023

Description

This PR enables Metric Math support for Applicationn AutoScaling TargetTracking policy. The feature was release on March 15, 2023.
https://aws.amazon.com/about-aws/whats-new/2023/03/application-auto-scaling-metric-math-target-tracking-policies/

Relations

Closes #30049.
Closes #28391.

References

Output from Acceptance Testing

$ make testacc TESTS=TestAccAppAutoScalingPolicy PKG=appautoscaling
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/appautoscaling/... -v -count 1 -parallel 20 -run='TestAccAppAutoScalingPolicy'  -timeout 180m
=== RUN   TestAccAppAutoScalingPolicy_basic
=== PAUSE TestAccAppAutoScalingPolicy_basic
=== RUN   TestAccAppAutoScalingPolicy_disappears
=== PAUSE TestAccAppAutoScalingPolicy_disappears
=== RUN   TestAccAppAutoScalingPolicy_scaleOutAndIn
=== PAUSE TestAccAppAutoScalingPolicy_scaleOutAndIn
=== RUN   TestAccAppAutoScalingPolicy_spotFleetRequest
=== PAUSE TestAccAppAutoScalingPolicy_spotFleetRequest
=== RUN   TestAccAppAutoScalingPolicy_DynamoDB_table
=== PAUSE TestAccAppAutoScalingPolicy_DynamoDB_table
=== RUN   TestAccAppAutoScalingPolicy_DynamoDB_index
=== PAUSE TestAccAppAutoScalingPolicy_DynamoDB_index
=== RUN   TestAccAppAutoScalingPolicy_multiplePoliciesSameName
=== PAUSE TestAccAppAutoScalingPolicy_multiplePoliciesSameName
=== RUN   TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
=== PAUSE TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
=== RUN   TestAccAppAutoScalingPolicy_ResourceID_forceNew
=== PAUSE TestAccAppAutoScalingPolicy_ResourceID_forceNew
=== RUN   TestAccAppAutoScalingPolicy_TargetTrack_metricMath
=== PAUSE TestAccAppAutoScalingPolicy_TargetTrack_metricMath
=== CONT  TestAccAppAutoScalingPolicy_basic
=== CONT  TestAccAppAutoScalingPolicy_DynamoDB_index
=== CONT  TestAccAppAutoScalingPolicy_ResourceID_forceNew
=== CONT  TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
=== CONT  TestAccAppAutoScalingPolicy_spotFleetRequest
=== CONT  TestAccAppAutoScalingPolicy_scaleOutAndIn
=== CONT  TestAccAppAutoScalingPolicy_TargetTrack_metricMath
=== CONT  TestAccAppAutoScalingPolicy_disappears
=== CONT  TestAccAppAutoScalingPolicy_DynamoDB_table
=== CONT  TestAccAppAutoScalingPolicy_multiplePoliciesSameName
--- PASS: TestAccAppAutoScalingPolicy_multiplePoliciesSameName (34.43s)
--- PASS: TestAccAppAutoScalingPolicy_DynamoDB_table (36.56s)
--- PASS: TestAccAppAutoScalingPolicy_multiplePoliciesSameResource (48.00s)
--- PASS: TestAccAppAutoScalingPolicy_DynamoDB_index (52.79s)
--- PASS: TestAccAppAutoScalingPolicy_spotFleetRequest (68.37s)
--- PASS: TestAccAppAutoScalingPolicy_disappears (84.47s)
--- PASS: TestAccAppAutoScalingPolicy_basic (87.37s)
--- PASS: TestAccAppAutoScalingPolicy_scaleOutAndIn (91.17s)
--- PASS: TestAccAppAutoScalingPolicy_ResourceID_forceNew (98.28s)
--- PASS: TestAccAppAutoScalingPolicy_TargetTrack_metricMath (98.73s)
PASS
ok      github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling     103.990s
...

Similar to EC2 AutoScaling PR: #28560

@github-actions
Copy link

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 size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. needs-triage Waiting for first response or review from a maintainer. labels Mar 22, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Welcome @snghffc 👋

It looks like this is your first Pull Request submission to the Terraform AWS Provider! If you haven’t already done so please make sure you have checked out our CONTRIBUTOR guide and FAQ to make sure your contribution is adhering to best practice and has all the necessary elements in place for a successful approval.

Also take a look at our FAQ which details how we prioritize Pull Requests for inclusion.

Thanks again, and welcome to the community! 😃

@snghffc snghffc changed the title Enable Metric Math support for TargetTrackingPolicy in Application Au… r/aws_appautoscaling_policy:Enable Metric Math support for TargetTrackingPolicy in Application Au… Mar 22, 2023
@snghffc snghffc marked this pull request as ready for review March 22, 2023 18:22
@jungseoklee
Copy link
Contributor

jungseoklee commented Mar 31, 2023

Update on Apr 11, 2023: I have submitted my review officially and deleted the original message to avoid confusion.

@breathingdust breathingdust added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 6, 2023
Copy link
Contributor

@jungseoklee jungseoklee left a comment

Choose a reason for hiding this comment

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

I am an author on #28560. The acceptance testing covers all combinations of metric data queries, e.g. expression with metric stat, standalone expression, expression relying on other metric data queries, metric with dimensions, and metric without dimensions. Hence, this PR looks good to me.

@jas550
Copy link

jas550 commented Apr 12, 2023

Hi,

Do you know when this feature will be merged and if it will be available for aws provider version 3?

@tomcart90
Copy link

Still waiting on this one. Does it need further review? Is it worth tagging those who reviewed #28560?

@snghffc
Copy link
Contributor Author

snghffc commented Apr 28, 2023

@ewbankkit Can we please get some help on this PR?
I see your contribution on a similar code change we did for EC2 AutoScaling #28560

@ewbankkit ewbankkit added the partner Contribution from a partner. label Apr 28, 2023
Copy link
Contributor

@ewbankkit ewbankkit left a comment

Choose a reason for hiding this comment

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

LGTM 🚀.

% make testacc TESTARGS='-run=TestAccAppAutoScalingPolicy_' PKG=appautoscaling ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/appautoscaling/... -v -count 1 -parallel 2  -run=TestAccAppAutoScalingPolicy_ -timeout 180m
=== RUN   TestAccAppAutoScalingPolicy_basic
=== PAUSE TestAccAppAutoScalingPolicy_basic
=== RUN   TestAccAppAutoScalingPolicy_disappears
=== PAUSE TestAccAppAutoScalingPolicy_disappears
=== RUN   TestAccAppAutoScalingPolicy_scaleOutAndIn
=== PAUSE TestAccAppAutoScalingPolicy_scaleOutAndIn
=== RUN   TestAccAppAutoScalingPolicy_spotFleetRequest
=== PAUSE TestAccAppAutoScalingPolicy_spotFleetRequest
=== RUN   TestAccAppAutoScalingPolicy_DynamoDB_table
=== PAUSE TestAccAppAutoScalingPolicy_DynamoDB_table
=== RUN   TestAccAppAutoScalingPolicy_DynamoDB_index
=== PAUSE TestAccAppAutoScalingPolicy_DynamoDB_index
=== RUN   TestAccAppAutoScalingPolicy_multiplePoliciesSameName
=== PAUSE TestAccAppAutoScalingPolicy_multiplePoliciesSameName
=== RUN   TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
=== PAUSE TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
=== RUN   TestAccAppAutoScalingPolicy_ResourceID_forceNew
=== PAUSE TestAccAppAutoScalingPolicy_ResourceID_forceNew
=== RUN   TestAccAppAutoScalingPolicy_TargetTrack_metricMath
=== PAUSE TestAccAppAutoScalingPolicy_TargetTrack_metricMath
=== CONT  TestAccAppAutoScalingPolicy_basic
=== CONT  TestAccAppAutoScalingPolicy_DynamoDB_index
--- PASS: TestAccAppAutoScalingPolicy_DynamoDB_index (36.41s)
=== CONT  TestAccAppAutoScalingPolicy_spotFleetRequest
--- PASS: TestAccAppAutoScalingPolicy_basic (78.27s)
=== CONT  TestAccAppAutoScalingPolicy_DynamoDB_table
--- PASS: TestAccAppAutoScalingPolicy_DynamoDB_table (27.88s)
=== CONT  TestAccAppAutoScalingPolicy_scaleOutAndIn
--- PASS: TestAccAppAutoScalingPolicy_spotFleetRequest (82.96s)
=== CONT  TestAccAppAutoScalingPolicy_disappears
--- PASS: TestAccAppAutoScalingPolicy_scaleOutAndIn (81.02s)
=== CONT  TestAccAppAutoScalingPolicy_ResourceID_forceNew
--- PASS: TestAccAppAutoScalingPolicy_disappears (74.80s)
=== CONT  TestAccAppAutoScalingPolicy_TargetTrack_metricMath
--- PASS: TestAccAppAutoScalingPolicy_TargetTrack_metricMath (77.71s)
=== CONT  TestAccAppAutoScalingPolicy_multiplePoliciesSameResource
--- PASS: TestAccAppAutoScalingPolicy_ResourceID_forceNew (90.37s)
=== CONT  TestAccAppAutoScalingPolicy_multiplePoliciesSameName
--- PASS: TestAccAppAutoScalingPolicy_multiplePoliciesSameName (25.74s)
--- PASS: TestAccAppAutoScalingPolicy_multiplePoliciesSameResource (32.18s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling	309.268s
% make testacc TESTARGS='-run=TestAccAppAutoScalingTarget_' PKG=appautoscaling ACCTEST_PARALLELISM=3 
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/appautoscaling/... -v -count 1 -parallel 3  -run=TestAccAppAutoScalingTarget_ -timeout 180m
=== RUN   TestAccAppAutoScalingTarget_basic
=== PAUSE TestAccAppAutoScalingTarget_basic
=== RUN   TestAccAppAutoScalingTarget_disappears
=== PAUSE TestAccAppAutoScalingTarget_disappears
=== RUN   TestAccAppAutoScalingTarget_tags
=== PAUSE TestAccAppAutoScalingTarget_tags
=== RUN   TestAccAppAutoScalingTarget_spotFleetRequest
=== PAUSE TestAccAppAutoScalingTarget_spotFleetRequest
=== RUN   TestAccAppAutoScalingTarget_emrCluster
=== PAUSE TestAccAppAutoScalingTarget_emrCluster
=== RUN   TestAccAppAutoScalingTarget_multipleTargets
=== PAUSE TestAccAppAutoScalingTarget_multipleTargets
=== RUN   TestAccAppAutoScalingTarget_optionalRoleARN
=== PAUSE TestAccAppAutoScalingTarget_optionalRoleARN
=== CONT  TestAccAppAutoScalingTarget_basic
=== CONT  TestAccAppAutoScalingTarget_emrCluster
=== CONT  TestAccAppAutoScalingTarget_tags
--- PASS: TestAccAppAutoScalingTarget_tags (52.60s)
=== CONT  TestAccAppAutoScalingTarget_spotFleetRequest
--- PASS: TestAccAppAutoScalingTarget_basic (80.80s)
=== CONT  TestAccAppAutoScalingTarget_disappears
--- PASS: TestAccAppAutoScalingTarget_spotFleetRequest (83.75s)
=== CONT  TestAccAppAutoScalingTarget_optionalRoleARN
--- PASS: TestAccAppAutoScalingTarget_optionalRoleARN (25.10s)
=== CONT  TestAccAppAutoScalingTarget_multipleTargets
--- PASS: TestAccAppAutoScalingTarget_multipleTargets (25.95s)
--- PASS: TestAccAppAutoScalingTarget_disappears (84.06s)
--- PASS: TestAccAppAutoScalingTarget_emrCluster (612.71s)
PASS
ok  	github.com/hashicorp/terraform-provider-aws/internal/service/appautoscaling	618.376s

@github-actions github-actions bot added generators Relates to code generators. tags Pertains to resource tagging. labels May 1, 2023
@ewbankkit ewbankkit merged commit 4a83dda into hashicorp:main May 1, 2023
@github-actions github-actions bot added this to the v4.66.0 milestone May 1, 2023
@snghffc
Copy link
Contributor Author

snghffc commented May 1, 2023

Thank you so much @ewbankkit for your help on this PR.

@jas550
Copy link

jas550 commented May 2, 2023

Hi, will this be available for aws provider version 3 as well?

@jasonarewhy
Copy link

@snghffc @ewbankkit thanks for the additions. However, the provider is now erroring when trying to refresh state for existing targets without tags:

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

@SJBarden
Copy link

SJBarden commented May 5, 2023

Yes also receiving the above error.
│ 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.service_autoscale

@tribecar-shurn
Copy link

Also receiving this error:

│ Error: listing tags for Application Auto Scaling Target (): InvalidParameter: 1 validation error(s) found.

│ - minimum field size of 1, ListTagsForResourceInput.ResourceARN.

@snghffc
Copy link
Contributor Author

snghffc commented May 5, 2023

Can you please share more details about the error?
What is the Test scenario and the provided API request for test?
Looking at the error message, It looks like ResourceARN property might not have been provided which is resulting in validation error.
ResourceARN is a required parameter : https://docs.aws.amazon.com/autoscaling/application/APIReference/API_ListTagsForResource.html

@tribecar-shurn
Copy link

tribecar-shurn commented May 5, 2023

For my use case this is my resource block:

resource "aws_appautoscaling_target" "tc-a-t-wla-dev" {
max_capacity = 4
min_capacity = 1
resource_id = "service/${aws_ecs_cluster.tc-ecs-c-wla-dev.name}/${aws_ecs_service.tc-ecs-s-wla-dev.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

This resource block is working fine in 4.65.0.
According to https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_target, all the required attributes have been provided.

@SJBarden
Copy link

SJBarden commented May 5, 2023

Terraform works with 4.65 for Autoscaling (No Code Changes in the Terraform), however something has been introduced in 4.66 that is producing the above error.

Its almost like listing tags are now a required field. However in my code I have no tags listed. This works on 4.65.

resource "aws_appautoscaling_target" "service_autoscale" {
min_capacity = var.service_min_capacity
max_capacity = var.service_max_capacity
resource_id = "service/${local.prefix}/${aws_ecs_service.service.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

@flowconic
Copy link

flowconic commented May 5, 2023

we are also facing this issue, our block is similar to yours @tribecar-shurn and with 4.66.0 it also started breaking. We are not having any tags in the resource block

The error we are receving is:

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.ecs_target,
│   on autoscaling.tf line 1, in resource "aws_appautoscaling_target" "ecs_target":
│    1: resource "aws_appautoscaling_target" "ecs_target" {
│ 

@ghdiska
Copy link
Contributor

ghdiska commented May 5, 2023

the bug ( #31180 ) in version 4.66 can be related to this commit ?

@tribecar-shurn
Copy link

Looks like the same issue.

@JJiangZS
Copy link

JJiangZS commented May 5, 2023

Hi, I am facing the same issue, I must untick the checkbox named "Use service auto scaling" then this issue has gone.

error details:

The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

module.main.module.service.module.service.data.aws_ecs_cluster.this: Refreshing state... [id=arn:aws:ecs:xxxx:cluster/APP-ECS]
module.main.module.service.module.service.data.aws_security_groups.ecs[0]: Refreshing state... [id=ap-southeast-1]
module.main.module.service.module.service.data.aws_iam_role.execute_role: Refreshing state... [id=APP-TASKEXE-ROLE]
module.main.module.service.module.service.data.aws_subnet.this: Refreshing state... [id=xxxx]
module.main.module.service.module.service.data.aws_iam_role.task_role: Refreshing state... [id=APP-TASK-ROLE]
module.main.module.service.module.service.data.aws_region.current: Refreshing state... [id=xxx]
module.main.module.service.module.service.data.aws_lb.this[0]: Refreshing state... [id=arn:aws:elasticloadbalancing:xxxxx:loadbalancer/app/APP-ALB/xxxxxxx]
module.main.module.service.module.service.aws_service_discovery_service.this[0]: Refreshing state... [id=xxxxxxx]
module.main.module.service.module.service.data.aws_arn.cluster: Refreshing state... [id=arn:aws:ecs:xxxxx:cluster/APP-APAC-ECS]
module.main.module.service.module.service.data.aws_lb_listener.public_443[0]: Refreshing state... [id=arn:aws:elasticloadbalancing:xxxxx:listener/app/APP-ALB/xxx/xxxx]
module.main.module.service.module.service.data.aws_vpc.this: Refreshing state... [id=xxxx]
module.main.module.service.module.service.aws_lb_target_group.this[0]: Refreshing state... [id=arn:aws:elasticloadbalancing:xxx:targetgroup/xxxxxx/xxxxx]
module.main.module.service.module.service.aws_lb_listener_rule.this[0]: Refreshing state... [id=arn:aws:elasticloadbalancing:xxxxx:listener-rule/app/APP-ALB/xxx/xxx/xxx]
module.main.module.service.module.service.aws_ecs_task_definition.this: Refreshing state... [id=app]
module.main.module.service.module.service.aws_ecs_service.this: Refreshing state... [id=arn:aws:ecs:app:service/APP-ECS/app-service]
module.main.module.service.module.service.aws_appautoscaling_target.this: Refreshing state... [id=service/APP-ECS/app-service]

Error: listing tags for Application Auto Scaling Target (): InvalidParameter: 1 validation error(s) found.

  • minimum field size of 1, ListTagsForResourceInput.ResourceARN.

##[error]Error: The process '/usr/bin/bash' failed because one or more lines were written to the STDERR stream
Finishing: Validate Terraform

@btara1
Copy link

btara1 commented May 5, 2023

Does this change mandate some code updates which are not yet published in the registry?

@coolbananas118
Copy link

We have this bug also. We just upgraded Terraform from 1.1.7 -> 1.4.6. I reported it and another team in the company has seen it also but they didn't do any upgrade, it just started happening for them, they are using version 0.14.6. Another strange thing: deployments in 2x other environments was fine but only occurs in 1 environment. It seems to be random.

@andreaadams11
Copy link

andreaadams11 commented May 5, 2023

We have the same thing happening in our environment. What I found was that it fails for older scalable targets. If you run:

aws application-autoscaling describe-scalable-targets --service-namespace ecs

you'll find that some scalable targets do not return a ScalableTargetARN. It appears that only those created more recently have one. I believe the code will need to account for this. If you don't have a ScalableTargetARN, you can't create a tag on the resource.

We are going to raise the issue w/AWS this morning, but thinking the code needs to be updated in the meantime.

@github-actions
Copy link

github-actions bot commented May 5, 2023

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

@github-actions
Copy link

github-actions bot commented Jun 5, 2023

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 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. generators Relates to code generators. partner Contribution from a partner. service/appautoscaling Issues and PRs that pertain to the appautoscaling service. size/XL Managed by automation to categorize the size of a PR. tags Pertains to resource tagging. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet