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

Add aws_vpn_gateway_attachment resource. #7870

Conversation

kwilczynski
Copy link
Contributor

This commit adds VPN Gateway attachment resource, and also an initial tests and documentation stubs.

Signed-off-by: Krzysztof Wilczynski krzysztof.wilczynski@linux.com

@kwilczynski kwilczynski changed the title Add aws_vpn_gateway_attachment resource. [WIP] Add aws_vpn_gateway_attachment resource. Jul 29, 2016
@kwilczynski
Copy link
Contributor Author

kwilczynski commented Jul 29, 2016

Resolves #7810.

Things to do:

  • Add aws_vpn_gateway_attachment resource.
  • Update aws_vpn_gateway resource so that vpc_id attribute is a computed value.
  • Correct state detection in aws_vpn_gateway.
  • Add acceptance tests.
  • Add documentation.
  • Fix acceptance tests for the aws_vpn_gateway resource.
  • Filter VpcAttachments response which are in the "attached" state only.

@kwilczynski
Copy link
Contributor Author

I had a chat with @stack72 and we need to change the way how state of VPN Gateway is detected in the #7861, it should be corrected e.g.,

    if len(vpnGateway.VpcAttachments) == 0 || *vpnGateway.VpcAttachments[0].State == "detached" || *vpnGateway.State == "deleted" {
        d.Set("vpc_id", "")
    } else {
        d.Set("vpc_id", vpnGateway.VpcAttachments[0].VpcId)
    }

or

    vpnGateway := resp.VpnGateways[0]
    if vpnGateway == nil || *vpnGateway.State == "deleted" {
        d.SetId("")
        return nil
    }

@stack72
Copy link
Contributor

stack72 commented Jul 31, 2016

@kwilczynski we still need the part that does this || *vpnGateway.VpcAttachments[0].State == "detached" that is valid :)

@kwilczynski
Copy link
Contributor Author

@stack72 what I am suggesting is either to treat deleted gateway as "gone", and so to adda check here; resource_aws_vpn_gateway.go#L82-L87; or checking for "deleted" state along the VPN attachments (as per resource_aws_vpn_gateway.go#L89-L94, which might not be a good idea as "detached" will also satisfy the condition when the gateway is deleted (as VPN Gateway would return for a brief moment as being both deleted and detached) - this results only in clearing out the VPC ID and might not trigger new resource to be added.

What do you think?

I will test later to make sure that the logic holds water.

@kwilczynski
Copy link
Contributor Author

@stack72 over to you! 🚀

@kwilczynski
Copy link
Contributor Author

