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

Refreshing a context variable errors if the context is removed #66

Open
RomainBillot opened this issue Dec 13, 2021 · 2 comments
Open

Comments

@RomainBillot
Copy link

RomainBillot commented Dec 13, 2021

Hi 👋 ,

I had a context test, which had one variable password. This context AND the variable were created from terraform.

Later on, I wanted to create the context outside of terraform. It ends up the state looking for a non-existant context_id (even if the name were the same).
In fact, I switched from a resource to a data because the context is finally created outside from terraform.

I had a weird error You don't have permission to list environment variables in this context, but the real underlying error was like if the context_id didn't exist anymore.

Can we make the state refreshing only rely on context name and not on somewhat id?

Workaround: I had to make a terraform state rm circleci_context_environment_variable.password because this variable state refresh failed before.

@RomainBillot RomainBillot changed the title Mutating a context where variables was stored outside from terraform make provider lost Mutating a context that were created in terraform and now outside from terraform make variable state refresh fail Dec 13, 2021
@bendrucker
Copy link
Collaborator

Your suggestion breaks with provider guidelines, IDs should be used wherever available over ambiguous identifiers like names. Terraform resources should not have implicit name matching behavior. Existing resources should be import-ed by ID as needed.

However, it does seem like there's a behavioral change needed here. If the parent context is gone, a variable should be removed from state entirely.

@bendrucker bendrucker changed the title Mutating a context that were created in terraform and now outside from terraform make variable state refresh fail Refreshing a context variable errors if the context is removed Dec 13, 2021
@bendrucker
Copy link
Collaborator

Couple of small issues were present leading to this bug, see #67.

As for the fact that the returned error is "you don't have permission" rather than "context not found," that's because Circle has mis-implemented this. Applications should generally return 404 when the user doesn't have access to a resource to avoid disclosing its existence. Instead Circle returns a 403, always. #67 adds that to the HTTP client so that 403 is treated as an expected error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants