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

availability_zone getting cleared on aws vpn gateway in statefile #4752

Closed
qgriffith-zz opened this issue Jan 19, 2016 · 2 comments · Fixed by #8645
Closed

availability_zone getting cleared on aws vpn gateway in statefile #4752

qgriffith-zz opened this issue Jan 19, 2016 · 2 comments · Fixed by #8645

Comments

@qgriffith-zz
Copy link

Using terraform 0.6.9 the availability_zone is getting cleared from the state file and terraform is trying to re-create the vpn becasue the state file contains a blank availability_zone when the vpn has a availability_zone attached to it. When manually editing the state file to put the availability_zone back, the next plan will clear the availability_zone and try to re-build the vpn.

State file

               "aws_vpn_gateway.vpn_gateway": {
                    "type": "aws_vpn_gateway",
                    "depends_on": [
                        "aws_vpc.main"
                    ],
                    "primary": {
                        "id": "vgw-xxxx",
                        "attributes": {
                            "availability_zone": "",
                            "id": "vgw-xxxx",
                            "tags.#": "1",
                            "tags.Name": "xxx",
                            "vpc_id": "vpc-xxx"
                        }
                    }
                }
            }
        },

We are setting the avalability_zone on the resource config for the vpn. The root cause could be that AWS API may not be returning the avalabilty_zone and terafform is blanking it out. Instead if AWS returns a blank value the current value should be kept.

resource "aws_vpn_gateway" "vpn_gateway" {
    vpc_id = "${aws_vpc.main.id}"
    availability_zone = "us-west-2a"

    tags {
        Name = "vpn-us-west-2"
    }
}
stack72 added a commit that referenced this issue Sep 3, 2016
availability zone

Fixes #4752

According to the AWS Documentation, when `describing-vpn-gateways`

```
AvailabilityZone -> (string)
The Availability Zone where the virtual private gateway was created, if applicable. This field may be empty or not returned.
```

Therefore, if we pass an availability zone as part of vpn gateway, then it may come back as an empty string. If we set this empty string back to state, then the next plan will look as follows:

```
-/+ aws_vpn_gateway.vpn_gateway
    availability_zone: "" => "us-west-2a" (forces new resource)
    tags.%:            "1" => "1"
    tags.Name:         "vpn-us-west-2" => "vpn-us-west-2"
    vpc_id:            "vpc-1e9da47a" => "vpc-1e9da47a"

Plan: 1 to add, 0 to change, 1 to destroy.
```

If the availability_zone comes back from AWS as an empty string, then we should not set it to state to avoid forcing a new resource for the user

```
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGateway_withAvailabilityZoneSetToState'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/03 17:10:57 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGateway_withAvailabilityZoneSetToState -timeout 120m
=== RUN   TestAccAWSVpnGateway_withAvailabilityZoneSetToState
--- FAIL: TestAccAWSVpnGateway_withAvailabilityZoneSetToState (36.11s)
       	testing.go:265: Step 0 error: Check failed: Check 2/2 error: aws_vpn_gateway.foo: Attribute 'availability_zone' expected "us-west-2a", got ""
FAIL
exit status 1
FAIL   	github.com/hashicorp/terraform/builtin/providers/aws   	36.130s
make: *** [testacc] Error 1
[stacko@Pauls-MacBook-Pro:~/Code/go/src/github.com/hashicorp/terraform on master]
% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSVpnGateway_withAvailabilityZoneSetToState'                                                                                       2 ↵ ✹
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2016/09/03 17:12:25 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSVpnGateway_withAvailabilityZoneSetToState -timeout 120m
=== RUN   TestAccAWSVpnGateway_withAvailabilityZoneSetToState
--- PASS: TestAccAWSVpnGateway_withAvailabilityZoneSetToState (46.50s)
PASS
ok     	github.com/hashicorp/terraform/builtin/providers/aws   	46.517s
```
@stack72
Copy link
Contributor

stack72 commented Sep 3, 2016

Hi @qgriffith

Apologies for the issue here and how long it has taken to get this worked on. I have just opened PR #8645 to solve the issue

Paul

@ghost
Copy link

ghost commented Apr 22, 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 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants