-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Creating GCP project in terraform #13109
Comments
Hey @stratog, thanks for reporting. I took a look at your config and I think I know what's going on. Let's pull these two resources out:
In this section, the project is created using the
Getting these throughout your config will likely solve a lot of the errors you've been seeing. Try that out and let me know how it goes! |
Thanks @danawillow. I found that step and it helped a bit. A challenge I've found around the services, turning on one API will trigger another to be enabled and sometimes we won't have permission to add/disable the api and any step dependent on gets affected. Also, in another project, I am finding that the compute api services get removed and that caused a lot of issues with creating/deleting resources that we observed above. Overall, I found it easier to import a project with a few resources created and managed vs creating a new project from scratch. |
Sorry to hear you're still having issues. It sounds like that first one is covered by #13004. Feel free to file issues for any of the other problems you're seeing as well. In the meantime, is there anything else I can help with for this issue or should we call it solved? |
Sure, that seems like the next root cause of creating a project from scratch. |
Cool cool. I'm going to go ahead and close this issue then. |
@danawillow I'm seeing similar issues without even managing the What I do is to create a new gcloud project manually through the cloud console and then enable all required APIs using Unfortunately I'm unable to provision my setup in one single terraform run since terraform seems to try to provision some resources whose APIs have not yet been enabled (even though they are listed in the On the first run I get errors like:
Repeating Is there actually any notion of dependency between |
Hey @ctavan, I don't think there's anything we can do about that code-wise since the automatic dependency generation relies on referencing a resource from another, which isn't possible in this case. Luckily, there's a configuration parameter that exists for use cases like this: https://www.terraform.io/docs/configuration/resources.html#explicit-dependencies. Adding |
Hey @danawillow, thanks for your quick feedback and for the hint about
Also for resources there's a problem during the initial run:
So looks like However I think I might have found a different viable workaround: Since most (if not all) of the Google resources accept an optional I was wondering if referring to static, non-computed attributes like Anyways, here's an example of what appears to work well for me: resource "google_project_services" "main" {
project = "my-project"
services = [
"bigquery-json.googleapis.com",
"cloudapis.googleapis.com",
"cloudtrace.googleapis.com",
"compute-component.googleapis.com",
"container.googleapis.com",
"dataflow.googleapis.com",
"logging.googleapis.com",
"monitoring.googleapis.com",
"pubsub.googleapis.com",
"sqladmin.googleapis.com"
]
}
resource "google_storage_bucket" "static" {
name = "my-bucket-name"
project = "${google_project_services.main.project}"
location = "US"
} |
Oh, great idea! Your intuition is correct- that does create the dependency. If you're ever curious again about the dependency graph that terraform creates, you can try using |
Yeah we're a bit past my area of expertise but I'm sure someone on the internet has a good answer for you :) |
Hi everyone, I'm facing the same issue I think...here are the output of my "terraform apply" Error: Error applying plan: 1 error(s) occurred:
Terraform does not automatically rollback in the face of errors. And these are my files: main.tf: root@lwayslearning:/home/tadeu/terraform# cat main.tf root@lwayslearning:/home/tadeu/terraform# cat instances.tf
} I dont know what else should I do! :( Any help will be appreciate!! Tks!!! |
@tadeuuuuu Check to see if you've modified your compute service account:
I ran into this issue when I set IAM permissions, removing anything that was preset, and replaced it with just the handful of permissions that I had set explicitly in terraform. |
Yup, @tadeuuuuu I would just double check the permissions you have granted to whatever service account you're using for credentials. A good strategy I like for debugging this sort of thing is to try to accomplish whatever it is you're trying to do in gcloud using the same service account- if you get the same error, then you know that terraform isn't the issue. |
Hello! Please help me with the following issue:
I have tried to use terraform for GCP's modules, however - It's my first time with this cloud and I can't understand which actions I did wrong. I can't create any resources..... Thanks. |
I am also facing similar issues at the time of applying the plan. |
Hey @rahulkp220, I'd recommend double-checking the permissions on the account you're using to run Terraform. |
@danawillow Thanks, but I have given the permission of Can you tell me the roles I should give to my |
That should be fine. Have you tried using that same service account with gcloud to read compute zones? (https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account). There's also very little debugging we can really do with just an error message, unfortunately. If you'd like to open a new issue and fill out the full template there, that would be a big help in debugging. But try the gcloud thing first :) |
Hmm, so there are two accounts to start with. Right now, I have my first account sitting inside the gcloud configs.(the one that I used with
But for automation, I am using |
@danawillow Ohkay, I did authenticate the account by using,
and tried to list the zones. I fell into the following errors.
|
Right, so that seems like something that you need to work out the correct IAM permissions for. If the account doesn't have permissions in gcloud, then it won't have them in Terraform either. |
I'm having a similar issue. I have a Terraform file that does nothing except enable APIs that I'm running against a project with no APIs enabled. The credentials.json file is a JSON file from a service account that's a Project Owner. There shouldn't be any race conditions, since the only thing the terraform file does it enable APIs. This is what happens when I run terraform apply:
|
Here's the code:
|
@danawillow Found another aspect of this issue today, the project name/id; example:
This is a GCP error AND it errors (somewhat?) incorrectly; here's some testing:
In this case
The Google docs give no indication that there are rules for However, at least in this limited circumstance, there seem to be rules when terraforming. I can't find these rules anywhere. Hope this helps 😄 |
Hi @todd-dsm, this is a pretty old, closed issue. If you have a new bug to report please fill out the full template in the google provider issue tracker: https://github.com/terraform-providers/terraform-provider-google/issues. |
Hi team, I'm trying to create google host and service project from scratch but whenever I try to do terraform apply more then once it deletes my project created with same name and recreates but then it gives project already exists and google removes that projects after 30 days. Kindly help how can I resolve the problem tried using data source but of no use. |
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. |
I'm having issues creating a GCP project from scratch using terraform. The order of operations seems off. I have to rerun apply several times as terraform gets stuck waiting for the project to get created, apis to initialize, networks get get created, and finally after everything else is created, I get permission issues when a GKE cluster even as project owner.
Terraform Version
Terraform v0.9.1
Affected Resource(s)
Please list the resources as a list, for example:
If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.
Terraform Configuration Files
config
tfstate
Debug Output
debug
Expected Behavior
Actual Behavior
What actually happened?
Errors occur when creating resources that are depending on another resource that terraform is in the process of creating.
google_container_cluster.asia-northeast1-std-m: googleapi: Error 403: Google Compute Engine: Required 'compute.zones.get' permission for 'projects/terraform-test-nonprod/zones/asia-northeast1-a', forbidden
Creating a project from scratch seems to be missing certain permissions. I've done with the google_container_cluster resource with a service account and with local exec with my own credentials. Both are project owners and compute admins among many many other roles that should have access. I have a feeling that because the apis were not ready when it tried to create these resources, it may have partially corrupted the IAM policies.
Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
not found and cannot be used for API calls., accessNotConfigured
not fully initialized with the default service accounts. Please try again later., backendError
resource was not found, notFound
Error 403: Google Compute Engine: Required 'compute.zones.get' permission for 'projects/terraform-test-nonprod/zones/asia-northeast1-a', forbidden
The text was updated successfully, but these errors were encountered: