-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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: aws_api_gateway_vpc_link #2512
New Resource: aws_api_gateway_vpc_link #2512
Conversation
atsushi-ishibashi
commented
Dec 1, 2017
•
edited
Loading
edited
- test
- docs
So I set |
😕
|
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 the work here! This is looking really good :)
Just left a few comments to address before merging this! 👍 🚀
|
||
resp, err := conn.GetVpcLink(input) | ||
if err != nil { | ||
if ecrerr, ok := err.(awserr.Error); 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.
We can rewrite a part of this block to:
if isAWSErr(err, "ErrCodeNotFoundException", "some message returned by the API") {
...
}
Where some message returned by the API
is actually a message when this error happens! 😄
(the same should be applied to the update & delete parts)
target_arn = "${aws_lb.test_a.arn}" | ||
} | ||
`, rName, rName) | ||
} |
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 also add a test with an actual API Gateway and a HTTP endpoint, so that we ensure it's all ok.
I'm actually wondering whether we need a hard dependency (using depends_on
) on the HTTP integration since this resource is just creating a link between the API Gateway service & the VPC targets... 🤔
Not sure if this could result in race dependencies! 🤷♂️
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 couldn't understand what you meant so cloud you describe more details:bow: ? @Ninir
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 guess what @Ninir means is that we should add a test which tests the full setup including API Gateway integration leveraging the VPC Link.
It seems we'd also need to update other API Gateway resources to make that happen, namely to add few more attributes to aws_api_gateway_integration
per http://docs.aws.amazon.com/apigateway/api-reference/resource/integration/#connectionType
I'm personally ok with shipping this resource as is and addressing the above in a separate PR to keep diffs small and easier to review - what do you think @Ninir ?
Pending: []string{apigateway.VpcLinkStatusPending}, | ||
Target: []string{apigateway.VpcLinkStatusAvailable}, | ||
Refresh: apigatewayVpcLinkRefreshStatusFunc(conn, *resp.Id), | ||
Timeout: 10 * time.Minute, |
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.
Does the timeout really need to be this big? (same goes for the update)
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.
Docs says
Creates a VPC link, under the caller's account in a selected region, in an asynchronous operation that typically takes 2-4 minutes to complete and become operational.
So I set 5 minutes:bow:
Provides an API Gateway VPC Link. | ||
--- | ||
|
||
# aws_api_gateway_usage_plan |
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.
Copy/pasta typo? 😄
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.
😅
Just checking on the status of this as I am really looking forward to this feature. Looks like it has stalled a bit over the holidays. |
@atsushi-ishibashi Just encountering an issue with the tests:
Do you have time to investigate? Thanks! |
@Ninir Uhhh.. There may be possibility that vpc link was deleting when api to delete nlb was called. |
After
What is the best way to wait until completely deleted? |
|
I have it's possible to use |
Good idea👍 Thanks! |
Pending: []string{apigateway.VpcLinkStatusPending}, | ||
Target: []string{apigateway.VpcLinkStatusAvailable}, | ||
Refresh: apigatewayVpcLinkRefreshStatusFunc(conn, *resp.Id), | ||
Timeout: 5 * time.Minute, |
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 was trying this PR out, and hit a case where this operation timed out after 5 minutes. The VPC Link did end up being successfully created. The AWS docs note that this can take "2-4 minutes", so it may be worth allowing more buffer here (and on update), to ensure these don't time out under normal conditions?
https://docs.aws.amazon.com/cli/latest/reference/apigateway/create-vpc-link.html
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 your advice!
@Ninir Ok, the test passed
|
|
||
* `name` - (Required) The name used to label and identify the VPC link. | ||
* `description` - (Optional) The description of the VPC link. | ||
* `target_arn` - (Required, ForceNew) The ARN of network load balancer of the VPC targeted by the VPC link. |
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.
(Required, ForceNew) The ARN of a network load balancer in the VPC targeted by the VPC link.
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 correct me!
Hey folks, this looks very promising. What is the status of this pull request? Would love to see this resource in terraform. ✌️ |
Also checking in on this. I'm also thinking that |
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.
@atsushi-ishibashi thanks for the PR and @Ninir for earlier review.
I left you some (hopefully final) questions/comments.
return fmt.Errorf("[WARN] Error waiting for APIGateway Vpc Link status to be \"%s\": %s", apigateway.VpcLinkStatusAvailable, err) | ||
} | ||
|
||
d.SetId(*resp.Id) |
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 usually set the ID as soon as we can after receiving it from the API, before making any further requests so that it's recorded in the state in case any future API requests fail for any reason. Do you mind moving it above the StateChangeConf
block?
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: 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.
Is there any particular reason this should be implemented as 1-1 relationship instead of reflecting the API, i.e. allowing users to assign multiple LBs to one VPC link?
resp, err := conn.GetVpcLink(input) | ||
if err != nil { | ||
if isAWSErr(err, apigateway.ErrCodeNotFoundException, "") { | ||
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.
Nitpick: Do you mind adding our usual WARN
log message here?
Pending: []string{apigateway.VpcLinkStatusPending, | ||
apigateway.VpcLinkStatusAvailable, | ||
apigateway.VpcLinkStatusDeleting}, | ||
Target: []string{"deleted"}, |
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.
Using empty string here is equally valid and in fact preferred, over making up our own statuses 😉
return err | ||
} | ||
|
||
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.
Nitpick: I know we still have it in many resources, but it's redundant. The ID is emptied automatically in the core.
return err | ||
} | ||
|
||
if *resp.Status != apigateway.VpcLinkStatusDeleting { |
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 we should treat any positive response here as a failure - the VPC link should be already deleted by the time test finishes and practically have no status (i.e. it shouldn't be in deleting
status).
if !ok { | ||
return fmt.Errorf("Not found: %s", name) | ||
} | ||
|
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.
Do you mind checking the API here also?
@radeksimko I remembered that the interface could accept a multiple of lb but you can apply only one lb. Refer to web console as well.
However in the future, aws may support multiple so it's better to use |
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.
However in the future, aws may support multiple so it's better to use MaxItem for now. What do you think?
I agree - see my inline comments. We can add MaxItems: 1
for now and eventually remove it once/if Amazon decides to raise the limit.
cidr_block = "10.10.0.0/21" | ||
availability_zone = "${data.aws_availability_zones.test.names[0]}" | ||
} | ||
`, rName, rName) |
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.
The main reason the test is failing the way it's failing is because two resources (aws_lb.test_a
and aws_lb.test_b
) both have the same name and the TypeSet
will internally merge them into a single ARN since the ARN is the same.
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.
Once you fix that you get more reasonable error which I think we can just present to the user:
* aws_api_gateway_vpc_link.test: BadRequestException: More than one target arn specified for vpc link.
status code: 400, request id: d4eabe6c-0ff8-11e8-bea2-d9187e5e8757
As you rightly mentioned Amazon currently doesn't support more than 1 LB though, so we'll have to keep this test focused on single LB only.
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.
That's right! Thank you for correct.
@radeksimko 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.
✅ 👍 Thanks @atsushi-ishibashi
This has been released in version 1.10.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! |