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

Creating New Workspaces with GitHub App Installation Fails #1073

Open
naftulikay opened this issue Sep 22, 2023 · 0 comments
Open

Creating New Workspaces with GitHub App Installation Fails #1073

naftulikay opened this issue Sep 22, 2023 · 0 comments
Labels

Comments

@naftulikay
Copy link

It appears that #854 is not fixed with the latest provider version. I cannot create new workspaces, but I can import/modify existing workspaces, even though all workspaces operate in the same GitHub repository.

Terraform Cloud/Enterprise version

Terraform Cloud

Terraform version

v1.5.7

Terraform Configuration Files

As background:

  1. I created a new Terraform Cloud organization.
  2. I setup the GitHub app installation.
  3. I created an organization token.
  4. I created a variable set called "Terraform Cloud" which contains the environment variable TFE_TOKEN which contains the organization token.
  5. I created the appropriate Terraform Cloud projects.
  6. I created the following workspace "my-org-terraform-cloud" in the web console using a GitHub repository as a source.
  7. I created other workspaces in the web console, and these work just fine after importing them using import {} blocks. I can modify them using the tfe provider without any issues.
  8. I imported the Terraform Cloud projects.
  9. I used the Terraform Cloud REST API to get the GitHub app installation id from the projects in this organization which work.
  10. I modified my workspaces variable such that new workspaces would be set up.
  11. Creation of new workspaces using tfe_workspace fails.
locals {
  github_org_name = "my-org"
  github_repo_name = "terraform"
  git_default_branch = "my-branch"
  tfcloud_org_name = "my-org"
}

variable projects {
  type = set(string)
  default = ["my-project"]
}

resource tfe_project default {
  for_each = var.projects

  name = each.value
  organization = local.tfcloud_org_name

  lifecycle {
    prevent_destroy = true
  }
}

variable workspaces {
    default = {
        "existing-workspace-name" = {
            "project" = "project-name"
        }
        "new-workspace-name" = {
            "project" = "project-name"
        }
    }
}

variable tfcloud_github_app_installation_id {
  default = "ghain-XXXXXX"
}

resource tfe_workspace default {
  for_each = var.workspaces

  name = each.key
  project_id = tfe_project.default[each.value["project"]].id
  organization = local.tfcloud_org_name
  working_directory = "workspaces/${each.key}"
  trigger_prefixes = distinct(["/workspaces/${each.key}"])

  vcs_repo {
    identifier = "${local.github_org_name}/${local.github_repo_name}"
    github_app_installation_id = var.tfcloud_github_app_installation_id
    branch = local.git_default_branch
  }

  force_delete = false
  allow_destroy_plan = false

  lifecycle {
    prevent_destroy = true
  }
}

Expected Behavior

I expect that the tfe provider will be able to create new Terraform Cloud workspaces using the tfe_workspace resource.

Actual Behavior

It fails with the following message:

 Error creating workspace new-workspace-name for organization my-org: invalid attribute Repository doesn't exist or isn't accessible

Once again:

  1. The GitHub app installation ID is the same as is used by the existing workspaces.
  2. The GitHub repository being used for all Terraform Cloud workspaces is exactly the same for all workspaces.
  3. Modifying Terraform Cloud workspaces which already exists works fine ✔️ but creation of new workspaces fails

Additional Context

Other than mentioned above, there is nothing special about my setup. The code that I have above functions when working on Terraform Cloud GitHub workspaces in my personal GitHub namespace (naftulikay) but does not work for workspaces within the org that I am working in.

@naftulikay naftulikay added the bug label Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant