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

swtiching from project_services to project_service with for_each crashes terraform #4788

Closed
ideasculptor opened this issue Oct 31, 2019 · 2 comments · Fixed by GoogleCloudPlatform/magic-modules#2942
Assignees

Comments

@ideasculptor
Copy link

Terraform Version

$ terraform --version
Terraform v0.12.12

Terraform Configuration Files

The trigger seems to have been a switch from project_services resource enabling a list of apis to a project_service resource enumerated via for_each. Because the project in question did not have any resources assigned to it, disabling all of the apis in project_services, including compute, succeeded (it fails in the more 'normal' case of a project that has at least one compute dependency within it). When the apis are enabled via the for_each enumeration, it fails because the compute api is no longer enabled. So I manually re-enabled it via the console. But terraform now crashes whenever I run it, whether performing apply or delete, so I cannot even clean house and start over.

Crash Output

https://gist.github.com/ideasculptor/e1f2351e5222eb80af385ecffadbbbfd

Expected Behavior

It should not crash

Actual Behavior

It did crash

Steps to Reproduce

create a project with project_services resource enabling apis. My list was as follows:

[
    "cloudbilling.googleapis.com",
    "cloudresourcemanager.googleapis.com",
    "compute.googleapis.com",
    "container.googleapis.com",
    "iam.googleapis.com",
    "iamcredentials.googleapis.com",
    "logging.googleapis.com",
    "serviceusage.googleapis.com",
    "storage-api.googleapis.com",
  ]

Make sure to destroy the default network and any other resources in the project, so that disabling ALL of those apis will succeed. Then switch to code which use project_service resource and for_each, to perform the same work. Re-apply and run. When it errors out because compute.googleapis.com is no longer enabled, manually re-enable by visiting the URL in the error message. Then re-apply. Terraform will crash.

Additional Context

I'm using terragrunt to wrap terraform, but that isn't a factor. Terraform is being run correctly by terragrunt. The bug doesn't manifest and terraform runs 'correctly' if the apis cannot be disabled due to existing resources conflicting. I just do state rm to remove the un-removable apis and the subsequent apply works just fine. The issue is only if the api removal actually succeeds.

References

terraform-google-modules/terraform-google-project-factory#305

@chrisst
Copy link
Contributor

chrisst commented Jan 8, 2020

@ideasculptor It looks like the panic appears to be happening in code related to the google_project_usage_export_bucket resource and not because of the project services. It looks like export usage was disabled on the project which was causing this resource to crash. I'll have a fix shortly but if you haven't already, re-enabling exports should fix your immediate issue.

@ghost
Copy link

ghost commented Feb 9, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Feb 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants