-
Notifications
You must be signed in to change notification settings - Fork 885
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
Changes from 6 commits
fad6802
a298e71
637e19e
b882d8f
18683ec
8da4b59
5e61b94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ package terraform | |||||||||||
|
||||||||||||
import ( | ||||||||||||
"fmt" | ||||||||||||
"sort" | ||||||||||||
"strings" | ||||||||||||
|
||||||||||||
"github.com/awalterschulze/gographviz" | ||||||||||||
|
@@ -723,29 +724,40 @@ func orderedRichParametersResources(tfResourcesRichParameters []*tfjson.StateRes | |||||||||||
return tfResourcesRichParameters | ||||||||||||
} | ||||||||||||
|
||||||||||||
ordered := make([]*tfjson.StateResource, len(orderedNames)) | ||||||||||||
for i, name := range orderedNames { | ||||||||||||
var ordered []*tfjson.StateResource | ||||||||||||
for _, name := range orderedNames { | ||||||||||||
for _, resource := range tfResourcesRichParameters { | ||||||||||||
if resource.Name == name { | ||||||||||||
ordered[i] = resource | ||||||||||||
ordered = append(ordered, resource) | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
// 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) { | ||||||||||||
nonNil := make([]*tfjson.StateResource, 0, len(ordered)) | ||||||||||||
for _, resource := range ordered { | ||||||||||||
if resource != nil { | ||||||||||||
nonNil = append(nonNil, resource) | ||||||||||||
// 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 | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
||||||||||||
ordered = nonNil | ||||||||||||
// 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 | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be simplified:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||||||||||||
} | ||||||||||||
return ordered | ||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = "0.7.0" | ||
} | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = "~> 2.22" | ||
} | ||
} | ||
} | ||
|
||
data "coder_parameter" "child_first_parameter_from_module" { | ||
name = "First parameter from child module" | ||
mutable = true | ||
type = "string" | ||
description = "First parameter from child module" | ||
default = "abcdef" | ||
} | ||
|
||
data "coder_parameter" "child_second_parameter_from_module" { | ||
name = "Second parameter from child module" | ||
mutable = true | ||
type = "string" | ||
description = "Second parameter from child module" | ||
default = "ghijkl" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
terraform { | ||
required_providers { | ||
coder = { | ||
source = "coder/coder" | ||
version = "0.7.0" | ||
} | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = "~> 2.22" | ||
} | ||
} | ||
} | ||
|
||
module "this_is_external_child_module" { | ||
source = "./child-external-module" | ||
} | ||
|
||
data "coder_parameter" "first_parameter_from_module" { | ||
name = "First parameter from module" | ||
mutable = true | ||
type = "string" | ||
description = "First parameter from module" | ||
default = "abcdef" | ||
} | ||
|
||
data "coder_parameter" "second_parameter_from_module" { | ||
name = "Second parameter from module" | ||
mutable = true | ||
type = "string" | ||
description = "Second parameter from module" | ||
default = "ghijkl" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have anything in particular against the
goto
here, butcontinue outerLoop
is likely to raise fewer eyebrows.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear you. I replaced
goto
with a simple boolean check.