hashicorp / terraform-provider-tfe

Official HCP Terraform and Terraform Enterprise provider, maintained by HashiCorp. Provision HCP Terraform or Terraform Enterprise - with Terraform!
https://registry.terraform.io/providers/hashicorp/tfe
Mozilla Public License 2.0
159 stars 151 forks source link

Circular dependency in `tfe_workspace` using execution_mode=agent and `tfe_agent_pool_allowed_workspaces` #1111

Open megrehncitrix opened 8 months ago

megrehncitrix commented 8 months ago

Terraform Cloud/Enterprise version

Terraform Cloud

Terraform version

1.3.4

Terraform Configuration Files

resource "tfe_workspace" "example-workspace" {
  name               = "example"
  organization       = "example-org"
  allow_destroy_plan = false
  agent_pool_id      = tfe_agent_pool.org-agent-pool.id
  execution_mode     = "agent"
}

resource "tfe_agent_pool_allowed_workspaces" "example-agent-pool-scope" {
  agent_pool_id         = tfe_agent_pool.org-agent-pool.id
  allowed_workspace_ids = [tfe_workspace.example-workspace.id]
}

Debug Output

╷
│ Error: Error creating workspace example-workspace for organization example-org: invalid attribute
│ 
│ Agent pool workspace does not have access to use this agent pool
│ 
│   with tfe_workspace.example-workspace,
│   on workspaces.tf line 15, in resource "tfe_workspace" "example-workspace":
│   15: resource "tfe_workspace" "example-workspace" {

Expected Behavior

The workspace should be created with the intended agent pool as its execution mode.

Actual Behavior

Workspace cannot be created and configured accordingly. Agent pool id is required if execution_mode is set to agent.

Additional Context

Seen during new workspace creation. The desire in this configuration it to create and control which workspaces have access to which agent pools.

Possible solution: allow tfe_workspace to configure allowed workspaces for the target agent pool id if the caller has appropriate permissions.

zeidlerb commented 3 months ago

I think is issue has been effectively resolved with the introduction of tfe_workspace_settings in version 0.51.0. The execution mode can now be set after the workspace has been created and the pool has been assigned.

I vote to close this issue.