2022-09-14 03:02:19 +00:00
|
|
|
//go:build !all
|
|
|
|
// +build !all
|
|
|
|
|
2020-12-01 18:03:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
|
2022-09-14 03:02:19 +00:00
|
|
|
"github.com/pulumi/pulumi-random/sdk/v4/go/random"
|
2021-03-17 13:20:05 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
2022-07-26 18:04:13 +00:00
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi/config"
|
2020-12-01 18:03:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type MyResource struct {
|
|
|
|
pulumi.ResourceState
|
|
|
|
|
2022-07-26 18:04:13 +00:00
|
|
|
Length pulumi.IntOutput `pulumi:"length"`
|
|
|
|
Prefix pulumi.StringPtrOutput `pulumi:"prefix"`
|
2020-12-01 18:03:47 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 16:36:39 +00:00
|
|
|
type (
|
|
|
|
myResourceArgs struct{}
|
|
|
|
MyResourceArgs struct{}
|
|
|
|
)
|
2020-12-01 18:03:47 +00:00
|
|
|
|
|
|
|
func (MyResourceArgs) ElementType() reflect.Type {
|
|
|
|
return reflect.TypeOf((*myResourceArgs)(nil)).Elem()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetResource(ctx *pulumi.Context, urn pulumi.URN) (*MyResource, error) {
|
|
|
|
var resource MyResource
|
|
|
|
err := ctx.RegisterResource("unused:unused:unused", "unused", &MyResourceArgs{}, &resource,
|
|
|
|
pulumi.URN_(string(urn)))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &resource, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pulumi.Run(func(ctx *pulumi.Context) error {
|
2022-07-26 18:04:13 +00:00
|
|
|
c := config.New(ctx, "")
|
|
|
|
bar := c.RequireSecret("bar")
|
2020-12-01 18:03:47 +00:00
|
|
|
pet, err := random.NewRandomPet(ctx, "cat", &random.RandomPetArgs{
|
|
|
|
Length: pulumi.Int(2),
|
2022-07-26 18:04:13 +00:00
|
|
|
Prefix: bar,
|
2020-12-01 18:03:47 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
getPetLength := pet.URN().ApplyT(func(urn pulumi.URN) (pulumi.IntInput, error) {
|
|
|
|
r, err := GetResource(ctx, urn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return r.Length, nil
|
|
|
|
})
|
2022-07-26 18:04:13 +00:00
|
|
|
getPetSecret := pet.URN().ApplyT(func(urn pulumi.URN) (pulumi.StringPtrInput, error) {
|
|
|
|
r, err := GetResource(ctx, urn)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return r.Prefix, nil
|
|
|
|
})
|
2020-12-01 18:03:47 +00:00
|
|
|
ctx.Export("getPetLength", getPetLength)
|
2022-07-26 18:04:13 +00:00
|
|
|
ctx.Export("secret", getPetSecret)
|
2020-12-01 18:03:47 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|