Skip to content

feat: include coder_parameters from external modules #8195

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 7 commits into from
Jun 26, 2023
Merged
Changes from 1 commit
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
Diff view
Diff view
Next Next commit
Collect parameters from external modules
  • Loading branch information
mtojek committed Jun 26, 2023
commit fad6802663fd8dba66e1f2bc49d2df91e65fa8c3
38 changes: 33 additions & 5 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package terraform

import (
"fmt"
"sort"
"strings"

"github.com/awalterschulze/gographviz"
Expand Down Expand Up @@ -732,11 +733,12 @@ func orderedRichParametersResources(tfResourcesRichParameters []*tfjson.StateRes
}
}

// There's an edge case possible for us to have a parameter name that isn't
// present in the state, since the ordered names come statically from
// parsing the Terraform file. We need to filter out the nil values if there
// are any present.
if len(tfResourcesRichParameters) != len(orderedNames) {
// There's an edge case possible for us to have a parameter name that isn't
// present in the state, since the ordered names come statically from
// parsing the Terraform file. We need to filter out the nil values if there
// are any present.

nonNil := make([]*tfjson.StateResource, 0, len(ordered))
for _, resource := range ordered {
if resource != nil {
Expand All @@ -745,7 +747,33 @@ func orderedRichParametersResources(tfResourcesRichParameters []*tfjson.StateRes
}

ordered = nonNil
}

// Another edge case: a parameter is present in an external module (Git repository, static files, etc.),
// which can't be easily parsed to check the parameter order.
// Those parameters will be prepended to the "ordered" list.
var external []*tfjson.StateResource
for _, resource := range tfResourcesRichParameters {
for _, o := range ordered {
if resource.Name == o.Name {
goto next
}
}

// This is external parameter.
external = append(external, resource)
next:
}

if len(external) > 0 {
sort.Slice(external, func(i, j int) bool {
return external[i].Name < external[j].Name
})

withExternal := make([]*tfjson.StateResource, 0, len(ordered)+len(external))
withExternal = append(withExternal, external...)
withExternal = append(withExternal, ordered...)
ordered = withExternal
}
}
return ordered
}