-
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
New resource: service discovery http namespace #6864
Conversation
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 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), |
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.
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?
CreatorRequestId: aws.String(requestId), | |
CreatorRequestId: aws.String(resource.UniqueId()), |
|
||
resp, err := conn.CreateHttpNamespace(input) | ||
if err != nil { | ||
return err |
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.
Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.
return err | |
return fmt.Errorf("error creating Service Discovery HTTP Namespace (%s): %s", name, err) |
|
||
opresp, err := stateConf.WaitForState() | ||
if err != nil { | ||
return err |
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.
Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.
return err | |
return fmt.Errorf("error waiting for Service Discovery HTTP Namespace (%s) creation: %s", name, err) |
d.SetId("") | ||
return nil | ||
} | ||
return err |
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.
Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.
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 |
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.
Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.
return err | |
return fmt.Errorf("error deleting Service Discovery HTTP Namespace (%s): %s", d.Id(), err) |
|
||
_, err = stateConf.WaitForState() | ||
if err != nil { | ||
return err |
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.
Nit: We should provide context about when this error occurred for operators and code maintainers, e.g.
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"]) |
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.
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" |
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.
It'd be good to randomize this now, before additional parallel tests are added. 👍
rName := "terraformtesting" | |
rName := acctest.RandomWithPrefix("tf-acc-test") |
_, err := conn.GetNamespace(input) | ||
if err != nil { | ||
if isAWSErr(err, servicediscovery.ErrCodeNamespaceNotFound, "") { | ||
return nil |
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 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. 👍
return nil | |
continue |
return fmt.Sprintf(` | ||
resource "aws_service_discovery_http_namespace" "test" { | ||
name = %q | ||
description = "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.
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.
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.
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 Done all the changes $ make testacc TEST=./aws TESTARGS='-run=TestAccAWSServiceDiscoveryHttpNamespace_' |
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.
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" |
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.
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.
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. |
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! |
Fixes #6783
Output from acceptance testing: