8000 fix: Parse resources from Terraform Modules by kylecarbs · Pull Request #1501 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

fix: Parse resources from Terraform Modules #1501

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

Merged
merged 1 commit into from
May 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
10000
Diff view
Diff view
fix: Parse resources from Terraform Modules
Fixes when Terraform modules are used to primariy provision
infrastructure!
  • Loading branch information
kylecarbs committed May 17, 2022
commit 2803f845b8bf3bb245c40e2e52343714c4497e42
28 changes: 23 additions & 5 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,17 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
resources := make([]*proto.Resource, 0)
agents := map[string]*proto.Agent{}

tfResources := plan.Config.RootModule.Resources
var appendResources func(mod *tfjson.ConfigModule)
appendResources = func(mod *tfjson.ConfigModule) {
for _, module := range mod.ModuleCalls {
appendResources(module.Module)
}
tfResources = append(tfResources, mod.Resources...)
}

// Store all agents inside the maps!
for _, resource := range plan.Config.RootModule.Resources {
for _, resource := range tfResources {
if resource.Type != "coder_agent" {
continue
}
Expand Down Expand Up @@ -340,7 +349,7 @@ func parseTerraformPlan(ctx context.Context, terraform *tfexec.Terraform, planfi
agents[resource.Address] = agent
}

for _, resource := range plan.PlannedValues.RootModule.Resources {
for _, resource := range tfResources {
if resource.Mode == tfjson.DataResourceMode {
continue
}
Expand Down Expand Up @@ -407,8 +416,17 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
}
agents := map[string]*proto.Agent{}

tfResources := state.Values.RootModule.Resources
var appendResources func(resource *tfjson.StateModule)
appendResources = func(mod *tfjson.StateModule) {
for _, module := range mod.ChildModules {
appendResources(module)
}
tfResources = append(tfResources, mod.Resources...)
}

// Store all agents inside the maps!
for _, resource := range state.Values.RootModule.Resources {
for _, resource := range tfResources {
if resource.Type != "coder_agent" {
continue
}
Expand Down Expand Up @@ -439,7 +457,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
}

// Manually associate agents with instance IDs.
for _, resource := range state.Values.RootModule.Resources {
for _, resource := range tfResources {
if resource.Type != "coder_agent_instance" {
continue
}
Expand Down Expand Up @@ -471,7 +489,7 @@ func parseTerraformApply(ctx context.Context, terraform *tfexec.Terraform, state
}
}

for _, resource := range state.Values.RootModule.Resources {
for _, resource := range tfResources {
if resource.Mode == tfjson.DataResourceMode {
continue
}
Expand Down
0