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

Add provider config organization, making all resource organization fields optional #762

Conversation

brandonc
Copy link
Collaborator

@brandonc brandonc commented Jan 11, 2023

Description

Drawing inspiration from the google provider, this adds a new provider config field organization which could make all the resource-specific organization fields optional if defined. Please review commit-wise

Testing plan

My testing methodology was making sure that config can be refactored from resource-specific org to default org with no infrastructure changes and vice-versa.

Example Config

The config contains all the resources that previously required an organization field:

provider "tfe" {
  hostname = "..."
  token = "..."
  organization = "hashicorp"
}

variable "gh_token" {
  type = string
}

variable "ssh_key" {
  type = string
}

resource "tfe_workspace" "foo" {
  name = "foo"
}

resource "tfe_variable_set" "foo" {
  name          = "Test Varset"
  description   = "Some description."
}

resource "tfe_workspace_variable_set" "foo" {
  workspace_id    = tfe_workspace.foo.id
  variable_set_id = tfe_variable_set.foo.id
}

resource "tfe_variable" "test-a" {
  key             = "seperate_variable"
  value           = "my_value_name"
  category        = "terraform"
  description     = "a useful description"
  variable_set_id = tfe_variable_set.foo.id
}

resource "tfe_agent_pool" "foo" {
  name         = "my-agent-pool-name"
}

resource "tfe_oauth_client" "foo" {
  name             = "my-github-oauth-client"
  api_url          = "https://api.github.com"
  http_url         = "https://github.com"
  oauth_token      = var.gh_token
  service_provider = "github"
}

resource "tfe_organization_membership" "test1" {
  email = "example1@company.com"
}

resource "tfe_organization_membership" "test2" {
  email = "example2@company.com"
}

resource "tfe_organization_token" "test" {
  force_regenerate = true
}

resource "tfe_policy" "test" {
  name         = "my-policy-name"
  description  = "This policy always passes"
  kind         = "sentinel"
  policy       = "main = rule { true }"
  enforce_mode = "hard-mandatory"
}

resource "tfe_policy_set" "test" {
  name          = "my-policy-set"
  description   = "A brand new policy set"
  kind          = "sentinel"
  policy_ids    = [tfe_policy.test.id]
  workspace_ids = [tfe_workspace.foo.id]
}

resource "tfe_project" "test" {
  name = "projectname"
}

resource "tfe_ssh_key" "test" {
  name         = "my-ssh-key-name"
  key          = var.ssh_key
}

resource "tfe_team" "test" {
  name         = "my-team-name"
}

data "tfe_agent_pool" "test" {
  name          = "my-agent-pool-name"
}

output "agent-pool" {
  value = data.tfe_agent_pool.test.id
}

External links

Closes #434

@brandonc brandonc requested a review from a team as a code owner January 11, 2023 01:18
@brandonc brandonc force-pushed the TF-3541-add-provider-config-default-organization-that-could-apply-to-all-resources branch 6 times, most recently from c583b5b to 91d1528 Compare January 13, 2023 23:45
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I was able to smoke test the default org 🎉

One comment, It might be helpful to indicate on the doc that when using default_organization, the organization must already exist, unlike when an org is specified with a resource block. Consequently, the organization must be a literal and cannot be resource/datasource instance like resource.tfe_organization.test-org.name.

@brandonc brandonc changed the title Add provider config default_organization Add provider config organization, making all resource organization fields optional Jan 18, 2023
@brandonc brandonc force-pushed the TF-3541-add-provider-config-default-organization-that-could-apply-to-all-resources branch from 721bc66 to 391446f Compare January 18, 2023 22:20
@brandonc
Copy link
Collaborator Author

@Uk1288 I fixed a bug in the tfe_outputs data source and added alternative configuration using TFE_ORGANIZATION environment variable.

@brandonc brandonc force-pushed the TF-3541-add-provider-config-default-organization-that-could-apply-to-all-resources branch from 391446f to 47f8003 Compare January 18, 2023 23:44
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

@brandonc brandonc merged commit 5f1e78c into main Jan 19, 2023
@brandonc brandonc deleted the TF-3541-add-provider-config-default-organization-that-could-apply-to-all-resources branch January 19, 2023 16:22
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 this pull request may close these issues.

default value for organization field
2 participants