pulumi/tests/testdata/codegen/components-pp/go/exampleComponent.go

107 lines
3.1 KiB
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
)
type DeploymentZonesArgs struct {
Zone pulumi.StringInput
}
type GithubAppArgs struct {
Id pulumi.StringInput
KeyBase64 pulumi.StringInput
WebhookSecret pulumi.StringInput
}
type ServersArgs struct {
Name pulumi.StringInput
}
type ExampleComponentArgs struct {
Input pulumi.StringInput
CidrBlocks map[string]pulumi.StringInput
GithubApp *GithubAppArgs
Servers []*ServersArgs
DeploymentZones map[string]*DeploymentZonesArgs
IpAddress []pulumi.IntInput
}
type ExampleComponent struct {
pulumi.ResourceState
Result pulumi.AnyOutput
}
func NewExampleComponent(
ctx *pulumi.Context,
name string,
args *ExampleComponentArgs,
opts ...pulumi.ResourceOption,
) (*ExampleComponent, error) {
var componentResource ExampleComponent
err := ctx.RegisterComponentResource("components:index:ExampleComponent", name, &componentResource, opts...)
if err != nil {
return nil, err
}
password, err := random.NewRandomPassword(ctx, fmt.Sprintf("%s-password", name), &random.RandomPasswordArgs{
Length: pulumi.Int(16),
Special: pulumi.Bool(true),
OverrideSpecial: args.Input,
}, pulumi.Parent(&componentResource))
if err != nil {
return nil, err
}
_, err = random.NewRandomPassword(ctx, fmt.Sprintf("%s-githubPassword", name), &random.RandomPasswordArgs{
Length: pulumi.Int(16),
Special: pulumi.Bool(true),
OverrideSpecial: args.GithubApp.WebhookSecret,
}, pulumi.Parent(&componentResource))
if err != nil {
return nil, err
}
// Example of iterating a list of objects
var serverPasswords []*random.RandomPassword
for index := 0; index < len(args.Servers); index++ {
key0 := index
val0 := index
__res, err := random.NewRandomPassword(ctx, fmt.Sprintf("%s-serverPasswords-%v", name, key0), &random.RandomPasswordArgs{
Length: pulumi.Int(16),
Special: pulumi.Bool(true),
OverrideSpecial: args.Servers[val0].Name,
}, pulumi.Parent(&componentResource))
if err != nil {
return nil, err
}
serverPasswords = append(serverPasswords, __res)
}
// Example of iterating a map of objects
var zonePasswords []*random.RandomPassword
for key0, val0 := range args.DeploymentZones {
__res, err := random.NewRandomPassword(ctx, fmt.Sprintf("%s-zonePasswords-%v", name, key0), &random.RandomPasswordArgs{
Length: pulumi.Int(16),
Special: pulumi.Bool(true),
[program-gen/go] Fix optional primitive values being derefrenced (#15592) # Description Fixes #15524 where the primitive optional types were being derefrenced. It took me a while to figure where the problem was because I couldn't really reproduce the original issue with a new PCL program. The `aws-optionals-pp` test case program in PCL would repro the issue when converted from the CLI via `convert --from pcl` but not from the unit tests even when using the exact same schema 🤔 this was really weird. That said, the fix turned out straightforward and it does fix the same issue in generated component resources. ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [x] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [x] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. -->
2024-03-10 04:49:06 +00:00
OverrideSpecial: pulumi.String(val0),
}, pulumi.Parent(&componentResource))
if err != nil {
return nil, err
}
zonePasswords = append(zonePasswords, __res)
}
_, err = NewSimpleComponent(ctx, fmt.Sprintf("%s-simpleComponent", name), nil, pulumi.Parent(&componentResource))
if err != nil {
return nil, err
}
err = ctx.RegisterResourceOutputs(&componentResource, pulumi.Map{
"result": password.Result,
})
if err != nil {
return nil, err
}
componentResource.Result = password.Result
return &componentResource, nil
}