Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

using workspace_id #293

Merged
merged 1 commit into from
Feb 11, 2020
Merged

Conversation

JoseD92
Copy link
Contributor

@JoseD92 JoseD92 commented Feb 10, 2020

Changes tf-cloud-credential so that it receives the workspace_id as an argument instead of searching it with a datasource, because the datasource brings problems when the workspace does not exists

@JoseD92 JoseD92 requested a review from mcgirr February 10, 2020 19:39
@JoseD92
Copy link
Contributor Author

JoseD92 commented Feb 10, 2020

The error for this PR happens when using this module and the code for making the tf workspace to which the module will add the variables to are within the same tf project. This is because the module uses a datasource to get the id of the workspace, but datasources only work on existing resources so both can't be add to the project simultaneously. Resulting in errors like:

Error: Could not find workspace My-Project/project_workspace

  on modules/tf-cloud-credential/data.tf line 1, in data "tfe_workspace" "workspace":
   1: data "tfe_workspace" "workspace" {

with the additions of this PR the plan is successful as it uses the id of the new workspace directly, creating the workspace and variables:

  # module.workspace.tfe_workspace will be created
  + resource "tfe_workspace" "tfe_workspace" {
      + auto_apply            = false
      + external_id           = (known after apply)
      + file_triggers_enabled = true
      + id                    = (known after apply)
      + name                  = "myproject"
      + operations            = true
      + organization          = "myproject"
      + queue_all_runs        = true
      + ssh_key_id            = "***"
      + terraform_version     = "0.12.20"
      + working_directory     = "terraform/myproject"
    }

  # module.myproject.tfe_variable.workspace_aws_access_key_id will be created
  + resource "tfe_variable" "workspace_aws_access_key_id" {
      + category     = "env"
      + hcl          = false
      + id           = (known after apply)
      + key          = "AWS_ACCESS_KEY_ID"
      + sensitive    = true
      + value        = (sensitive value)
      + workspace_id = (known after apply)
    }

  # module.myproject.tfe_variable.workspace_aws_default_region will be created
  + resource "tfe_variable" "workspace_aws_default_region" {
      + category     = "env"
      + hcl          = false
      + id           = (known after apply)
      + key          = "AWS_DEFAULT_REGION"
      + sensitive    = false
      + value        = (sensitive value)
      + workspace_id = (known after apply)
    }

  # module.myproject.tfe_variable.workspace_aws_secret_access_key_id will be created
  + resource "tfe_variable" "workspace_aws_secret_access_key_id" {
      + category     = "env"
      + hcl          = false
      + id           = (known after apply)
      + key          = "AWS_SECRET_ACCESS_KEY"
      + sensitive    = true
      + value        = (sensitive value)
      + workspace_id = (known after apply)
    }

@mcgirr
Copy link
Contributor

mcgirr commented Feb 11, 2020

Thanks for this PR @JoseD92 I will review it and get it merged

@mcgirr mcgirr merged commit 61f66ba into master Feb 11, 2020
@mcgirr
Copy link
Contributor

mcgirr commented Feb 12, 2020

This looks good to me. Thanks! Let's not remote the MR branch just yet until all the places that use it have been updated.

@ketzacoatl ketzacoatl deleted the use-workspace_id-on-tf-cloud-credentials branch February 14, 2020 19:27
Magicloud pushed a commit that referenced this pull request Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants