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

Feature/fargate support v2 #2559

Merged
merged 13 commits into from
Feb 9, 2018
Merged

Feature/fargate support v2 #2559

merged 13 commits into from
Feb 9, 2018

Conversation

johnnorton
Copy link
Contributor

The previous merge for ECS Fargate support did not include the ability to ENABLE "Assign Public IP" when creating the ECS Service.

From what I can tell, this is an option that only works for services on Fargate. This option assigns a public IP to the ENI. This is required to access the internet from the container if you do not have a NAT gateway setup.

@johnnorton johnnorton mentioned this pull request Dec 5, 2017
@radeksimko
Copy link
Member

Hi @johnnorton
AFAICT the networking block is updatable per API docs:
http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html#ECS-UpdateService-request-networkConfiguration

Can you tell us more about the motivation behind the ForceNew in all fields?

Also Elem is used to define elements nested under the field, which is only relevant to TypeList or TypeSet, potentially TypeMap, but certainly not TypeString.

Finally we'll need to add a test to exercise this new field and ensure it works. Let me know if you need any help with that.

Thanks.

@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. waiting-response Maintainers are waiting on response from community or contributor. labels Dec 6, 2017
@johnnorton
Copy link
Contributor Author

@radeksimko
Thanks for the input. My reasoning behind forcenew on networking was based on the Console not allowing updates to a service. I will test with the CLI and see.

This is my first foray into GoLang. I will will take a look at your suggestions and create a test.

Standby....

John

if d.HasChange("network_configration") {
input.NetworkConfiguration = expandEcsNetworkConfigration(d.Get("network_configuration").([]interface{}))
}
//d.HasChange("network_configration") is not working, so explicity calling method.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why the the func HadChange is not detecting a change on "network_configuration". Maybe we need to implement equals on the structure?

@johnnorton
Copy link
Contributor Author

@radeksimko. Yes updating the network config does not need to force a new resource but the existing tasks will not get the new settings as per the docs.

Please review my comments in the code and let me know.

Thanks!

