-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
resource/ecs_service: Support ServiceRegistries #3906
resource/ecs_service: Support ServiceRegistries #3906
Conversation
a7964cf
to
cd54da5
Compare
rebased |
Looking forward to making use of this 👍 Thanks! |
I gave this a try today @atsushi-ishibashi. It looks like its going to work, but I did run into one minor issue when using it with a aws_service_discovery_service which uses A records. The Port parameter should be optional as it says in your documentation, but when I don't provide a port, it looks like this code provides a blank one and I get an error:
|
Issue reference: #4025 |
@@ -204,6 +204,24 @@ func resourceAwsEcsService() *schema.Resource { | |||
}, | |||
}, | |||
}, | |||
|
|||
"service_registries": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can only support MaxItems == 1
. When I tried using more than one registry in #4026 I got back an error from AWS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
aws/resource_aws_ecs_service.go
Outdated
sr := &ecs.ServiceRegistry{ | ||
RegistryArn: aws.String(raw["registry_arn"].(string)), | ||
} | ||
if port, ok := raw["port"].(int); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want ok && port != 0
to prevent what @stevecrozz was seeing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure👍 I'll fix
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this contribution! Left some initial comments below. Please let me know if you have any questions or do not have time to implement the feedback.
@@ -204,6 +204,25 @@ func resourceAwsEcsService() *schema.Resource { | |||
}, | |||
}, | |||
}, | |||
|
|||
"service_registries": { | |||
Type: schema.TypeSet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify the implementation, we should opt for schema.TypeList
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far, MaxItems is 1 but there is a possibility that aws increases it.
And the order of service_registries
has no meaning, so I think set is better.
aws/resource_aws_ecs_service.go
Outdated
"registry_arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add ValidateFunc: validateArn,
for this attribute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure👍
aws/resource_aws_ecs_service.go
Outdated
"port": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably add ValidateFunc: validation.IntBetween(0, 65536),
for this attribute
serviceRegistries := d.Get("service_registries").(*schema.Set).List() | ||
if len(serviceRegistries) > 0 { | ||
srs := make([]*ecs.ServiceRegistry, 0, len(serviceRegistries)) | ||
for _, v := range serviceRegistries { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need the for loop for MaxItems == 1
attributes 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a possibility of increase.
aws/resource_aws_ecs_service.go
Outdated
} | ||
results := make([]map[string]interface{}, 0) | ||
for _, sr := range srs { | ||
c := make(map[string]interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to:
m := map[string]interface{}{
"port": int(aws.Int64Value(sr.Port)),
"registry_arn": aws.StringValue(sr.RegistryArn),
}
results = append(results, m)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When sr.Port is null, is it OK?
Config: testAccAWSEcsService_withServiceRegistries(rString, clusterName, tdName, svcName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckAWSEcsServiceExists("aws_ecs_service.test", &service), | ||
resource.TestCheckResourceAttr("aws_ecs_service.test", "service_registries.#", "1"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should test for service_registries.#
of "0"
in the basic test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure👍
aws/resource_aws_ecs_service_test.go
Outdated
name = "tf-acc-sd-%s" | ||
dns_config { | ||
namespace_id = "${aws_service_discovery_private_dns_namespace.test.id}" | ||
dns_records { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: indentation
aws/resource_aws_ecs_service_test.go
Outdated
desired_count = 1 | ||
service_registries { | ||
port = 34567 | ||
registry_arn = "${aws_service_discovery_service.test.arn}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: indentation
|
@bflad @atsushi-ishibashi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for getting this support added! LGTM 🚀
Test failure unrelated:
Tests failed: 1, passed: 16
=== RUN TestAccAWSEcsService_withUnnormalizedPlacementStrategy
--- PASS: TestAccAWSEcsService_withUnnormalizedPlacementStrategy (11.22s)
=== RUN TestAccAWSEcsService_withDeploymentValues
--- PASS: TestAccAWSEcsService_withDeploymentValues (31.93s)
=== RUN TestAccAWSEcsService_withEcsClusterName
--- PASS: TestAccAWSEcsService_withEcsClusterName (32.22s)
=== RUN TestAccAWSEcsService_withARN
--- PASS: TestAccAWSEcsService_withARN (41.49s)
=== RUN TestAccAWSEcsService_withPlacementConstraints
--- PASS: TestAccAWSEcsService_withPlacementConstraints (42.18s)
=== RUN TestAccAWSEcsService_basicImport
--- PASS: TestAccAWSEcsService_basicImport (42.45s)
=== RUN TestAccAWSEcsService_withPlacementStrategy
--- PASS: TestAccAWSEcsService_withPlacementStrategy (47.64s)
=== RUN TestAccAWSEcsService_withServiceRegistries
--- PASS: TestAccAWSEcsService_withServiceRegistries (49.93s)
=== RUN TestAccAWSEcsService_withFamilyAndRevision
--- PASS: TestAccAWSEcsService_withFamilyAndRevision (53.54s)
=== RUN TestAccAWSEcsService_withPlacementConstraints_emptyExpression
--- PASS: TestAccAWSEcsService_withPlacementConstraints_emptyExpression (63.49s)
=== RUN TestAccAWSEcsService_withRenamedCluster
--- PASS: TestAccAWSEcsService_withRenamedCluster (70.93s)
=== RUN TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration
--- PASS: TestAccAWSEcsService_withLaunchTypeEC2AndNetworkConfiguration (73.19s)
=== RUN TestAccAWSEcsService_withIamRole
--- PASS: TestAccAWSEcsService_withIamRole (119.23s)
=== RUN TestAccAWSEcsService_withLbChanges
--- PASS: TestAccAWSEcsService_withLbChanges (145.02s)
=== RUN TestAccAWSEcsService_withAlb
--- PASS: TestAccAWSEcsService_withAlb (194.58s)
=== RUN TestAccAWSEcsService_healthCheckGracePeriodSeconds
--- PASS: TestAccAWSEcsService_healthCheckGracePeriodSeconds (230.54s)
=== RUN TestAccAWSEcsService_withLaunchTypeFargate
--- FAIL: TestAccAWSEcsService_withLaunchTypeFargate (260.51s)
testing.go:518: Step 0 error: After applying this step, the plan was not empty:
DIFF:
UPDATE: aws_security_group.allow_all_a
ingress.#: "0" => "1"
ingress.2269895920.cidr_blocks.#: "0" => "1"
ingress.2269895920.cidr_blocks.0: "" => "10.10.0.0/16"
ingress.2269895920.description: "" => ""
ingress.2269895920.from_port: "" => "80"
ingress.2269895920.ipv6_cidr_blocks.#: "0" => "0"
ingress.2269895920.protocol: "" => "tcp"
ingress.2269895920.security_groups.#: "0" => "0"
ingress.2269895920.self: "" => "false"
ingress.2269895920.to_port: "" => "8000"
This has been released in version 1.15.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
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! |
required: #3905
rebase after #3905 merged.