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

aws_ecs_service support deployment_minimum_healthy_percent for DAEMON strategy #6150

Merged

Conversation

mschurenko
Copy link
Contributor

@mschurenko mschurenko commented Oct 14, 2018

This PR aims to fix #5236

To summarize, I would like to be able to set deployment_minimum_healthy_percent to 50 when using a scheduling strategy of DAEMON. Currently this is not possible as this value being set to nil. The result of this is that deployment_minimum_healthy_percent is set to 0 (AWS default) which results in downtime for a deployment.

This is my first PR to this project, so I might be missing something obvious, but there doesn't appear to be a way to conditionally set a default value in github.com/hashicorp/terraform/helper/schema https://github.com/terraform-providers/terraform-provider-aws/blob/master/vendor/github.com/hashicorp/terraform/helper/schema/schema.go#L37.

Ideally the default value for deployment_minimum_healthy_percent would be 200 for REPLICA strategy and 0 for DAEMON, but I was unable to do that.

As a result if one uses the DAEMON strategy but does not set a value for deployment_minimum_healthy_percent the default of 100 is used and you get this error:

 aws_ecs_service.my_service: InvalidParameterException: Both maximumPercent and minimumHealthyPercent cannot be 100 as this will block deployments.
	status code: 400, request id: 848ec013-cf6e-11e8-8638-07c29e49208f "my_service"

IMO this is better then the current behavior where one cannot set deployment_minimum_healthy_percent at all.

Having said this, I'm hoping there's a better approach to doing this.