@@ -1261,6 +1261,7 @@ resource "aws_ecs_service" "main" {
network_configuration {
security_groups = ["${aws_security_group.allow_all_a.id}", "${aws_security_group.allow_all_b.id}"]
subnets = ["${aws_subnet.main.*.id}"]
assign_public_ip = "ENABLED"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if this is all I need to do for the test. Seems like I am missing something

@radeksimko radeksimko removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 8, 2017
@johnnorton
Copy link
Contributor Author

@radeksimko Anything else needed here?

@headlessme
Copy link

Would also like to see this merged

@sleepdeprecation
Copy link

Is there any news on getting this merged? Not being able to set auto assign public IP is preventing me from configuring fargate-backed ECS services in terraform.

As a note on the PR itself, I think it would be nicer to be able to use true/false rather than ENABLED/DISABLED as the value, given that this is just a boolean value and that feels like it's exposing too much of the underlying API in a way that isn't particularly helpful.

@radeksimko radeksimko added this to the v1.10.0 milestone Jan 16, 2018
@johnnorton
Copy link
Contributor Author

@radeksimko

Made change suggested by @dkuntz2 dkuntz2

@austinkelleher
Copy link

This is also preventing me from configuring Fargate with Terraform. @radeksimko Can we please get this merged soon?

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.

Hi @johnnorton! This is getting there and thanks for your effort here. I'm providing a drive by review here since I know a couple of folks are waiting for this. If you don't have time or would like us to take this across the finish line, please let us know. 🚀

@@ -133,6 +133,11 @@ func resourceAwsEcsService() *schema.Resource {
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"assign_public_ip": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

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

You can remove &schema.Schema from this line here.

result := make(map[string]interface{})
result["security_groups"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.SecurityGroups))
result["subnets"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.Subnets))
result["assign_public_ip"] = "true"
if *nc.AwsvpcConfiguration.AssignPublicIp == "DISABLED" {
Copy link
Contributor

Choose a reason for hiding this comment

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

The AWS SDK provides constants we can use here instead of directly testing our own strings (this applies for all "DISABLED"/"ENABLED" in this PR), e.g. ecs.AssignPublicIpDisabled/ecs.AssignPublicIpEnabled

@@ -102,6 +102,7 @@ Guide](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query

* `subnets` - (Required) The subnets associated with the task or service.
* `security_groups` - (Optional) The security groups associated with the task or service. If you do not specify a security group, the default security group for the VPC is used.
* `assign_public_ip` - (Optional) Valid values are "ENABLED" or "DISABLED". Will assign a public IP address to the ENI.
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation needs to be updated since the switch from string values to boolean values and should also note the default of false.

@@ -1517,6 +1517,7 @@ resource "aws_ecs_service" "main" {
network_configuration {
security_groups = ["${aws_security_group.allow_all_a.id}", "${aws_security_group.allow_all_b.id}"]
subnets = ["${aws_subnet.main.*.id}"]
assign_public_ip = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add an appropriate attribute test where this is used (and one in the other Fargate test where it should be the default of false)? e.g. resource.TestCheckResourceAttr("aws_ecs_service.main", "network_configuration.0.assign_public_ip", "true")

@paddycarver paddycarver self-assigned this Jan 29, 2018
@ghost ghost added the size/M Managed by automation to categorize the size of a PR. label Feb 2, 2018
@johnnorton
Copy link
Contributor Author

johnnorton commented Feb 2, 2018

@bflad @radeksimko @paddycarver @austinkelleher --> Sorry I didn't get on this sooner. Sill learning Go (🤞 ) . Anyway please review and see if we can get this merged.

@bflad
Copy link
Contributor

bflad commented Feb 2, 2018

I'll take another look in a few hours. Thanks for the updates and contributions while learning Go! 😃

@austinkelleher
Copy link

Thanks for your work on this @johnnorton. Looking forward to seeing this merged.

@bflad bflad self-requested a review February 2, 2018 12:35
result := make(map[string]interface{})
result["security_groups"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.SecurityGroups))
result["subnets"] = schema.NewSet(schema.HashString, flattenStringList(nc.AwsvpcConfiguration.Subnets))
result["assign_public_ip"] = "true"
if *nc.AwsvpcConfiguration.AssignPublicIp == ecs.AssignPublicIpDisabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

If nc.AwsvpcConfiguration.AssignPublicIp is nil (its listed as optional in the ECS API documentation), this can cause Terraform to crash. I can fix this (and clean it up a little since it will automatically default to "false") prior to merge via:

if nc.AwsvpcConfiguration.AssignPublicIp != nil {
	result["assign_public_ip"] = fmt.Sprintf("%v", *nc.AwsvpcConfiguration.AssignPublicIp == ecs.AssignPublicIpEnabled)
}

@@ -34,7 +34,6 @@ func resourceAwsLbListener() *schema.Resource {
"load_balancer_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated change - will fix prior to merge

@bflad
Copy link
Contributor

bflad commented Feb 2, 2018

@johnnorton thank you so much for your contributions here! I will be pulling in your commits, but I am running into some issues acceptance testing this appropriately, which isn't really from your PR. I will fix those on top of this as it requires some refactoring of the resource/testing itself.

I wound up down this rabbit hole because ECS will return this error if you try to enable assign_public_ip on EC2 launch types:
InvalidParameterException: Assign public IP is not supported for this launch type.

Unfortunately, as noted in #85, the error handling in this resource is already causing trouble as it is retrying on some conditions like the above when it shouldn't be. The launch type and assign_public_ip combination is something we can validate at plan time, but the implementation is a little more complex than just few lines. I think it'll be best if I fix both of these issues together as its already hindering my acceptance testing. More soon.

@johnnorton
Copy link
Contributor Author

@bflad Excellent. Please let me know if I can help.

@bflad bflad merged commit 554f63d into hashicorp:master Feb 9, 2018
bflad added a commit that referenced this pull request Feb 9, 2018
@cemo
Copy link

cemo commented Feb 9, 2018

@bflad milestone seems v1.10.0, it should be v1.9.0

@bflad bflad modified the milestones: v1.10.0, v1.9.0 Feb 9, 2018
@bflad
Copy link
Contributor

bflad commented Feb 9, 2018

@cemo good catch, thanks and updated. Also, shout out to @johnnorton for working though the original PR.

@bflad
Copy link
Contributor

bflad commented Feb 9, 2018

This has been released in terraform-provider-aws version 1.9.0. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

jocgir added a commit to coveooss/terraform-provider-aws that referenced this pull request Feb 12, 2018
* commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (224 commits)
  v1.9.0
  Update CHANGELOG for hashicorp#1101 and hashicorp#3283
  docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing
  resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv
  Add lambda example (hashicorp#3168)
  Update CHANGELOG for hashicorp#3157
  docs/data-source/aws_region: Remove now deprecated current argument
  data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions
  Update CHANGELOG for hashicorp#3301
  Update CHANGELOG for hashicorp#2559 and hashicorp#3240
  Update CHANGELOG.md
  resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108)
  Update CHANGELOG.md
  resource/aws_dynamodb_table_item: Cleanup + add missing bits
  Added dynamodb_table_item resource hashicorp#517
  Update CHANGELOG.md
  New Resource: aws_cloud9_environment_ec2
  Update CHANGELOG.md
  Fixed markdown typo in docs
  resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn
  ...

# Conflicts:
#	aws/validators.go
jocgir added a commit to coveooss/terraform-provider-aws that referenced this pull request Feb 12, 2018
…parameters-features

* commit '5293a0e3b1366ee16d8742b9b2354781a79bfbd9': (752 commits)
  v1.9.0
  Update CHANGELOG for hashicorp#1101 and hashicorp#3283
  docs/resource/aws_sns_platform_application: Add note about platform_credential and platform_principal hashing
  resource/aws_sns_platform_application: Refactor ID parsing to its own function, use testing.T in testAccAwsSnsPlatformApplicationPlatformFromEnv
  Add lambda example (hashicorp#3168)
  Update CHANGELOG for hashicorp#3157
  docs/data-source/aws_region: Remove now deprecated current argument
  data-source/aws_region: Refactor logic into findRegionByEc2Endpoint and findRegionByName functions
  Update CHANGELOG for hashicorp#3301
  Update CHANGELOG for hashicorp#2559 and hashicorp#3240
  Update CHANGELOG.md
  resource/aws_kinesis_stream: Retry deletion on LimitExceededException (hashicorp#3108)
  Update CHANGELOG.md
  resource/aws_dynamodb_table_item: Cleanup + add missing bits
  Added dynamodb_table_item resource hashicorp#517
  Update CHANGELOG.md
  New Resource: aws_cloud9_environment_ec2
  Update CHANGELOG.md
  Fixed markdown typo in docs
  resource/aws_kinesis_firehose_delivery_stream: Prevent crashes on empty CloudWatchLoggingOptions and fix extended_s3_configuration kms_key_arn
  ...

# Conflicts:
#	aws/resource_aws_ssm_parameter_test.go
@johnnorton johnnorton deleted the feature/fargate_support_v2 branch February 13, 2018 01:54
@ghost
Copy link

ghost commented Apr 8, 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 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants