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

New resource: service discovery http namespace #6864

Merged
merged 5 commits into from
Dec 19, 2018

Conversation

saravanan30erd
Copy link
Contributor

Fixes #6783

Output from acceptance testing:

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

@ghost ghost added size/L Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. service/servicediscovery Issues and PRs that pertain to the servicediscovery service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. documentation Introduces or discusses updates to documentation. labels Dec 15, 2018
@bflad bflad added the new-resource Introduces a new resource. label Dec 17, 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.

Thanks so much for submitting this @saravanan30erd! A few little things and it should be good to go. Please let us know if you have any questions or do not have time to implement the feedback. 😄


input := &servicediscovery.CreateHttpNamespaceInput{
Name: aws.String(name),
CreatorRequestId: aws.String(requestId),
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it doesn't look like we need any real value for this ID since we don't save it anywhere and according to the SDK docs:

// CreatorRequestId can be any unique string, for example, a date/time stamp.

Should we remove all the logic above and simplify this?

Suggested change
CreatorRequestId: aws.String(requestId),
CreatorRequestId: aws.String(resource.UniqueId()),


resp, err := conn.CreateHttpNamespace(input)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error creating Service Discovery HTTP Namespace (%s): %s", name, err)


opresp, err := stateConf.WaitForState()
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error waiting for Service Discovery HTTP Namespace (%s) creation: %s", name, err)

d.SetId("")
return nil
}
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error reading Service Discovery HTTP Namespace (%s): %s", d.Id(), err)


resp, err := conn.DeleteNamespace(input)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error deleting Service Discovery HTTP Namespace (%s): %s", d.Id(), err)


_, err = stateConf.WaitForState()
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.

Suggested change
return err
return fmt.Errorf("error waiting for Service Discovery HTTP Namespace (%s) deletion: %s", d.Id(), err)

return err
}

d.SetId(*opresp.(*servicediscovery.GetOperationOutput).Operation.Targets["NAMESPACE"])
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally we'd ask for d.SetId() to be right after the creation and before the waiter to prevent creating potentially orphaned resources, but since the API doesn't return the namespace ID until you read the operation in the waiter, this is okay. 👍


func TestAccAWSServiceDiscoveryHttpNamespace_basic(t *testing.T) {
resourceName := "aws_service_discovery_http_namespace.test"
rName := "terraformtesting"
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be good to randomize this now, before additional parallel tests are added. 👍

Suggested change
rName := "terraformtesting"
rName := acctest.RandomWithPrefix("tf-acc-test")

_, err := conn.GetNamespace(input)
if err != nil {
if isAWSErr(err, servicediscovery.ErrCodeNamespaceNotFound, "") {
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This return nil should be replaced with continue so the for loop can check other aws_service_discovery_http_namespace resources for deletion if/when a test configuration contains multiple. 👍

Suggested change
return nil
continue

return fmt.Sprintf(`
resource "aws_service_discovery_http_namespace" "test" {
name = %q
description = "test"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: While its likely handled properly in the resource code already, it'd be nice if description was removed in the basic test configuration and tested separately since it is an optional argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I probably should have been more clear what I meant. While splitting out the description test was the first step, the next steps were removing this line here in testAccServiceDiscoveryHttpNamespaceConfig() so TestAccAWSServiceDiscoveryHttpNamespace_basic() doesn't add Description to the CreateHttpNamespace call, then creating a separate configuration function for usage in the description test:

func testAccServiceDiscoveryHttpNamespaceConfigDescription(rName, description string) string {
	return fmt.Sprintf(`
resource "aws_service_discovery_http_namespace" "test" {
  description = %q
  name        = %q
}
`, description, rName)
}

That's my bad. I'll make this adjustment on merge rather than bothering you about it.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Dec 19, 2018
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Dec 19, 2018
@saravanan30erd
Copy link
Contributor Author

@bflad Done all the changes

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSServiceDiscoveryHttpNamespace_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSServiceDiscoveryHttpNamespace_ -timeout 120m
=== RUN TestAccAWSServiceDiscoveryHttpNamespace_basic
=== PAUSE TestAccAWSServiceDiscoveryHttpNamespace_basic
=== RUN TestAccAWSServiceDiscoveryHttpNamespace_checkDescription
=== PAUSE TestAccAWSServiceDiscoveryHttpNamespace_checkDescription
=== CONT TestAccAWSServiceDiscoveryHttpNamespace_basic
=== CONT TestAccAWSServiceDiscoveryHttpNamespace_checkDescription
--- PASS: TestAccAWSServiceDiscoveryHttpNamespace_basic (124.12s)
--- PASS: TestAccAWSServiceDiscoveryHttpNamespace_checkDescription (124.12s)
PASS
ok github.com/terraform-providers/terraform-provider-aws/aws 124.165s

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Dec 19, 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.

LGTM, thanks @saravanan30erd! 🚀

--- PASS: TestAccAWSServiceDiscoveryHttpNamespace_basic (89.74s)
--- PASS: TestAccAWSServiceDiscoveryHttpNamespace_checkDescription (89.78s)

return fmt.Sprintf(`
resource "aws_service_discovery_http_namespace" "test" {
name = %q
description = "test"
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I probably should have been more clear what I meant. While splitting out the description test was the first step, the next steps were removing this line here in testAccServiceDiscoveryHttpNamespaceConfig() so TestAccAWSServiceDiscoveryHttpNamespace_basic() doesn't add Description to the CreateHttpNamespace call, then creating a separate configuration function for usage in the description test:

func testAccServiceDiscoveryHttpNamespaceConfigDescription(rName, description string) string {
	return fmt.Sprintf(`
resource "aws_service_discovery_http_namespace" "test" {
  description = %q
  name        = %q
}
`, description, rName)
}

That's my bad. I'll make this adjustment on merge rather than bothering you about it.

@bflad bflad added this to the v1.53.0 milestone Dec 19, 2018
@bflad bflad merged commit c2b0315 into hashicorp:master Dec 19, 2018
bflad added a commit that referenced this pull request Dec 19, 2018
@bflad
Copy link
Contributor

bflad commented Dec 20, 2018

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

@namliz
Copy link

namliz commented Dec 27, 2018

@bflad I'm glad this was merged but it is missing functionality or is slightly wrong in how it does things.

Opened #7016.

@ghost
Copy link

ghost commented Apr 1, 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 1, 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. new-resource Introduces a new resource. provider Pertains to the provider itself, rather than any interaction with AWS. service/servicediscovery Issues and PRs that pertain to the servicediscovery service. size/XL 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.

Feature request: Support HTTP namespaces for service discovery
3 participants