Changes proposed in this pull request:

  • aws_ecs_service resource will use deployment_minimum_healthy_percent when scheduling_strategy is set to DAEMON

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSEcsService_withDaemonSchedulingStrategy'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_withDaemonSchedulingStrategy -timeout 120m
=== RUN   TestAccAWSEcsService_withDaemonSchedulingStrategy
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategy (27.18s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	(cached)

@ghost ghost added size/XS Managed by automation to categorize the size of a PR. service/ecs Issues and PRs that pertain to the ecs service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Oct 14, 2018
@mschurenko mschurenko changed the title [WIP] aws_ecs_service support deployment_minimum_healthy_percent for DAEMON strategy aws_ecs_service support deployment_minimum_healthy_percent for DAEMON strategy Oct 15, 2018
@mschurenko
Copy link
Contributor Author

Hi @bflad. Not sure if anyone has had a chance to look at this yet.

Thanks

@mschurenko
Copy link
Contributor Author

I'm not trying to sound like a jerk or anything, but is this normal to have no response for a PR after 11 days? If this won't be accepted for whatever reason that's fine. I would just like to know. If it's not I'll most likely need to use Cloudformation for this.

@bflad
Copy link
Contributor

bflad commented Oct 25, 2018

@mschurenko its likely to be reviewed and accepted (potentially with some changes) given my understanding of the situation. A bunch of HashiCorp and community members have been busy with preparation, travel, and attendance of HashiConf this week.

@mschurenko
Copy link
Contributor Author

Hey @bflad thanks a lot for the response. Sorry to be so pushy. I didn't realize HashiConf was next week.

Thanks!

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. waiting-response Maintainers are waiting on response from community or contributor. labels Oct 30, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Initial comments below. Please let us know if you have any questions or do not have time to implement the feedback.

@@ -106,12 +106,6 @@ func resourceAwsEcsService() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
Default: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of leaving a Default: 100 here that only works for one of the scheduling strategies, should we instead remove Default: 100 and implement a DiffSuppressFunc that covers suppressing the difference depending on the strategy? A similar update should likely occur for maximum as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we remove the Default wouldn't that be backwards incompatible for those who are using a replica strategy and didn't set deployment_minimum_healthy_percent?

Similar for deployment_maximum_percent, if we remove Default won't that be a problem for backwards compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

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

The port attribute of the aws_elasticache_cluster resource is an example of a place where we allow two defaults chosen by the API, but suppress the difference if it is left unconfigured in the Terraform configuration: https://github.com/terraform-providers/terraform-provider-aws/blob/4ef574a20eeecd860ef40bf4ca94849cee9af0ef/aws/resource_aws_elasticache_cluster.go#L146-L157

Its not pretty, but it works. 😄 We could also set Computed: true.

Copy link
Contributor Author

@mschurenko mschurenko Oct 31, 2018

Choose a reason for hiding this comment

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

Ok. So when you say we allow two defaults chosen by the API, do you mean by the AWS API?

@@ -354,7 +348,7 @@ func resourceAwsEcsServiceCreate(d *schema.ResourceData, meta interface{}) error
input.SchedulingStrategy = aws.String(schedulingStrategy)
if schedulingStrategy == ecs.SchedulingStrategyDaemon {
// unset these if DAEMON
input.DeploymentConfiguration = nil
input.DeploymentConfiguration.MaximumPercent = aws.Int64(100)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to keep this logic here at all? Since the comment eludes to "unsetting" values due to DAEMON we should either remove this line or add a comment why its being hardcoded to 100

aws/resource_aws_ecs_service_test.go Show resolved Hide resolved
@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. and removed size/XS Managed by automation to categorize the size of a PR. labels Oct 31, 2018
@mschurenko
Copy link
Contributor Author

@bflad I made your recommended changes. I removed default values for deployment_maximum_percent and deployment_minimum_healthy_percent so that the AWS API default values are now used.

I added another acceptance test so there is now TestAccAWSEcsService_withDaemonSchedulingStrategy and TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum.

I ran all the ecs acceptance tests and they have passed:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSEcsService_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_ -timeout 120m
=== RUN   TestAccAWSEcsService_withARN
--- PASS: TestAccAWSEcsService_withARN (29.85s)
=== RUN   TestAccAWSEcsService_basicImport
--- PASS: TestAccAWSEcsService_basicImport (36.27s)
=== RUN   TestAccAWSEcsService_disappears
--- PASS: TestAccAWSEcsService_disappears (16.57s)
=== RUN   TestAccAWSEcsService_withUnnormalizedPlacementStrategy
--- PASS: TestAccAWSEcsService_withUnnormalizedPlacementStrategy (43.69s)
=== RUN   TestAccAWSEcsService_withFamilyAndRevision
--- PASS: TestAccAWSEcsService_withFamilyAndRevision (39.37s)
=== RUN   TestAccAWSEcsService_withRenamedCluster
--- PASS: TestAccAWSEcsService_withRenamedCluster (77.87s)
=== RUN   TestAccAWSEcsService_healthCheckGracePeriodSeconds
--- PASS: TestAccAWSEcsService_healthCheckGracePeriodSeconds (244.06s)
=== RUN   TestAccAWSEcsService_withIamRole
--- PASS: TestAccAWSEcsService_withIamRole (127.35s)
=== RUN   TestAccAWSEcsService_withDeploymentValues
--- PASS: TestAccAWSEcsService_withDeploymentValues (35.34s)
=== RUN   TestAccAWSEcsService_withLbChanges
--- PASS: TestAccAWSEcsService_withLbChanges (231.07s)
=== RUN   TestAccAWSEcsService_withEcsClusterName
--- PASS: TestAccAWSEcsService_withEcsClusterName (37.22s)
=== RUN   TestAccAWSEcsService_withAlb
--- PASS: TestAccAWSEcsService_withAlb (220.44s)
=== RUN   TestAccAWSEcsService_withPlacementStrategy
--- PASS: TestAccAWSEcsService_withPlacementStrategy (104.52s)
=== RUN   TestAccAWSEcsService_withPlacementConstraints
--- PASS: TestAccAWSEcsService_withPlacementConstraints (36.67s)
=== RUN   TestAccAWSEcsService_withPlacementConstraints_emptyExpression
--- PASS: TestAccAWSEcsService_withPlacementConstraints_emptyExpression (14.07s)
=== RUN   TestAccAWSEcsService_withLaunchTypeFargate
--- PASS: TestAccAWSEcsService_withLaunchTypeFargate (312.88s)
=== RUN   TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration
--- PASS: TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration (81.87s)
=== RUN   TestAccAWSEcsService_withDaemonSchedulingStrategy
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategy (25.51s)
=== RUN   TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum (18.01s)
=== RUN   TestAccAWSEcsService_withReplicaSchedulingStrategy
--- PASS: TestAccAWSEcsService_withReplicaSchedulingStrategy (36.20s)
=== RUN   TestAccAWSEcsService_withServiceRegistries
--- PASS: TestAccAWSEcsService_withServiceRegistries (48.68s)
=== RUN   TestAccAWSEcsService_withServiceRegistries_container
--- PASS: TestAccAWSEcsService_withServiceRegistries_container (38.18s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1856.477s
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSEcsServiceDataSource_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsServiceDataSource_ -timeout 120m

=== RUN   TestAccAWSEcsServiceDataSource_basic
--- PASS: TestAccAWSEcsServiceDataSource_basic (13.67s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	15.621s

Also, I updated the aws_ecs_service html doc to reflect the changes.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @mschurenko! 🚀

--- PASS: TestAccAWSEcsService_withARN (9.45s)
--- PASS: TestAccAWSEcsService_basicImport (11.82s)
--- PASS: TestAccAWSEcsService_withUnnormalizedPlacementStrategy (18.89s)
--- PASS: TestAccAWSEcsService_disappears (19.28s)
--- PASS: TestAccAWSEcsService_withRenamedCluster (20.57s)
--- PASS: TestAccAWSEcsService_withDeploymentValues (10.93s)
--- PASS: TestAccAWSEcsService_withFamilyAndRevision (41.15s)
--- PASS: TestAccAWSEcsService_withEcsClusterName (19.00s)
--- PASS: TestAccAWSEcsService_withLbChanges (38.46s)
--- PASS: TestAccAWSEcsService_withIamRole (119.67s)
--- PASS: TestAccAWSEcsService_withPlacementConstraints (6.95s)
--- PASS: TestAccAWSEcsService_withPlacementConstraints_emptyExpression (10.89s)
--- PASS: TestAccAWSEcsService_withPlacementStrategy (75.45s)
--- PASS: TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration (47.44s)
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategy (6.69s)
--- PASS: TestAccAWSEcsService_withDaemonSchedulingStrategySetDeploymentMinimum (6.61s)
--- PASS: TestAccAWSEcsService_withReplicaSchedulingStrategy (10.82s)
--- PASS: TestAccAWSEcsService_withServiceRegistries (16.71s)
--- PASS: TestAccAWSEcsService_withServiceRegistries_container (12.65s)
--- PASS: TestAccAWSEcsService_healthCheckGracePeriodSeconds (247.67s)
--- PASS: TestAccAWSEcsService_withAlb (231.25s)
--- PASS: TestAccAWSEcsService_withLaunchTypeFargate (262.40s)

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Oct 31, 2018
@bflad bflad added this to the v1.42.0 milestone Oct 31, 2018
@bflad bflad merged commit 97bb163 into hashicorp:master Oct 31, 2018
@bflad
Copy link
Contributor

bflad commented Nov 1, 2018

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

@ghost
Copy link

ghost commented Apr 2, 2020

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 and limited conversation to collaborators Apr 2, 2020
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. service/ecs Issues and PRs that pertain to the ecs service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_ecs_service - deployment_minimum_healthy_percent for DAEMON
2 participants