Tests are passing:

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGatewayAttachment_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/01 11:26:06 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGatewayAttachment_ -timeout 120m
=== RUN   TestAccAWSVpnGatewayAttachment_basic
--- PASS: TestAccAWSVpnGatewayAttachment_basic (71.04s)
=== RUN   TestAccAWSVpnGatewayAttachment_deleted
--- PASS: TestAccAWSVpnGatewayAttachment_deleted (91.58s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    162.648s

@kwilczynski kwilczynski force-pushed the feature/resource_aws_vpn_gateway_attachment branch from 4648a97 to ed406d2 Compare August 1, 2016 02:53
@@ -80,7 +81,7 @@ func resourceAwsVpnGatewayRead(d *schema.ResourceData, meta interface{}) error {
}

vpnGateway := resp.VpnGateways[0]
if vpnGateway == nil {
if vpnGateway == nil || *vpnGateway.State == "deleted" {
Copy link
Contributor

Choose a reason for hiding this comment

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

if we are adding state == "deleted" here, then we should remove it from line 89 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@stack72 corrected!

@stack72
Copy link
Contributor

stack72 commented Aug 1, 2016

few small nit picks and then we are good to merge! :)

@stack72 stack72 added the waiting-response An issue/pull request is waiting for a response from the community label Aug 1, 2016
@stack72 stack72 self-assigned this Aug 1, 2016
@stack72 stack72 changed the title [WIP] Add aws_vpn_gateway_attachment resource. Add aws_vpn_gateway_attachment resource. Aug 1, 2016
@stack72
Copy link
Contributor

stack72 commented Aug 1, 2016

Hey @kwilczynski

Thanks for making the changes here - they look good. On a final run of the acceptance tests, I get an error:

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGateway'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGateway -timeout 120m
=== RUN   TestAccAWSVpnGateway_importBasic
--- PASS: TestAccAWSVpnGateway_importBasic (56.88s)
=== RUN   TestAccAWSVpnGatewayAttachment_basic
--- PASS: TestAccAWSVpnGatewayAttachment_basic (90.84s)
=== RUN   TestAccAWSVpnGatewayAttachment_deleted
--- PASS: TestAccAWSVpnGatewayAttachment_deleted (98.34s)
=== RUN   TestAccAWSVpnGateway_basic
--- PASS: TestAccAWSVpnGateway_basic (101.33s)
=== RUN   TestAccAWSVpnGateway_reattach
--- FAIL: TestAccAWSVpnGateway_reattach (69.09s)
    testing.go:264: Step 1 error: Check failed: Check 2/2 error: Expected VPC gateway VPC attachment to be in 'detached' state, but was not: {
          State: "available",
          Type: "ipsec.1",
          VpcAttachments: [{
              State: "attached",
              VpcId: "vpc-6685d602"
            }],
          VpnGatewayId: "vgw-5b06df45"
        }
=== RUN   TestAccAWSVpnGateway_delete
--- PASS: TestAccAWSVpnGateway_delete (78.11s)
=== RUN   TestAccAWSVpnGateway_tags
--- PASS: TestAccAWSVpnGateway_tags (86.17s)
FAIL
exit status 1
FAIL    github.com/hashicorp/terraform/builtin/providers/aws    580.793s
make: *** [testacc] Error 1

@kwilczynski
Copy link
Contributor Author

@stack72 this is a side-effect of setting the vpc_id to be a computed value. It causes the variable when set to empty string (or its zero-value) to be ignored for update, thus the resource is unable to act upon the change.

My recommendation would be to change the re-attachment test, so that it would utilise two VPCs, first attach to the first one, then to the second one, and then back to the first one. Confirmation would: attachment still present with the first VPC and the second VPC attachment state would be detached.

I will get to it shortly.

@kwilczynski kwilczynski force-pushed the feature/resource_aws_vpn_gateway_attachment branch from 25b0e65 to 4277071 Compare August 4, 2016 09:47
@kwilczynski
Copy link
Contributor Author

Updated the test, which is now passing:

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGateway_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/08/04 18:17:20 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGateway_ -timeout 120m
=== RUN   TestAccAWSVpnGateway_importBasic
--- PASS: TestAccAWSVpnGateway_importBasic (54.63s)
=== RUN   TestAccAWSVpnGateway_basic
--- PASS: TestAccAWSVpnGateway_basic (91.75s)
=== RUN   TestAccAWSVpnGateway_reattach
--- PASS: TestAccAWSVpnGateway_reattach (123.66s)
=== RUN   TestAccAWSVpnGateway_delete
--- PASS: TestAccAWSVpnGateway_delete (71.24s)
=== RUN   TestAccAWSVpnGateway_tags
--- PASS: TestAccAWSVpnGateway_tags (77.91s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    419.218s

@kwilczynski
Copy link
Contributor Author

@stack72 over to you 🚀

@kwilczynski kwilczynski force-pushed the feature/resource_aws_vpn_gateway_attachment branch from edfe717 to 2f323ff Compare August 4, 2016 13:12
@kwilczynski
Copy link
Contributor Author

Added new item to do. I want to filter unattached and old VPN attachments, as there is no really a guarantee of any sort that the "attached" state is always under the 0 index in the list in the response.

This commit adds VPN Gateway attachment resource, and also an initial tests and
documentation stubs.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
@kwilczynski kwilczynski force-pushed the feature/resource_aws_vpn_gateway_attachment branch from 2f323ff to e06caa9 Compare August 5, 2016 23:36
@stack72
Copy link
Contributor

stack72 commented Aug 6, 2016

ok this now LGTM!

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGateway_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGateway_ -timeout 120m
=== RUN   TestAccAWSVpnGateway_importBasic
--- PASS: TestAccAWSVpnGateway_importBasic (102.25s)
=== RUN   TestAccAWSVpnGateway_basic
--- PASS: TestAccAWSVpnGateway_basic (141.25s)
=== RUN   TestAccAWSVpnGateway_reattach
--- PASS: TestAccAWSVpnGateway_reattach (213.06s)
=== RUN   TestAccAWSVpnGateway_delete
--- PASS: TestAccAWSVpnGateway_delete (109.62s)
=== RUN   TestAccAWSVpnGateway_tags
--- PASS: TestAccAWSVpnGateway_tags (132.90s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    699.098s
[stacko@Pauls-MBP:~/Code/go/src/github.com/hashicorp/terraform on kwilczynski-feature/resource_aws_vpn_gateway_attachment]
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGatewayAttachment_'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGatewayAttachment_ -timeout 120m
=== RUN   TestAccAWSVpnGatewayAttachment_basic
--- PASS: TestAccAWSVpnGatewayAttachment_basic (102.34s)
=== RUN   TestAccAWSVpnGatewayAttachment_deleted
--- PASS: TestAccAWSVpnGatewayAttachment_deleted (126.40s)
PASS
ok      github.com/hashicorp/terraform/builtin/providers/aws    228.766s

@stack72 stack72 merged commit 9c54e9c into hashicorp:master Aug 6, 2016
@ghost
Copy link

ghost commented Apr 23, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement provider/aws waiting-response An issue/pull request is waiting for a response from the community
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants