-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Add new aws_vpc_endpoint_route_table_association resource #10137
Conversation
This commit adds a new resource which allows to a list of route tables to be either added and/or removed from an existing VPC Endpoint. This resource would also be complimentary to the existing `aws_vpc_endpoint` resource where the route tables might not be specified (not a requirement for a VPC Endpoint to be created successfully) during creation, especially where the workflow is such where the route tables are not immediately known. Signed-off-by: Krzysztof Wilczynski <[email protected]> Additions by Kit Ewbank <[email protected]>: * Add functionality * Add documentation * Add acceptance tests * Set VPC endpoint route_table_ids attribute to "Computed"
Acceptance tests:
|
if err != nil { | ||
return fmt.Errorf("Error creating VPC Endpoint/Route Table association: %s", err.Error()) | ||
} | ||
|
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 believe generally you should be calling the d.SetId
here to populate the state, the fact that you call Read
immediately makes it a bit less necessary but is the pattern I've seen around the code base.
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.
OK, I'll fix that.
Removing the [WIP] marker. |
@ewbankkit hi there! Thank you for completing this when I could not do it. You are a ⭐️ ! I do agree that relying on |
return &schema.Resource{ | ||
Create: resourceAwsVPCEndpointRouteTableAssociationCreate, | ||
Read: resourceAwsVPCEndpointRouteTableAssociationRead, | ||
// "resource aws_vpc_endpoint_route_table_association: All fields are ForceNew or Computed w/out Optional, Update is superfluous" |
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 would get rid of the comment here. If we are never going to use UpdateFunc
then I would not bother with clarification.
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.
Will do.
return fmt.Errorf("Error deleting VPC Endpoint/Route Table association: %s", err.Error()) | ||
} | ||
|
||
switch ec2err.Code() { |
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.
Here, I would use fallthrough
for both NotFound
and simply log a simple message. Even more, perhaps catch all in the fallthrough
case, and then issue a single message noting that it is gone (we do that in few other places). I could also be re-factored to catch the !ok
case once, I believe.
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.
OK
return fmt.Sprintf("a-%s%d", endpointId, hashcode.String(rtId)) | ||
} | ||
|
||
type vpcEndpointNotFound struct { |
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 am struggling with this a bit - do we need a custom type (also same in the code below) for two error messages?
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'll revisit. I based that on another resource and maybe it's overkill in this situation.
* Removed error types and simplified the error handling in 'resourceAwsVPCEndpointRouteTableAssociationRead' * Simplified logging in 'resourceAwsVPCEndpointRouteTableAssociationDelete'
Pushed changes after @kwilczynski's code review:
|
} | ||
if !found { | ||
// The association no longer exists. | ||
d.SetId("") |
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.
A quick follow up point for the future - we usually log a message here just to let the user know we have removed from state
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.
OK. I won't change this now. Thanks for the tip.
return nil, err | ||
} | ||
|
||
return output.VpcEndpoints[0], 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.
Can we guarantee that it's the first endpoint in the collection?
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.
Yes. The desired VPC endpoint ID is passed as an input parameter and the API call will return either that VPC endpoint or a client error such as InvalidVpcEndpointId.Malformed
or InvalidVpcEndpointId.NotFound
.
We should be good here.
Hi @ewbankkit this LGTM! I left a few small questions inline - if you are happy with those then we can push forward Thanks to @kwilczynski for the review as well P. |
Sorry, at re:Invent all last week. I'll address these now... |
Hi @ewbankkit Thanks for the work here (and the responses to my nit questions) This LGTM!
|
…10137) * Add new aws_vpc_endpoint_route_table_association resource. This commit adds a new resource which allows to a list of route tables to be either added and/or removed from an existing VPC Endpoint. This resource would also be complimentary to the existing `aws_vpc_endpoint` resource where the route tables might not be specified (not a requirement for a VPC Endpoint to be created successfully) during creation, especially where the workflow is such where the route tables are not immediately known. Signed-off-by: Krzysztof Wilczynski <[email protected]> Additions by Kit Ewbank <[email protected]>: * Add functionality * Add documentation * Add acceptance tests * Set VPC endpoint route_table_ids attribute to "Computed" * Changes after review - Set resource ID in create function. * Changes after code review by @kwilczynski: * Removed error types and simplified the error handling in 'resourceAwsVPCEndpointRouteTableAssociationRead' * Simplified logging in 'resourceAwsVPCEndpointRouteTableAssociationDelete'
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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
This PR follows on from #9244 and addresses #9138.
Here's the log from @kwilczynski's initial commit:
As it stands now the new
aws_vpc_endpoint_route_table_association
resource associates/dissociates as singleroute_table_id
with a VPC endpoint.Somehow I feel it's "better" Terraform to use a
count
attribute on the resource to associate multiple route tables with a VPC endpoint rather than accept a list of route tables in a single association, e.g.Since this is a "synthetic" resource (no underlying AWS resource maps exactly to this) this doesn't cause a cognitive disconnect, plus it greatly simplifies the implementation.
I welcome feedback on this, especially from @coen-hyde and @supergibbs who commented on the associated issue.