Add aliases to the Go SDK codegen pkg (#4157)

This commit is contained in:
Levi Blackstone 2020-03-24 11:18:21 -06:00 committed by GitHub
parent c62d52690c
commit 8ce10e1dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -10,6 +10,8 @@ CHANGELOG
- Add missing builtin `MapArray` to Go SDK.
[#4144](https://github.com/pulumi/pulumi/pull/4144)
- Add aliases to Go SDK codegen pkg.
[#4157](https://github.com/pulumi/pulumi/pull/4157)
- Discontinue testing on Node 8 (which has been end-of-life since January 2020), and start testing on Node 13.
[#4156](https://github.com/pulumi/pulumi/pull/4156)

View file

@ -603,6 +603,27 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource) error {
}
}
// Set any defined aliases.
if len(r.Aliases) > 0 {
fmt.Fprintf(w, "\taliases := pulumi.Aliases([]pulumi.Alias{\n")
for _, alias := range r.Aliases {
s := "\t\t{\n"
if alias.Name != nil {
s += fmt.Sprintf("\t\t\tName: pulumi.String(%q),\n", *alias.Name)
}
if alias.Project != nil {
s += fmt.Sprintf("\t\t\tProject: pulumi.String(%q),\n", *alias.Project)
}
if alias.Type != nil {
s += fmt.Sprintf("\t\t\tType: pulumi.String(%q),\n", *alias.Type)
}
s += "\t\t},\n"
fmt.Fprint(w, s)
}
fmt.Fprintf(w, "\t})\n")
fmt.Fprintf(w, "\topts = append(opts, aliases)\n")
}
// Finally make the call to registration.
fmt.Fprintf(w, "\tvar resource %s\n", name)
fmt.Fprintf(w, "\terr := ctx.RegisterResource(\"%s\", name, args, &resource, opts...)\n", r.Token)