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

default value for organization field #434

Closed
ctrlok opened this issue Feb 12, 2022 · 7 comments · Fixed by #762
Closed

default value for organization field #434

ctrlok opened this issue Feb 12, 2022 · 7 comments · Fixed by #762

Comments

@ctrlok
Copy link

ctrlok commented Feb 12, 2022

Hello. Great work on supporting TFE plugin.

I want to propose to set the default value for the organization field in multiple resources.

Now I set the global variable org_name for all workspaces, but I need to declare this variable in each tf repo and then teach developers to use it (in keys they want to use tfe_outputs or other things).

And I can't see any reason, why it can't have a default value - current organization name.

@brandonc
Copy link
Collaborator

brandonc commented Dec 23, 2022

Thanks for this request. I agree that this could be convenient, especially in the popular case of having only one organization. I worry, though, about the possibility of applying changes to the wrong organization unintentionally with Terraform Enterprise users in particular, and users being confused by the type of error message (usually 404) that would be returned from the API for incorrect cross-org relationships.

One way to overcome this burden is to wrap your tfe resources in a module that accepts an organization variable, then use that variable in all other resources. Would your config support that?

Example

main.tf

module "tfe_team1" {
  source "./team1"
  organization = "foo"
}

team1/variables.tf

variable "organization" {
  type = string
}

team1/main.tf

resource "tfe_workspace" "ws" {
  organization = var.organization
  ...
}

@brandonc
Copy link
Collaborator

I am going to leave this open as a feature request, but I'd still be interested in hearing your thoughts.

@ctrlok
Copy link
Author

ctrlok commented Dec 27, 2022

Hi! Thanks for the reply!

I fixed my problem with using data.tfe_organization.default.name or local.org_name or variable from variable_set shared between all workflows var.org_name

My developers use terraform almost without involving the platform team, so the solution you provided makes no difference, while it requires creating modules and pass variables to the modules.

The main idea is that probably all other providers (aws, google) can set org_name/account_name/etc based on the org name specified in the provider definition.

@brandonc
Copy link
Collaborator

I'm convinced after looking through GCP's provider project config. Thanks for the additional details.

@rhughes1
Copy link
Contributor

@brandonc Would it be valuable as well to be able to set this up as an environment variable like the TFE/TFC token? ie TFE_ORGANIZATION?

@brandonc
Copy link
Collaborator

@rhughes1 Yes, that seems reasonable, too. Added it to #762.

@ctrlok
Copy link
Author

ctrlok commented Jan 24, 2023

@brandonc Thanks! It will help a lot!

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