Skip to content
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

Do not error on duplicate config keys #402

Merged
merged 12 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[#393](https://github.com/pulumi/pulumi-yaml/pull/393)

### Bug Fixes

- Do not error on duplicate config keys.
[#402](https://github.com/pulumi/pulumi-yaml/pull/402)
7 changes: 3 additions & 4 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ func LoadYAMLBytes(filename string, source []byte) (*ast.TemplateDecl, syntax.Di
if tdiags.HasErrors() {
return nil, diags, nil
}
// TODO: warn if using old configuration block
// if t.Configuration.Entries != nil {
// diags = append(diags, syntax.Warning(nil, "Pulumi.yaml: root-level `configuration` field is deprecated; please use `config` instead.", ""))
// }
if t.Configuration.Entries != nil {
diags = append(diags, syntax.Warning(nil, "Pulumi.yaml: root-level `configuration` field is deprecated; please use `config` instead.", ""))
}

return t, diags, nil
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/pulumiyaml/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type configNode interface {
type configNodeYaml ast.ConfigMapEntry

func (e configNodeYaml) valueKind() string {
return "config"
return "configYaml"
}

func (e configNodeYaml) key() *ast.StringExpr {
Expand All @@ -64,7 +64,7 @@ type configNodeEnv struct {
}

func (e configNodeEnv) valueKind() string {
return "config"
return "configEnv"
}

func (e configNodeEnv) key() *ast.StringExpr {
Expand Down Expand Up @@ -240,10 +240,17 @@ func checkUniqueNode(intermediates map[string]graphNode, node graphNode) syntax.
if other, found := intermediates[name]; found {
if node.valueKind() == other.valueKind() {
diags.Extend(ast.ExprError(key, fmt.Sprintf("found duplicate %s %s", node.valueKind(), name), ""))
} else if isConfigNode(node) && isConfigNode(other) {
diags = append(diags, syntax.Warning(nil, fmt.Sprintf("%s set in both `config` and `configuration`", name), ""))
aq17 marked this conversation as resolved.
Show resolved Hide resolved
} else {
diags.Extend(ast.ExprError(key, fmt.Sprintf("%s %s cannot have the same name as %s %s", node.valueKind(), name, other.valueKind(), name), ""))
}
return diags
}
return diags
}

func isConfigNode(n graphNode) bool {
_, ok := n.(configNode)
return ok
}