Skip to content

Commit

Permalink
logical name -> name
Browse files Browse the repository at this point in the history
  • Loading branch information
Zaid-Ajaj committed Jan 18, 2024
1 parent 1f17b1b commit 0cbacc5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Improvements

- Support logicalName for resources and config variables
- Support (logical) name for resources and config variables
[#546](https://github.com/pulumi/pulumi-yaml/pull/546)

### Bug Fixes
38 changes: 19 additions & 19 deletions pkg/pulumiyaml/ast/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,31 +271,31 @@ func (d *PropertyMapDecl) parse(name string, node syntax.Node) syntax.Diagnostic
type ConfigParamDecl struct {
declNode

Type *StringExpr
LogicalName *StringExpr
Secret *BooleanExpr
Default Expr
Value Expr
Type *StringExpr
Name *StringExpr
Secret *BooleanExpr
Default Expr
Value Expr
}

func (d *ConfigParamDecl) recordSyntax() *syntax.Node {
return &d.syntax
}

func ConfigParamSyntax(node *syntax.ObjectNode, typ *StringExpr, logicalName *StringExpr,
func ConfigParamSyntax(node *syntax.ObjectNode, typ *StringExpr, name *StringExpr,
secret *BooleanExpr, defaultValue Expr) *ConfigParamDecl {

return &ConfigParamDecl{
declNode: decl(node),
Type: typ,
LogicalName: logicalName,
Secret: secret,
Default: defaultValue,
declNode: decl(node),
Type: typ,
Name: name,
Secret: secret,
Default: defaultValue,
}
}

func ConfigParam(typ *StringExpr, logicalName *StringExpr, defaultValue Expr, secret *BooleanExpr) *ConfigParamDecl {
return ConfigParamSyntax(nil, typ, logicalName, secret, defaultValue)
func ConfigParam(typ *StringExpr, name *StringExpr, defaultValue Expr, secret *BooleanExpr) *ConfigParamDecl {
return ConfigParamSyntax(nil, typ, name, secret, defaultValue)
}

type ResourceOptionsDecl struct {
Expand Down Expand Up @@ -413,7 +413,7 @@ type ResourceDecl struct {
declNode

Type *StringExpr
LogicalName *StringExpr
Name *StringExpr
DefaultProvider *BooleanExpr
Properties PropertyMapDecl
Options ResourceOptionsDecl
Expand All @@ -426,15 +426,15 @@ func (d *ResourceDecl) recordSyntax() *syntax.Node {

// The names of exported fields.
func (*ResourceDecl) Fields() []string {
return []string{"type", "logicalname", "defaultprovider", "properties", "options", "get"}
return []string{"type", "name", "defaultprovider", "properties", "options", "get"}
}

func ResourceSyntax(node *syntax.ObjectNode, typ *StringExpr, logicalName *StringExpr, defaultProvider *BooleanExpr,
func ResourceSyntax(node *syntax.ObjectNode, typ *StringExpr, name *StringExpr, defaultProvider *BooleanExpr,
properties PropertyMapDecl, options ResourceOptionsDecl, get GetResourceDecl) *ResourceDecl {
return &ResourceDecl{
declNode: decl(node),
Type: typ,
LogicalName: logicalName,
Name: name,
DefaultProvider: defaultProvider,
Properties: properties,
Options: options,
Expand All @@ -444,12 +444,12 @@ func ResourceSyntax(node *syntax.ObjectNode, typ *StringExpr, logicalName *Strin

func Resource(
typ *StringExpr,
logicalName *StringExpr,
name *StringExpr,
defaultProvider *BooleanExpr,
properties PropertyMapDecl,
options ResourceOptionsDecl,
get GetResourceDecl) *ResourceDecl {
return ResourceSyntax(nil, typ, logicalName, defaultProvider, properties, options, get)
return ResourceSyntax(nil, typ, name, defaultProvider, properties, options, get)
}

type CustomTimeoutsDecl struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pulumiyaml/codegen/gen_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (g *generator) genResource(n *pcl.Resource) {
}

if n.Name() != n.LogicalName() {
entries = append(entries, syn.ObjectProperty(syn.String("logicalName"), syn.String(n.LogicalName())))
entries = append(entries, syn.ObjectProperty(syn.String("name"), syn.String(n.LogicalName())))
}

if len(properties) > 0 {
Expand Down Expand Up @@ -633,7 +633,7 @@ func (g *generator) genConfigVariable(n *pcl.ConfigVariable) {
}

if n.Name() != n.LogicalName() {
entries = append(entries, syn.ObjectProperty(syn.String("logicalName"), syn.String(n.LogicalName())))
entries = append(entries, syn.ObjectProperty(syn.String("name"), syn.String(n.LogicalName())))
}
if n.DefaultValue != nil {
prop := syn.ObjectProperty(syn.String("default"), g.expr(n.DefaultValue))
Expand Down
8 changes: 4 additions & 4 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,8 @@ func (e *programEvaluator) registerConfig(intm configNode) (interface{}, bool) {
case configNodeYaml:
k, intmKey = intm.Key.Value, intm.Key
c := intm.Value
if c.LogicalName != nil && c.LogicalName.Value != "" {
k = c.LogicalName.Value
if c.Name != nil && c.Name.Value != "" {
k = c.Name.Value
}
// If we implement global type checking, the type of configuration variables
// can be inferred and this requirement relaxed.
Expand Down Expand Up @@ -1220,8 +1220,8 @@ func (e *programEvaluator) registerResource(kvp resourceNode) (lateboundResource
// Create either a latebound custom resource or latebound provider resource depending on
// whether the type token indicates a special provider type.
resourceName := k
if v.LogicalName != nil && v.LogicalName.Value != "" {
resourceName = v.LogicalName.Value
if v.Name != nil && v.Name.Value != "" {
resourceName = v.Name.Value
}

var state lateboundResource
Expand Down
6 changes: 3 additions & 3 deletions pkg/pulumiyaml/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,13 @@ configuration:
assert.False(t, found, "We should not get any errors: '%s'", diags)
}

func TestConfigLogicalNames(t *testing.T) { //nolint:paralleltest
func TestConfigNames(t *testing.T) { //nolint:paralleltest
const text = `name: test-yaml
runtime: yaml
configuration:
foo:
type: String
logicalName: logicalFoo
name: logicalFoo
bar:
type: String
`
Expand Down Expand Up @@ -1984,7 +1984,7 @@ runtime: yaml
resources:
sourceName:
type: test:resource:UsingLogicalName
logicalName: actual-registered-name
name: actual-registered-name
sourceNameOnly:
type: test:resource:WithoutLogicalName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
configuration:
configLexicalName:
type: string
logicalName: "cC-Charlie_charlie.\U0001F603⁉️"
name: "cC-Charlie_charlie.\U0001F603⁉️"
resources:
resourceLexicalName:
type: random:RandomPet
logicalName: "aA-Alpha_alpha.\U0001F92F⁉️"
name: "aA-Alpha_alpha.\U0001F92F⁉️"
properties:
prefix: ${configLexicalName}
outputs:
Expand Down

0 comments on commit 0cbacc5

Please sign in to comment.