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

Allow setting folder_id on google_project to "" #1419

Closed
morgante opened this issue May 2, 2018 · 6 comments
Closed

Allow setting folder_id on google_project to "" #1419

morgante opened this issue May 2, 2018 · 6 comments
Labels

Comments

@morgante
Copy link

morgante commented May 2, 2018

Terraform Version

Terraform v0.11.7
+ provider.external v1.0.0
+ provider.google (unversioned)
+ provider.http v1.0.1

Affected Resource(s)

  • google_project

Terraform Configuration Files

locals {
  organization_id = "816421441114"
  folder_id       = ""
}
resource "google_project" "test_project" {
  name       = "My Project"
  project_id = "gcp-fnd-test-project-folder"
  org_id     = "${local.organization_id}"
  folder_id  = "${local.folder_id}"
}

Expected Behavior

Setting folder_id to "" should have the same behavior as leaving it off entirely.

Actual Behavior

The only way to successfully execute this is to leave folder_id off entirely (and create at org level) or leave off org_id (and create at folder level). This has to be hard-coded in the HCL, making variable creation impossible.

The key code is here: https://github.com/terraform-providers/terraform-provider-google/blob/42b07b30e618d3ceabdd6d36f8a13656f137f528/google/resource_google_project.go#L53-L64

Important Factoids

This is critical to being able to dynamically only set the folder ID based on variables or parameters.

@sethvargo
Copy link
Contributor

sethvargo commented May 2, 2018

This is happening because of the use of conflicts_with in the schema, which is doing validation on the presence of keys instead of presence of keys with_values. If we move that validation into the resource-level, this becomes possible at the expense of more code to maintain.

Given the use case (it seems like people would want to use modules and parameterize this as part of a larger "thing"), I think it's a good idea to remove the top-level conflicts_with.

The other downside is that by moving it to resource time, it won't fail during the plan (but will during the apply). Something to consider...

@rosbo
Copy link
Contributor

rosbo commented May 2, 2018

I opened an issue against Terraform core a few months ago about this.

The answer I got was that HCL2 will introduce a proper concept of unset and null.

For more details, here is the issue I opened:
https://github.com/hashicorp/terraform/issues/16575

Given that we would lose plan-time validation, I suggest we wait until HCL2.

What do you think?

@paddycarver paddycarver added the bug label May 2, 2018
@morgante
Copy link
Author

morgante commented May 2, 2018

I'm not convinced that we benefit much from plan-time validation, to be honest. In fact, I would suggest we don't need it at all and could instead switch on a single value (whether folder_id is set or not). I think if folder_id is specified, the desired behavior (being in that folder) is clear, even if org_id is also specified.

This is currently causing a fair amount of pain with some key customers.

@sethvargo
Copy link
Contributor

I tend to agree with @morgante that the trade-off leans toward giving customers power of extensibility in the short term

@rosbo
Copy link
Contributor

rosbo commented May 2, 2018

Alright, you convinced me. I will open a PR soon to fix this.

@ghost
Copy link

ghost commented Nov 18, 2018

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 unassigned rosbo Nov 18, 2018
@ghost ghost locked and limited conversation to collaborators Nov 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants