Files
coder/provisioner/terraform/testdata/resources/devcontainer-multiple-agents/devcontainer-multiple-agents.tf
T
Danielle Maywood 1a94aa67a3 feat(provisioner): associate resources with coder_devcontainer (#21602)
Closes https://github.com/coder/internal/issues/1239

Allow associating `coder_env`, `coder_script` and `coder_app` with
`coder_devcontainer` resource. To do this we make use of the newly added
`subagent_id` field in the `coder_devcontainer` resource added in
https://github.com/coder/terraform-provider-coder/pull/474
2026-01-29 00:01:30 +00:00

55 lines
1.3 KiB
Terraform

terraform {
required_providers {
coder = {
source = "coder/coder"
version = ">=2.0.0"
}
}
}
# Two agents, but the devcontainer only depends on one.
# This tests the continue path when iterating agents for devcontainer association.
resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
}
resource "coder_agent" "secondary" {
os = "linux"
arch = "amd64"
}
# This devcontainer only depends on the main agent.
resource "coder_devcontainer" "dev" {
agent_id = coder_agent.main.id
workspace_folder = "/workspace"
}
# A second devcontainer that also depends on main agent.
# This allows us to test the dependsOnDevcontainer returning false
# when checking if an app belongs to this devcontainer vs dev.
resource "coder_devcontainer" "other" {
agent_id = coder_agent.main.id
workspace_folder = "/other"
}
# This app depends on "dev" devcontainer, not "other".
# When iterating devcontainers, dependsOnDevcontainer should return
# false for "other" and true for "dev".
resource "coder_app" "devcontainer-app" {
agent_id = coder_devcontainer.dev.subagent_id
slug = "devcontainer-app"
}
resource "null_resource" "dev" {
depends_on = [
coder_agent.main
]
}
resource "null_resource" "secondary" {
depends_on = [
coder_agent.secondary
]
}