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

resource/ecs_service: Support ServiceRegistries #3906

Merged
merged 3 commits into from
Apr 12, 2018

Conversation

atsushi-ishibashi
Copy link
Contributor

required: #3905
rebase after #3905 merged.

TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_withServiceRegistries -timeout 120m
=== RUN   TestAccAWSEcsService_withServiceRegistries
--- PASS: TestAccAWSEcsService_withServiceRegistries (131.90s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	131.944s

@ghost ghost added size/XXL Managed by automation to categorize the size of a PR. dependencies Used to indicate dependency changes. labels Mar 24, 2018
@radeksimko radeksimko added the service/ecs Issues and PRs that pertain to the ecs service. label Mar 26, 2018
@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/XXL Managed by automation to categorize the size of a PR. dependencies Used to indicate dependency changes. labels Mar 26, 2018
@atsushi-ishibashi
Copy link
Contributor Author

rebased

@jeffnappi
Copy link
Contributor

Looking forward to making use of this 👍 Thanks!

@stevecrozz
Copy link

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:

InvalidParameterException: A port was provided but is not required by the specified service registry

@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Apr 3, 2018
@bflad
Copy link
Contributor

bflad commented Apr 3, 2018

Issue reference: #4025

@@ -204,6 +204,24 @@ func resourceAwsEcsService() *schema.Resource {
},
},
},

"service_registries": {
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you!

sr := &ecs.ServiceRegistry{
RegistryArn: aws.String(raw["registry_arn"].(string)),
}
if port, ok := raw["port"].(int); ok {
Copy link

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure👍 I'll fix

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Apr 4, 2018
@atsushi-ishibashi
Copy link
Contributor Author

TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_withServiceRegistries -timeout 120m
=== RUN   TestAccAWSEcsService_withServiceRegistries
--- PASS: TestAccAWSEcsService_withServiceRegistries (111.30s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	111.336s

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.

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,
Copy link
Contributor

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.

Copy link
Contributor Author

@atsushi-ishibashi atsushi-ishibashi Apr 5, 2018

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.

"registry_arn": {
Type: schema.TypeString,
Required: true,
},
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure👍

"port": {
Type: schema.TypeInt,
Optional: true,
},
Copy link
Contributor

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 {
Copy link
Contributor

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 😄

Copy link
Contributor Author

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.

}
results := make([]map[string]interface{}, 0)
for _, sr := range srs {
c := make(map[string]interface{})
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure👍

Copy link
Contributor Author

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"),
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure👍

name = "tf-acc-sd-%s"
dns_config {
namespace_id = "${aws_service_discovery_private_dns_namespace.test.id}"
dns_records {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: indentation

desired_count = 1
service_registries {
port = 34567
registry_arn = "${aws_service_discovery_service.test.arn}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: indentation

@atsushi-ishibashi
Copy link
Contributor Author

TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_withServiceRegistries -timeout 120m
=== RUN   TestAccAWSEcsService_withServiceRegistries
--- PASS: TestAccAWSEcsService_withServiceRegistries (73.29s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	73.323s
TF_ACC=1 go test ./aws -v -run=TestAccAWSEcsService_withARN -timeout 120m
=== RUN   TestAccAWSEcsService_withARN
--- PASS: TestAccAWSEcsService_withARN (66.16s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	66.194s

@Wesam18
Copy link

Wesam18 commented Apr 12, 2018

@bflad @atsushi-ishibashi
We do have a need for this feature. When do we expect to have it released?

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.

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"

@bflad bflad added this to the v1.15.0 milestone Apr 12, 2018
@bflad bflad merged commit 4ff21b9 into hashicorp:master Apr 12, 2018
bflad added a commit that referenced this pull request Apr 12, 2018
@bflad
Copy link
Contributor

bflad commented Apr 18, 2018

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.

@ghost
Copy link

ghost commented Apr 6, 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 6, 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/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants