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
18 changes: 15 additions & 3 deletions aws/resource_aws_ecs_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,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.

Type: schema.TypeString,
Optional: true,
Default: "DISABLED",
},
},
},
},
Expand Down Expand Up @@ -400,9 +405,12 @@ func flattenEcsNetworkConfigration(nc *ecs.NetworkConfiguration) []interface{} {
if nc == nil {
return nil
}

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"] = *nc.AwsvpcConfiguration.AssignPublicIp

return []interface{}{result}
}

Expand All @@ -416,6 +424,11 @@ func expandEcsNetworkConfigration(nc []interface{}) *ecs.NetworkConfiguration {
awsVpcConfig.SecurityGroups = expandStringSet(val.(*schema.Set))
}
awsVpcConfig.Subnets = expandStringSet(raw["subnets"].(*schema.Set))
log.Printf("[DEBUG] assign_public_ip %s", raw["assign_public_ip"])
if val, ok := raw["assign_public_ip"].(string); ok {
awsVpcConfig.AssignPublicIp = aws.String(val)
log.Printf("[DEBUG] AssingPublicIp %s", awsVpcConfig.AssignPublicIp)
}
return &ecs.NetworkConfiguration{AwsvpcConfiguration: awsVpcConfig}
}

Expand Down Expand Up @@ -481,9 +494,8 @@ func resourceAwsEcsServiceUpdate(d *schema.ResourceData, meta interface{}) error
}
}

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?

input.NetworkConfiguration = expandEcsNetworkConfigration(d.Get("network_configuration").([]interface{}))

// Retry due to IAM & ECS eventual consistency
err := resource.Retry(2*time.Minute, func() *resource.RetryError {
Expand Down
1 change: 1 addition & 0 deletions aws/resource_aws_ecs_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}
}
`, rName, rName)
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/ecs_service.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Guide](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-
`network_configuration` support the following:
* `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.

For more information, see [Task Networking](http://docs.aws.amazon.com/AmazonECS/latest/developerguidetask-networking.html)

## Attributes Reference
Expand Down