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

provider/aws: Fix issue upgrading to Terraform v0.9+ with AWS OpsWorks Stacks #13024

Merged
merged 1 commit into from
Mar 28, 2017

Conversation

catsby
Copy link
Contributor

@catsby catsby commented Mar 23, 2017

Fix an issue when upgrading from Terraform < 0.9 to 0.9+, when we added
support for the regional endpoints in OpsWorks Stacks. OpsWorks Stacks
can only be managed via the endpoint with which they were created, not
where the stack resides:

Stacks can only be accessed or managed within the endpoint in which they are created

Prior to #12688, all OpsWorks stacks were created via us-east-1 endpoint, which was the only way to create them until very recent. Amazon has since added regional endpoints, and deprecated the approach of all-stacks-go-thru-us-east.

When we removed the default of us-east-1 in Terraform v0.9.0, any opsworks_stack resources created in a version of Terraform < 0.9 began querying the API with whatever region the Provider had been configured, not necessarily us-east-1, the region they were created with.

Any user in this situation would be presented with Terraform trying to create a new opsworks stack, because it was unable to find it due to the region diff. See #12842 .

Here, we add a stack_endpoint computed attribute, where we'll store the region in which the stack is found. On the next UPDATE or REFRESH action, Terraform will attempt to find the stack in the default Provider region. If not found, it will attempt to find it in us-east-1. If it's found in east, we'll save that as the stack_endpoint.

Future UPDATE, REFRESH, and DELETE operations will check this computed attribute and get the connection needed, if the stack_endpoint is found.

The acceptance test TestAccAWSOpsWorksStack_classic_endpoints should cover this. It first creates a stack in us-east-1, using us-east-1 region. In the second step, we switch to us-west-2 and preform a plan-only check of the configuration. Without the ability to check us-east-1 after checking the updated Provider region, this test step would fail to find the stack created and offer to create it, failing the step because it produces a non-empty plan.

Fix an issue when upgrading from Terraform < 0.9 to 0.9+, when we added
support for the regional endpoints in OpsWorks Stacks. OpsWorks Stacks
can only be managed via the endpoint with which they were created, not
where the stack resides.
@catsby catsby changed the title provider/aws: Add failing test for OpsWorks endpoints provider/aws: Fix issue upgrading to Terraform v0.9+ with AWS OpsWorks Stacks Mar 23, 2017
@stack72
Copy link
Contributor

stack72 commented Mar 28, 2017

LGTM! Thanks for the fix :)

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSOpsWorksStack_'                ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/03/28 12:24:47 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSOpsWorksStack_ -timeout 120m
=== RUN   TestAccAWSOpsWorksStack_classic_endpoints
--- PASS: TestAccAWSOpsWorksStack_classic_endpoints (45.10s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	45.121s```

@stack72 stack72 merged commit dd25334 into master Mar 28, 2017
@stack72 stack72 deleted the b-opsworks-endpoints branch March 28, 2017 09:29
ryon pushed a commit to ryon/terraform that referenced this pull request Mar 29, 2017
Fix an issue when upgrading from Terraform < 0.9 to 0.9+, when we added
support for the regional endpoints in OpsWorks Stacks. OpsWorks Stacks
can only be managed via the endpoint with which they were created, not
where the stack resides.
@GuiSim
Copy link
Contributor

GuiSim commented Apr 6, 2017

I'm facing this issue right now! Thanks for the fix.
How can I know which version of Terraform has this fix? I'm running on 0.9.2.

If this fix is in 0.9.2, I might have a closely related issue that affects module.phobos.aws_opsworks_custom_layer and aws_opsworks_instance. It appears that Terraform can't see layers and instances created with classic endpoint using a version of Terraform older than 0.9. It will attempt to recreate them and fail.

Let me know if you'd like me to fill a new issue or if this is supposed to be fixed by this @catsby !

Thanks!

@catsby
Copy link
Contributor Author

catsby commented Apr 6, 2017

This fix should apply to opsworks_stacks only. In my research that was the only resource that had this limitation, according to the docs I read:

Stacks can only be accessed or managed within the endpoint in which they are created

It's entirely possible things that belong to this stack also have that limitation? If you discover this is the case, please open a new GitHub issue.

Thanks!

@rafaelmagu
Copy link

For the record, this does not fix the problem with existing stacks. It continues to think my stack doesn't exist, but won't allow me to import saying that the stack already exists.

@GuiSim
Copy link
Contributor

GuiSim commented Apr 6, 2017

Judging by @rafaelmagu 's last comment, I think that #12842 is not resolved and should be reopened.

@nabeken
Copy link
Contributor

nabeken commented Apr 8, 2017

@catsby I think Stacks is just used to clarify since they have another AWS OpsWorks for Chef Automate so Stacks does not mean a stack in OpsWorks Stacks.

Actually, All API requests should go to regional endpoint, which means all TF opsworks resources should contact to it.

@nabeken
Copy link
Contributor

nabeken commented Apr 8, 2017

@catsby Filed an issue #13483

bflad added a commit to hashicorp/terraform-provider-aws that referenced this pull request Sep 25, 2019
… to real Terraform version

Reference: hashicorp/terraform#13024
Reference: #9570

This migration is required for migrating to the standalone Terraform Plugin SDK and removing our dependency on github.com/hashicorp/terraform in the future.

Output from acceptance testing:

```
--- PASS: TestAccAWSOpsWorksStack_classic_endpoints (28.89s)
```

User-Agent from testing above:

```
User-Agent: aws-sdk-go/1.24.4 (go1.13; darwin; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.12.7
```
@ghost
Copy link

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

Successfully merging this pull request may close these issues.

5 participants