Compare commits

...

23 commits

Author SHA1 Message Date
Anton Tayanovskyy 4d4ff9f1d6
Fixes 8403 name conflicts in Go codegen (#8492)
* Apply fn renaming on Result name conflict

* Add tests

* Add test declaration to test driver

* Accept baselines for other langs
2021-11-24 20:13:47 -05:00
Fraser Waters 2d26cdd9ed
Run validate function even if dryRun=true (#8494)
Hit this while trying to add some validation checks to runs of Preview while using plans. Seems one test actually was assuming this was the case already and just hasn't been running it's expected validate function.
2021-11-24 22:13:29 +00:00
Pat Gavlin b14bc09b1c
Update a misleading comment. (#8491) 2021-11-24 10:37:08 -08:00
Fraser Waters 09b7aa9186
Add String and GoString to Result (#8490)
I got fed up of assert errors in tests that looked like:
```
Expected nil, but got: &result.simpleResult{err:(*errors.fundamental)(0xc0002fa5d0)}
```

It was very hard to work out at a glance what had gone wrong and I kept
having to hook a debugger just to look at what the error was.

With GoString these now print something like:
```
Expected nil, but got: &simpleResult{err: Unexpected diag message: <{%reset%}>resource violates plan: properties changed: -zed, -baz, -foo<{%reset%}>
}
```

Which is much more useful.
2021-11-24 17:01:55 +00:00
Alex Mullans c39343fa3d
Update CONTRIBUTING.md with latest information (#8451)
* Update CONTRIBUTING.md

* Add `make dist` to recommended make targets
2021-11-23 16:31:56 -08:00
Ian Wahbe 4b7985384c
[codegen/go] Call site defaults for Pulumi Object types (#8411)
* Add test case

* Fix tests

* Add test dependencies correctly

* Feed through error handling

* Include test output

* Get types to line up

* Add remaining test files

* Update changelog

* Correctly find type paths

* Handle transitive objects

* Handle required fields

* Add feature flag for go

* Add required+default test case

* Don't `<any>` cast known types.

* Add more flags.

I realize this should really wait for PR#8400 to merge.

* Add plain object to env-helper test

This test fails right now. My next problem is fixing it.

* Handle plain types

* Handle function inputs

* Fix the indentation

* Handle output types correctly

* Remove unnecessary `!`

* Add test case

* Fix tests

* Add test dependencies correctly

* Feed through error handling

* Include test output

* Get types to line up

* Add remaining test files

* Update changelog

* Correctly find type paths

* Handle transitive objects

* Handle required fields

* Add required+default test case

* Don't `<any>` cast known types.

* Add plain object to env-helper test

This test fails right now. My next problem is fixing it.

* Handle plain types

* Handle function inputs

* Fix the indentation

* Handle output types correctly

* Remove unnecessary `!`

* Start on `genPlainObjectDefaultFunc`

* Add missing change to fix test

* Run tests with merge

* Refactor out assign

* Merge in next _index.md diff

* Change method name to `Defaults`

* Handle enums correctly

* Another attempt at _index.md

* Make module generation deterministic

* Add checks for old values

* Insert defaults in resources

* Fix docs generation

Credit to @praneetloke

* Progress on adding defaults to Resource arguments

* Handle resource argument defaults

* Don't create defaults if disableObjectDefaults

* Rename test folder

* Add test for disable flag

* Fix disable test

* Update docs

* Abstract out nil comparisons

* Use reflection to test for empty values

* Simplify Ptr and pulumi.Any type handling

* Remove unused function

* Apply defaults to functions

* Update new test with master codegen

* Tests + nil check
2021-11-23 15:10:15 -08:00
Anton Tayanovskyy 6cb801cf17
Add a unit test to check Array/Index (#8486) 2021-11-23 16:52:02 -05:00
Pat Gavlin 52d01bb915
[codegen/go] Remove ResourcePtr input/output types (#8449)
These changes remove the `Ptr` variants of input/ouptut types for
resources. A `TPtr` input or output is normally generated for `T` if `T`
is present in an `optional(input(T))` or `optional(output(T))` and if
the Go representation for `T` is not nilable. The generation of `Ptr`
variants for resource types breaks the latter rule: the canonical
representation of a resource type named `Foo` is a pointer to a struct
type named `Foo` (i.e. `*Foo`). `Foo` itself is not a resource, as it
does not implement the Go `Resource` interface. Because this
representation already accommodates `nil` to indicate the lack of a
value, we need not generate `FooPtr{Input,Output}` types.

Besides being unnecessary, the implementation of `Ptr` types for
resources was incorrect. Rather than using `**Foo` as their element
type, these types use `*Foo`--identical to the element type used for
the normal input/output types. Furthermore, the generated code for
at least `FooOutput.ToFooPtrOutputWithContext` and `FooPtrOutput.Elem`
was incorrect, making these types virtually unusable in practice.

Finally, these `Ptr` types should never appear on input/output
properties in practice, as the logic we use to generate input and output
type references never generates them for `optional({input,output}(T)).
Instead, it generates references to the standard input/output types.

Though this is _technically_ a breaking change--it changes the set of
exported types for any package that defines resources--I believe that in
practice it will be invisible to users for the reasons stated above.
These types are not usable, and were never referenced.

This is preparatory work for #7943.
2021-11-23 10:24:56 -08:00
Ian Wahbe c1c82b8317
Change build green link from travis to github (#8483) 2021-11-22 17:00:05 -08:00
Ian Wahbe e77d780370
Cleanup CHANGELOG_PENDING.md (#8482) 2021-11-22 16:59:22 -08:00
Ian Wahbe 72a4e1fc3f
Update pkg -> sdk dependency (#8481) 2021-11-22 14:39:54 -08:00
Ian Wahbe c6cefcd3f4
Prepare for v3.18.1 release (#8480) 2021-11-22 14:30:47 -08:00
Ian Wahbe 4029a1c89b
iwahbe/8474/dont serialize unknown values (#8475)
* Don't serialize unknown values

* Add test

* Update CHANGELOG_PENDING.md
2021-11-22 12:40:17 -08:00
Ian Wahbe d9dd88c740
Add tsconfig option to specify tsconfig path (#8452)
* Add tsconfig option to specify tsconfig path

* Add CHANGELOG entry and fix lint

* Add a test

* Fix test
2021-11-22 11:42:39 -08:00
Anton Tayanovskyy 574a6a104d
Do not FailNow() in generators (#8469) 2021-11-19 20:39:11 -05:00
Ian Wahbe 87d8c7f074
[sdk/pthon] Version Check: Handle virtual env correctly (#8465)
* Handle virtual env correctly

* Add CHANGELOG entry

* Correctly display which version is EOL
2021-11-19 15:21:13 -08:00
Ian Wahbe 7222e5570a
[cli] check main after master (#8463)
* Allow specifying a branch with url#branch

* Probe for master and main

* Update CHANGELOG

* Fix linter errors

* Remove unnecessary feature

* Fix lint

* Update changelog to reflect new limited scope.

We only talk about the master -> main probing, because that is all the
PR does. It used to duplicate another feature.
2021-11-19 13:49:59 -08:00
raphaelauv dbc8ab9ad6
[FIX] unprotect cmd example (#8430)
* [FIX] unprotect cmd example
2021-11-19 12:39:34 -08:00
Praneet Loke 2c25c3fbd0
[backend/filestate] Don't unwrap go-cloud errors (#8455)
* Don't unwrap go-cloud errors

* Remove unused func

* Add changelog entry

Co-authored-by: Ian Wahbe <ian@wahbe.com>
2021-11-19 12:21:37 -08:00
Anton Tayanovskyy f98d39b84b
Fix non-determinism in docsgen (#8456) 2021-11-19 11:23:06 -05:00
Anton Tayanovskyy e60d6bf248
Programgen support for F.Invoke forms in .NET (#7949) (#8432)
* Implement .NET codegen for F.Invoke forms

* Add tests for .NET Invoke

* Fixed conflict

* Accept changes reverting fargate example
2021-11-18 17:53:17 -05:00
Anton Tayanovskyy e846b3201f
Go implementation of fn.Output program gen (#7949) (#8431)
* Modify Go codegen for fn.Output overloads

* Fix go tests

* Fixed CHANGELOG conflict

* ACCEPT changes reverting Fargate example to master, file issue

* Link an issue
2021-11-18 17:50:51 -05:00
Anton Tayanovskyy 1cedb29193
Programgen support for fn_output forms in Python (#7949) (#8433)
* Update Python programgen to use fn_output forms

* Fix skips

* Fix CHANGELOG

* Accept changes, backing out Fargate change
2021-11-18 17:43:13 -05:00
332 changed files with 10915 additions and 2043 deletions

View file

@ -1,6 +1,43 @@
CHANGELOG
=========
## 3.18.1 (2021-11-22)
### Improvements
- [cli] - When running `pulumi new https://github.com/name/repo`, check
for branch `main` if branch `master` doesn't exist.
[#8463](https://github.com/pulumi/pulumi/pull/8463)
- [codegen/python] - Program generator now uses `fn_output` forms where
appropriate, simplifying auto-generated examples.
[#8433](https://github.com/pulumi/pulumi/pull/8433)
- [codegen/go] - Program generator now uses fnOutput forms where
appropriate, simplifying auto-generated examples.
[#8431](https://github.com/pulumi/pulumi/pull/8431)
- [codegen/dotnet] - Program generator now uses `Invoke` forms where
appropriate, simplifying auto-generated examples.
[#8432](https://github.com/pulumi/pulumi/pull/8432)
### Bug Fixes
- [cli/nodejs] - Allow specifying the tsconfig file used in Pulumi.yaml.
[#8452](https://github.com/pulumi/pulumi/pull/8452)
- [codegen/nodejs] - Respect default values in Pulumi object types.
[#8400](https://github.com/pulumi/pulumi/pull/8400)
- [sdk/python] - Correctly handle version checking python virtual environments.
[#8465](https://github.com/pulumi/pulumi/pull/8465)
- [cli] - Catch expected errors in stacks with filestate backends.
[#8455](https://github.com/pulumi/pulumi/pull/8455)
- [sdk/dotnet] - Do not attempt to serialize unknown values.
[#8475](https://github.com/pulumi/pulumi/pull/8475)
## 3.18.0 (2021-11-17)
### Improvements

View file

@ -1,6 +1,12 @@
### Improvements
- [codegen/go] - Remove `ResourcePtr` types from generated SDKs. Besides being
unnecessary--`Resource` types already accommodate `nil` to indicate the lack of
a value--the implementation of `Ptr` types for resources was incorrect, making
these types virtually unusable in practice.
[#8449](https://github.com/pulumi/pulumi/pull/8449)
### Bug Fixes
- [codegen/typescript] - Respect default values in Pulumi object types.
[#8400](https://github.com/pulumi/pulumi/pull/8400)
- [codegen/go] - Respect default values in Pulumi object types.
[#8411](https://github.com/pulumi/pulumi/pull/8400)

View file

@ -22,7 +22,7 @@ To hack on Pulumi, you'll need to get a development environment set up. You'll w
You can easily get all required dependencies with brew and npm
```bash
brew install node pipenv python@3 typescript yarn go@1.17 golangci/tap/golangci-lint pulumi/tap/pulumictl
brew install node pipenv python@3 typescript yarn go@1.17 golangci/tap/golangci-lint pulumi/tap/pulumictl coreutils
curl https://raw.githubusercontent.com/Homebrew/homebrew-cask/0272f0d33f/Casks/dotnet-sdk.rb > dotnet-sdk.rb # v3.1.0
brew install --HEAD -s dotnet-sdk.rb
rm dotnet-sdk.rb
@ -53,9 +53,10 @@ ulimit -n 5000
Across our projects, we try to use a regular set of make targets. The ones you'll care most about are:
0. `make ensure`, which restores/installs any build dependencies
1. `make ensure`, which restores/installs any build dependencies
1. `make dist`, which just builds and installs the Pulumi CLI
1. `make`, which builds Pulumi and runs a quick set of tests
2. `make all` which builds Pulumi and runs the quick tests and a larger set of tests.
1. `make all` which builds Pulumi and runs the quick tests and a larger set of tests.
We make heavy use of integration level testing where we invoke `pulumi` to create and then delete cloud resources. This requires you to have a Pulumi account (so [sign up for free](https://pulumi.com) today if you haven't already) and login with `pulumi login`.

View file

@ -173,8 +173,8 @@ details of the core Pulumi CLI and [programming model concepts](https://www.pulu
| Architecture | Build Status |
| ------------ | ------------ |
| Linux/macOS x64 | [![Linux x64 Build Status](https://travis-ci.com/pulumi/pulumi.svg?token=cTUUEgrxaTEGyecqJpDn&branch=master)](https://travis-ci.com/pulumi/pulumi) |
| Windows x64 | [![Windows x64 Build Status](https://ci.appveyor.com/api/projects/status/uqrduw6qnoss7g4i?svg=true&branch=master)](https://ci.appveyor.com/project/pulumi/pulumi) |
| Linux/macOS x64 | [![Linux x64 Build Status](https://github.com/pulumi/pulumi/actions/workflows/master.yml/badge.svg)](https://github.com/pulumi/pulumi/actions/workflows/master.yml) |
| Windows x64 | [![Windows x64 Build Status](https://ci.appveyor.com/api/projects/status/uqrduw6qnoss7g4i?svg=true&branch=master)](https://ci.appveyor.com/project/pulumi/pulumi) |
### Languages

View file

@ -323,7 +323,7 @@ func (b *localBackend) GetStack(ctx context.Context, stackRef backend.StackRefer
snapshot, path, err := b.getStack(stackName)
switch {
case gcerrors.Code(drillError(err)) == gcerrors.NotFound:
case gcerrors.Code(err) == gcerrors.NotFound:
return nil, nil
case err != nil:
return nil, err
@ -882,12 +882,3 @@ func (b *localBackend) UpdateStackTags(ctx context.Context,
// The local backend does not currently persist tags.
return errors.New("stack tags not supported in --local mode")
}
// Returns the original error in the chain. If `err` is nil, nil is returned.
func drillError(err error) error {
e := err
for errors.Unwrap(e) != nil {
e = errors.Unwrap(e)
}
return e
}

View file

@ -187,3 +187,20 @@ func TestListStacksWithMultiplePassphrases(t *testing.T) {
}
}
func TestDrillError(t *testing.T) {
// Login to a temp dir filestate backend
tmpDir, err := ioutil.TempDir("", "filestatebackend")
assert.NoError(t, err)
b, err := New(cmdutil.Diag(), "file://"+filepath.ToSlash(tmpDir))
assert.NoError(t, err)
ctx := context.Background()
// Get a non-existent stack and expect a nil error because it won't be found.
stackRef, err := b.ParseStackReference("dev")
if err != nil {
t.Fatalf("unexpected error %v when parsing stack reference", err)
}
_, err = b.GetStack(ctx, stackRef)
assert.Nil(t, err)
}

View file

@ -323,7 +323,7 @@ func (b *localBackend) getHistory(name tokens.QName, pageSize int, page int) ([]
allFiles, err := listBucket(b.bucket, dir)
if err != nil {
// History doesn't exist until a stack has been updated.
if gcerrors.Code(drillError(err)) == gcerrors.NotFound {
if gcerrors.Code(err) == gcerrors.NotFound {
return nil, nil
}
return nil, err
@ -391,7 +391,7 @@ func (b *localBackend) renameHistory(oldName tokens.QName, newName tokens.QName)
allFiles, err := listBucket(b.bucket, oldHistory)
if err != nil {
// if there's nothing there, we don't really need to do a rename.
if gcerrors.Code(drillError(err)) == gcerrors.NotFound {
if gcerrors.Code(err) == gcerrors.NotFound {
return nil
}
return err

View file

@ -902,8 +902,14 @@ func (mod *modContext) genNestedTypes(member interface{}, resourceType bool) []d
// and if it appears in an input object and/or output object.
mod.getTypes(member, tokens)
var typs []docNestedType
var sortedTokens []string
for token := range tokens {
sortedTokens = append(sortedTokens, token)
}
sort.Strings(sortedTokens)
var typs []docNestedType
for _, token := range sortedTokens {
for _, t := range mod.pkg.Types {
switch typ := t.(type) {
case *schema.ObjectType:

View file

@ -1,4 +1,4 @@
// Copyright 2016-2020, Pulumi Corporation.
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -46,6 +46,9 @@ type generator struct {
asyncInit bool
configCreated bool
diagnostics hcl.Diagnostics
// Helper map to emit custom type name suffixes that match
// those emitted by codegen.
usedInFunctionOutputVersionInputs map[schema.Type]bool
}
const pulumiPackage = "pulumi"
@ -343,14 +346,32 @@ func (g *generator) functionName(tokenArg model.Expression) (string, string) {
return rootNamespace, fmt.Sprintf("%s%s.%s", rootNamespace, namespace, Title(member))
}
func (g *generator) toSchemaType(destType model.Type) (schema.Type, bool) {
schemaType, ok := pcl.GetSchemaForType(destType.(model.Type))
if !ok {
return nil, false
}
return codegen.UnwrapType(schemaType), true
}
// argumentTypeName computes the C# argument class name for the given expression and model type.
func (g *generator) argumentTypeName(expr model.Expression, destType model.Type) string {
schemaType, ok := pcl.GetSchemaForType(destType.(model.Type))
schemaType, ok := g.toSchemaType(destType)
if !ok {
return ""
}
suffix := "Args"
if g.usedInFunctionOutputVersionInputs[schemaType] {
suffix = "InputArgs"
}
return g.argumentTypeNameWithSuffix(expr, destType, suffix)
}
schemaType = codegen.UnwrapType(schemaType)
func (g *generator) argumentTypeNameWithSuffix(expr model.Expression, destType model.Type, suffix string) string {
schemaType, ok := g.toSchemaType(destType)
if !ok {
return ""
}
objType, ok := schemaType.(*schema.ObjectType)
if !ok {
@ -382,7 +403,7 @@ func (g *generator) argumentTypeName(expr model.Expression, destType model.Type)
} else if qualifier != "" {
namespace = namespace + "." + qualifier
}
member = member + "Args"
member = member + suffix
return fmt.Sprintf("%s%s.%s", rootNamespace, namespace, Title(member))
}

View file

@ -255,6 +255,28 @@ func (g *generator) genFunctionUsings(x *model.FunctionCallExpression) []string
return []string{fmt.Sprintf("%s = Pulumi.%[1]s", pkg)}
}
func (g *generator) markTypeAsUsedInFunctionOutputVersionInputs(t model.Type) {
if g.usedInFunctionOutputVersionInputs == nil {
g.usedInFunctionOutputVersionInputs = make(map[schema.Type]bool)
}
schemaType, ok := g.toSchemaType(t)
if !ok {
return
}
g.usedInFunctionOutputVersionInputs[schemaType] = true
}
func (g *generator) visitToMarkTypesUsedInFunctionOutputVersionInputs(expr model.Expression) {
visitor := func(expr model.Expression) (model.Expression, hcl.Diagnostics) {
isCons, _, t := pcl.RecognizeTypedObjectCons(expr)
if isCons {
g.markTypeAsUsedInFunctionOutputVersionInputs(t)
}
return expr, nil
}
model.VisitExpression(expr, nil, visitor) // nolint:errcheck
}
func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionCallExpression) {
switch expr.Name {
case pcl.IntrinsicConvert:
@ -294,10 +316,19 @@ func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionC
case pcl.Invoke:
_, name := g.functionName(expr.Args[0])
g.Fprintf(w, "%s.InvokeAsync(", name)
if len(expr.Args) >= 2 {
g.Fgenf(w, "%.v", expr.Args[1])
isOut, outArgs, outArgsTy := pcl.RecognizeOutputVersionedInvoke(expr)
if isOut {
g.visitToMarkTypesUsedInFunctionOutputVersionInputs(outArgs)
g.Fprintf(w, "%s.Invoke(", name)
typeName := g.argumentTypeNameWithSuffix(expr, outArgsTy, "InvokeArgs")
g.genObjectConsExpressionWithTypeName(w, outArgs, typeName)
} else {
g.Fprintf(w, "%s.InvokeAsync(", name)
if len(expr.Args) >= 2 {
g.Fgenf(w, "%.v", expr.Args[1])
}
}
if len(expr.Args) == 3 {
g.Fgenf(w, ", %.v", expr.Args[2])
}
@ -446,7 +477,18 @@ func (g *generator) genObjectConsExpression(w io.Writer, expr *model.ObjectConsE
return
}
typeName := g.argumentTypeName(expr, destType)
destTypeName := g.argumentTypeName(expr, destType)
g.genObjectConsExpressionWithTypeName(w, expr, destTypeName)
}
func (g *generator) genObjectConsExpressionWithTypeName(
w io.Writer, expr *model.ObjectConsExpression, destTypeName string) {
if len(expr.Items) == 0 {
return
}
typeName := destTypeName
if typeName != "" {
g.Fgenf(w, "new %s", typeName)
g.Fgenf(w, "\n%s{\n", g.Indent)

View file

@ -114,6 +114,9 @@ type pkgContext struct {
// Determines if we should emit type registration code
disableInputTypeRegistrations bool
// Determines if we should emit object defaults code
disableObjectDefaults bool
}
func (pkg *pkgContext) detailsForType(t schema.Type) *typeDetails {
@ -269,6 +272,7 @@ func rawResourceName(r *schema.Resource) string {
return tokenToName(r.Token)
}
// If `nil` is a valid value of type `t`.
func isNilType(t schema.Type) bool {
switch t := t.(type) {
case *schema.OptionalType, *schema.ArrayType, *schema.MapType, *schema.ResourceType, *schema.InputType:
@ -295,23 +299,6 @@ func isNilType(t schema.Type) bool {
return false
}
// The default value for a Pulumi primitive type.
func primitiveNilValue(t schema.Type) string {
contract.Assert(schema.IsPrimitiveType(t))
switch t {
case schema.BoolType:
return "false"
case schema.IntType:
return "0"
case schema.NumberType:
return "0.0"
case schema.StringType:
return "\"\""
default:
return "nil"
}
}
func (pkg *pkgContext) inputType(t schema.Type) (result string) {
switch t := codegen.SimplifyInputUnion(t).(type) {
case *schema.OptionalType:
@ -513,7 +500,12 @@ func (pkg *pkgContext) typeStringImpl(t schema.Type, argsType bool) string {
}
func (pkg *pkgContext) typeString(t schema.Type) string {
return pkg.typeStringImpl(t, false)
s := pkg.typeStringImpl(t, false)
if s == "pulumi." {
return "pulumi.Any"
}
return s
}
func (pkg *pkgContext) isExternalReference(t schema.Type) bool {
@ -571,6 +563,10 @@ func (pkg *pkgContext) resolveObjectType(t *schema.ObjectType) string {
}
return name
}
return pkg.contextForExternalReferenceType(t).typeString(t)
}
func (pkg *pkgContext) contextForExternalReferenceType(t *schema.ObjectType) *pkgContext {
extPkg := t.Package
var goInfo GoPackageInfo
@ -584,7 +580,7 @@ func (pkg *pkgContext) resolveObjectType(t *schema.ObjectType) string {
pkgImportAliases: goInfo.PackageImportAliases,
modToPkg: goInfo.ModuleToPackage,
}
return extPkgCtx.typeString(t)
return extPkgCtx
}
func (pkg *pkgContext) outputType(t schema.Type) string {
@ -629,6 +625,9 @@ func (pkg *pkgContext) outputType(t schema.Type) string {
}
// TODO(pdg): union types
return "pulumi.AnyOutput"
case *schema.InputType:
// We can't make output types for input types. We instead strip the input and try again.
return pkg.outputType(t.ElementType)
default:
switch t {
case schema.BoolType:
@ -780,16 +779,14 @@ type genInputImplementationArgs struct {
elementType string
ptrMethods bool
toOutputMethods bool
resourceType bool
}
func genInputImplementation(w io.Writer, name, receiverType, elementType string, ptrMethods, resourceType bool) {
func genInputImplementation(w io.Writer, name, receiverType, elementType string, ptrMethods bool) {
genInputImplementationWithArgs(w, genInputImplementationArgs{
name: name,
receiverType: receiverType,
elementType: elementType,
ptrMethods: ptrMethods,
resourceType: resourceType,
toOutputMethods: true,
})
}
@ -798,14 +795,9 @@ func genInputImplementationWithArgs(w io.Writer, genArgs genInputImplementationA
name := genArgs.name
receiverType := genArgs.receiverType
elementType := genArgs.elementType
resourceType := genArgs.resourceType
fmt.Fprintf(w, "func (%s) ElementType() reflect.Type {\n", receiverType)
if resourceType {
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil))\n", elementType)
} else {
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil)).Elem()\n", elementType)
}
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil)).Elem()\n", elementType)
fmt.Fprintf(w, "}\n\n")
if genArgs.toOutputMethods {
@ -833,15 +825,11 @@ func genInputImplementationWithArgs(w io.Writer, genArgs genInputImplementationA
}
}
func genOutputType(w io.Writer, baseName, elementType string, ptrMethods, resourceType bool) {
func genOutputType(w io.Writer, baseName, elementType string, ptrMethods bool) {
fmt.Fprintf(w, "type %sOutput struct { *pulumi.OutputState }\n\n", baseName)
fmt.Fprintf(w, "func (%sOutput) ElementType() reflect.Type {\n", baseName)
if resourceType {
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil))\n", elementType)
} else {
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil)).Elem()\n", elementType)
}
fmt.Fprintf(w, "\treturn reflect.TypeOf((*%s)(nil)).Elem()\n", elementType)
fmt.Fprintf(w, "}\n\n")
fmt.Fprintf(w, "func (o %[1]sOutput) To%[2]sOutput() %[1]sOutput {\n", baseName, Title(baseName))
@ -865,8 +853,8 @@ func genOutputType(w io.Writer, baseName, elementType string, ptrMethods, resour
}
}
func genArrayOutput(w io.Writer, baseName, elementType string, resourceType bool) {
genOutputType(w, baseName+"Array", "[]"+elementType, false, resourceType)
func genArrayOutput(w io.Writer, baseName, elementType string) {
genOutputType(w, baseName+"Array", "[]"+elementType, false)
fmt.Fprintf(w, "func (o %[1]sArrayOutput) Index(i pulumi.IntInput) %[1]sOutput {\n", baseName)
fmt.Fprintf(w, "\treturn pulumi.All(o, i).ApplyT(func (vs []interface{}) %s {\n", elementType)
@ -875,8 +863,8 @@ func genArrayOutput(w io.Writer, baseName, elementType string, resourceType bool
fmt.Fprintf(w, "}\n\n")
}
func genMapOutput(w io.Writer, baseName, elementType string, resourceType bool) {
genOutputType(w, baseName+"Map", "map[string]"+elementType, false, resourceType)
func genMapOutput(w io.Writer, baseName, elementType string) {
genOutputType(w, baseName+"Map", "map[string]"+elementType, false)
fmt.Fprintf(w, "func (o %[1]sMapOutput) MapIndex(k pulumi.StringInput) %[1]sOutput {\n", baseName)
fmt.Fprintf(w, "\treturn pulumi.All(o, k).ApplyT(func (vs []interface{}) %s{\n", elementType)
@ -885,8 +873,8 @@ func genMapOutput(w io.Writer, baseName, elementType string, resourceType bool)
fmt.Fprintf(w, "}\n\n")
}
func genPtrOutput(w io.Writer, baseName, elementType string, resourceType bool) {
genOutputType(w, baseName+"Ptr", "*"+elementType, false, resourceType)
func genPtrOutput(w io.Writer, baseName, elementType string) {
genOutputType(w, baseName+"Ptr", "*"+elementType, false)
fmt.Fprintf(w, "func (o %[1]sPtrOutput) Elem() %[1]sOutput {\n", baseName)
fmt.Fprintf(w, "\treturn o.ApplyT(func(v *%[1]s) %[1]s {\n", baseName)
@ -952,7 +940,7 @@ func (pkg *pkgContext) genEnum(w io.Writer, enumType *schema.EnumType) error {
fmt.Fprintf(w, "type %[1]sArray []%[1]s\n\n", name)
genInputImplementation(w, name+"Array", name+"Array", "[]"+name, false, false)
genInputImplementation(w, name+"Array", name+"Array", "[]"+name, false)
}
// Generate the map input.
@ -961,24 +949,24 @@ func (pkg *pkgContext) genEnum(w io.Writer, enumType *schema.EnumType) error {
fmt.Fprintf(w, "type %[1]sMap map[string]%[1]s\n\n", name)
genInputImplementation(w, name+"Map", name+"Map", "map[string]"+name, false, false)
genInputImplementation(w, name+"Map", name+"Map", "map[string]"+name, false)
}
// Generate the array output
if details.arrayElement {
genArrayOutput(w, name, name, false)
genArrayOutput(w, name, name)
}
// Generate the map output.
if details.mapElement {
genMapOutput(w, name, name, false)
genMapOutput(w, name, name)
}
return nil
}
func (pkg *pkgContext) genEnumOutputTypes(w io.Writer, name, elementArgsType, elementGoType, asFuncName string) {
genOutputType(w, name, name, true, false)
genOutputType(w, name, name, true)
fmt.Fprintf(w, "func (o %[1]sOutput) To%[2]sOutput() %[3]sOutput {\n", name, asFuncName, elementArgsType)
fmt.Fprintf(w, "return o.To%sOutputWithContext(context.Background())\n", asFuncName)
@ -1001,7 +989,7 @@ func (pkg *pkgContext) genEnumOutputTypes(w io.Writer, name, elementArgsType, el
fmt.Fprintf(w, "}).(%sPtrOutput)\n", elementArgsType)
fmt.Fprint(w, "}\n\n")
genPtrOutput(w, name, name, false)
genPtrOutput(w, name, name)
fmt.Fprintf(w, "func (o %[1]sPtrOutput) To%[2]sPtrOutput() %[3]sPtrOutput {\n", name, asFuncName, elementArgsType)
fmt.Fprintf(w, "return o.To%sPtrOutputWithContext(context.Background())\n", asFuncName)
@ -1103,6 +1091,27 @@ func (pkg *pkgContext) genEnumInputFuncs(w io.Writer, typeName string, enum *sch
fmt.Fprintln(w)
}
func (pkg *pkgContext) assignProperty(w io.Writer, p *schema.Property, object, value string, indirectAssign bool) {
t := strings.TrimSuffix(pkg.typeString(p.Type), "Input")
switch codegen.UnwrapType(p.Type).(type) {
case *schema.EnumType:
t = ""
}
if codegen.IsNOptionalInput(p.Type) {
if t != "" {
value = fmt.Sprintf("%s(%s)", t, value)
}
fmt.Fprintf(w, "\targs.%s = %s\n", Title(p.Name), value)
} else if indirectAssign {
tmpName := camel(p.Name) + "_"
fmt.Fprintf(w, "%s := %s\n", tmpName, value)
fmt.Fprintf(w, "%s.%s = &%s\n", object, Title(p.Name), tmpName)
} else {
fmt.Fprintf(w, "%s.%s = %s\n", object, Title(p.Name), value)
}
}
func (pkg *pkgContext) genPlainType(w io.Writer, name, comment, deprecationMessage string,
properties []*schema.Property) {
@ -1115,6 +1124,66 @@ func (pkg *pkgContext) genPlainType(w io.Writer, name, comment, deprecationMessa
fmt.Fprintf(w, "}\n\n")
}
func (pkg *pkgContext) genPlainObjectDefaultFunc(w io.Writer, name string,
properties []*schema.Property) error {
defaults := []*schema.Property{}
for _, p := range properties {
if p.DefaultValue != nil || codegen.IsProvideDefaultsFuncRequired(p.Type) {
defaults = append(defaults, p)
}
}
// There are no defaults, so we don't need to generate a defaults function.
if len(defaults) == 0 {
return nil
}
printComment(w, fmt.Sprintf("%s sets the appropriate defaults for %s", ProvideDefaultsMethodName, name), false)
fmt.Fprintf(w, "func (val *%[1]s) %[2]s() *%[1]s {\n", name, ProvideDefaultsMethodName)
fmt.Fprint(w, "if val == nil {\n return nil\n}\n")
fmt.Fprint(w, "tmp := *val\n")
for _, p := range defaults {
if p.DefaultValue != nil {
dv, err := pkg.getDefaultValue(p.DefaultValue, codegen.UnwrapType(p.Type))
if err != nil {
return err
}
pkg.needsUtils = true
fmt.Fprintf(w, "if isZero(tmp.%s) {\n", Title(p.Name))
pkg.assignProperty(w, p, "tmp", dv, !p.IsRequired())
fmt.Fprintf(w, "}\n")
} else if funcName := pkg.provideDefaultsFuncName(p.Type); funcName != "" {
var member string
if codegen.IsNOptionalInput(p.Type) {
f := fmt.Sprintf("func(v %[1]s) %[1]s { return v.%[2]s*() }", name, funcName)
member = fmt.Sprintf("tmp.%[1]s.ApplyT(%[2]s)\n", Title(p.Name), f)
} else {
member = fmt.Sprintf("tmp.%[1]s.%[2]s()\n", Title(p.Name), funcName)
}
sigil := ""
if p.IsRequired() {
sigil = "*"
}
pkg.assignProperty(w, p, "tmp", sigil+member, false)
} else {
panic(fmt.Sprintf("Property %s[%s] should not be in the default list", p.Name, p.Type.String()))
}
}
fmt.Fprintf(w, "return &tmp\n}\n")
return nil
}
// The name of the method used to instantiate defaults.
const ProvideDefaultsMethodName = "Defaults"
func (pkg *pkgContext) provideDefaultsFuncName(typ schema.Type) string {
if !codegen.IsProvideDefaultsFuncRequired(typ) {
return ""
}
return ProvideDefaultsMethodName
}
func (pkg *pkgContext) genInputTypes(w io.Writer, t *schema.ObjectType, details *typeDetails) {
contract.Assert(t.IsInputShape())
@ -1125,7 +1194,7 @@ func (pkg *pkgContext) genInputTypes(w io.Writer, t *schema.ObjectType, details
pkg.genInputArgsStruct(w, name+"Args", t)
genInputImplementation(w, name, name+"Args", name, details.ptrElement, false)
genInputImplementation(w, name, name+"Args", name, details.ptrElement)
// Generate the pointer input.
if details.ptrElement {
@ -1139,7 +1208,7 @@ func (pkg *pkgContext) genInputTypes(w io.Writer, t *schema.ObjectType, details
fmt.Fprintf(w, "\treturn (*%s)(v)\n", ptrTypeName)
fmt.Fprintf(w, "}\n\n")
genInputImplementation(w, name+"Ptr", "*"+ptrTypeName, "*"+name, false, false)
genInputImplementation(w, name+"Ptr", "*"+ptrTypeName, "*"+name, false)
}
// Generate the array input.
@ -1148,7 +1217,7 @@ func (pkg *pkgContext) genInputTypes(w io.Writer, t *schema.ObjectType, details
fmt.Fprintf(w, "type %[1]sArray []%[1]sInput\n\n", name)
genInputImplementation(w, name+"Array", name+"Array", "[]"+name, false, false)
genInputImplementation(w, name+"Array", name+"Array", "[]"+name, false)
}
// Generate the map input.
@ -1157,7 +1226,7 @@ func (pkg *pkgContext) genInputTypes(w io.Writer, t *schema.ObjectType, details
fmt.Fprintf(w, "type %[1]sMap map[string]%[1]sInput\n\n", name)
genInputImplementation(w, name+"Map", name+"Map", "map[string]"+name, false, false)
genInputImplementation(w, name+"Map", name+"Map", "map[string]"+name, false)
}
}
@ -1196,7 +1265,6 @@ func (pkg *pkgContext) genOutputTypes(w io.Writer, genArgs genOutputTypesArgs) {
name, /* baseName */
name, /* elementType */
details.ptrElement, /* ptrMethods */
false, /* resourceType */
)
for _, p := range t.Properties {
@ -1215,7 +1283,7 @@ func (pkg *pkgContext) genOutputTypes(w io.Writer, genArgs genOutputTypesArgs) {
}
if details.ptrElement {
genPtrOutput(w, name, name, false)
genPtrOutput(w, name, name)
for _, p := range t.Properties {
printCommentWithDeprecationMessage(w, p.Comment, p.DeprecationMessage, false)
@ -1248,11 +1316,11 @@ func (pkg *pkgContext) genOutputTypes(w io.Writer, genArgs genOutputTypesArgs) {
}
if details.arrayElement {
genArrayOutput(w, name, name, false)
genArrayOutput(w, name, name)
}
if details.mapElement {
genMapOutput(w, name, name, false)
genMapOutput(w, name, name)
}
}
@ -1306,6 +1374,11 @@ func (pkg *pkgContext) getDefaultValue(dv *schema.DefaultValue, t schema.Type) (
return "", err
}
val = v
switch t.(type) {
case *schema.EnumType:
typeName := strings.TrimSuffix(pkg.typeString(codegen.UnwrapType(t)), "Input")
val = fmt.Sprintf("%s(%s)", typeName, val)
}
}
if len(dv.Environment) > 0 {
@ -1389,6 +1462,8 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
fmt.Fprintf(w, "\t}\n\n")
// Produce the inputs.
// Check all required inputs are present
for _, p := range r.InputProperties {
if p.IsRequired() && isNilType(p.Type) && p.DefaultValue == nil {
fmt.Fprintf(w, "\tif args.%s == nil {\n", Title(p.Name))
@ -1397,26 +1472,8 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
}
}
assign := func(p *schema.Property, value string, indentation int) {
ind := strings.Repeat("\t", indentation)
t := strings.TrimSuffix(pkg.typeString(p.Type), "Input")
switch codegen.UnwrapType(p.Type).(type) {
case *schema.EnumType:
t = strings.TrimSuffix(t, "Ptr")
}
if t == "pulumi." {
t = "pulumi.Any"
}
if codegen.IsNOptionalInput(p.Type) {
fmt.Fprintf(w, "\targs.%s = %s(%s)\n", Title(p.Name), t, value)
} else if isNilType(p.Type) {
tmpName := camel(p.Name) + "_"
fmt.Fprintf(w, "%s%s := %s\n", ind, tmpName, value)
fmt.Fprintf(w, "%sargs.%s = &%s\n", ind, Title(p.Name), tmpName)
} else {
fmt.Fprintf(w, "%sargs.%s = %s\n", ind, Title(p.Name), value)
}
assign := func(p *schema.Property, value string) {
pkg.assignProperty(w, p, "args", value, isNilType(p.Type))
}
for _, p := range r.InputProperties {
@ -1425,19 +1482,51 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
if err != nil {
return err
}
assign(p, v, 1)
assign(p, v)
} else if p.DefaultValue != nil {
v, err := pkg.getDefaultValue(p.DefaultValue, codegen.UnwrapType(p.Type))
dv, err := pkg.getDefaultValue(p.DefaultValue, codegen.UnwrapType(p.Type))
if err != nil {
return err
}
defaultComp := "nil"
if !codegen.IsNOptionalInput(p.Type) && !isNilType(p.Type) {
defaultComp = primitiveNilValue(p.Type)
}
fmt.Fprintf(w, "\tif args.%s == %s {\n", Title(p.Name), defaultComp)
assign(p, v, 2)
pkg.needsUtils = true
fmt.Fprintf(w, "\tif isZero(args.%s) {\n", Title(p.Name))
assign(p, dv)
fmt.Fprintf(w, "\t}\n")
} else if name := pkg.provideDefaultsFuncName(p.Type); name != "" && !pkg.disableObjectDefaults {
var value string
var needsNilCheck bool
if codegen.IsNOptionalInput(p.Type) {
innerFuncType := strings.TrimSuffix(pkg.typeString(codegen.UnwrapType(p.Type)), "Args")
applyName := fmt.Sprintf("%sApplier", camel(p.Name))
fmt.Fprintf(w, "%[3]s := func(v %[1]s) *%[1]s { return v.%[2]s() }\n", innerFuncType, name, applyName)
outputValue := pkg.convertToOutput(fmt.Sprintf("args.%s", Title(p.Name)), p.Type)
outputType := pkg.typeString(p.Type)
if strings.HasSuffix(outputType, "Input") {
outputType = strings.TrimSuffix(outputType, "Input") + "Output"
}
// Because applies return pointers, we need to convert to PtrOutput and then call .Elem().
var tail string
if !strings.HasSuffix(outputType, "PtrOutput") {
outputType = strings.TrimSuffix(outputType, "Output") + "PtrOutput"
tail = ".Elem()"
}
needsNilCheck = !p.IsRequired()
value = fmt.Sprintf("%s.ApplyT(%s).(%s)%s", outputValue, applyName, outputType, tail)
} else {
value = fmt.Sprintf("args.%[1]s.%[2]s()", Title(p.Name), name)
}
v := func() {
fmt.Fprintf(w, "args.%[1]s = %s\n", Title(p.Name), value)
}
if needsNilCheck {
fmt.Fprintf(w, "if args.%s != nil {\n", Title(p.Name))
v()
fmt.Fprint(w, "}\n")
} else {
v()
}
}
}
@ -1704,42 +1793,26 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
fmt.Fprintf(w, "\tTo%[1]sOutputWithContext(ctx context.Context) %[1]sOutput\n", name)
fmt.Fprintf(w, "}\n\n")
genInputImplementation(w, name, "*"+name, name, generateResourceContainerTypes, true)
genInputImplementation(w, name, "*"+name, "*"+name, false)
if generateResourceContainerTypes {
// Emit the resource pointer input type.
fmt.Fprintf(w, "type %sPtrInput interface {\n", name)
fmt.Fprintf(w, "\tpulumi.Input\n\n")
fmt.Fprintf(w, "\tTo%[1]sPtrOutput() %[1]sPtrOutput\n", name)
fmt.Fprintf(w, "\tTo%[1]sPtrOutputWithContext(ctx context.Context) %[1]sPtrOutput\n", name)
fmt.Fprintf(w, "}\n\n")
ptrTypeName := camel(name) + "PtrType"
fmt.Fprintf(w, "type %s %sArgs\n\n", ptrTypeName, name)
genInputImplementation(w, name+"Ptr", "*"+ptrTypeName, "*"+name, false, true)
if generateResourceContainerTypes && !r.IsProvider {
// Generate the resource array input.
pkg.genInputInterface(w, name+"Array")
fmt.Fprintf(w, "type %[1]sArray []%[1]sInput\n\n", name)
genInputImplementation(w, name+"Array", name+"Array", "[]*"+name, false)
if !r.IsProvider {
// Generate the resource array input.
pkg.genInputInterface(w, name+"Array")
fmt.Fprintf(w, "type %[1]sArray []%[1]sInput\n\n", name)
genInputImplementation(w, name+"Array", name+"Array", "[]*"+name, false, false)
// Generate the resource map input.
pkg.genInputInterface(w, name+"Map")
fmt.Fprintf(w, "type %[1]sMap map[string]%[1]sInput\n\n", name)
genInputImplementation(w, name+"Map", name+"Map", "map[string]*"+name, false, false)
}
// Generate the resource map input.
pkg.genInputInterface(w, name+"Map")
fmt.Fprintf(w, "type %[1]sMap map[string]%[1]sInput\n\n", name)
genInputImplementation(w, name+"Map", name+"Map", "map[string]*"+name, false)
}
// Emit the resource output type.
genOutputType(w, name, name, generateResourceContainerTypes, true)
genOutputType(w, name, "*"+name, false)
if generateResourceContainerTypes {
genPtrOutput(w, name, name, true)
if !r.IsProvider {
genArrayOutput(w, name, name, true)
genMapOutput(w, name, name, true)
}
if generateResourceContainerTypes && !r.IsProvider {
genArrayOutput(w, name, "*"+name)
genMapOutput(w, name, "*"+name)
}
pkg.genResourceRegistrations(w, r, generateResourceContainerTypes)
@ -1747,6 +1820,30 @@ func (pkg *pkgContext) genResource(w io.Writer, r *schema.Resource, generateReso
return nil
}
// Takes an expression and type, and returns a string that converts that expression to an Output type.
//
// Examples:
// ("bar", Foo of ObjectType) => "bar.ToFooOutput()"
// ("id", FooOutput) => "id"
// ("ptr", FooInput of ObjectType) => "ptr.ToFooPtrOutput().Elem()"
func (pkg *pkgContext) convertToOutput(expr string, typ schema.Type) string {
elemConversion := ""
switch typ.(type) {
case *schema.OptionalType:
elemConversion = ".Elem()"
}
outputType := pkg.outputType(typ)
// Remove any element before the last .
outputType = outputType[strings.LastIndex(outputType, ".")+1:]
if strings.HasSuffix(outputType, "ArgsOutput") {
outputType = strings.TrimSuffix(outputType, "ArgsOutput") + "Output"
}
if elemConversion != "" {
outputType = strings.TrimSuffix(outputType, "Output") + "PtrOutput"
}
return fmt.Sprintf("%s.To%s()%s", expr, outputType, elemConversion)
}
func NeedsGoOutputVersion(f *schema.Function) bool {
fPkg := f.Package
@ -1764,7 +1861,7 @@ func NeedsGoOutputVersion(f *schema.Function) bool {
return f.NeedsOutputVersion()
}
func (pkg *pkgContext) genFunctionCodeFile(f *schema.Function) string {
func (pkg *pkgContext) genFunctionCodeFile(f *schema.Function) (string, error) {
importsAndAliases := map[string]string{}
pkg.getImports(f, importsAndAliases)
buffer := &bytes.Buffer{}
@ -1775,12 +1872,14 @@ func (pkg *pkgContext) genFunctionCodeFile(f *schema.Function) string {
}
pkg.genHeader(buffer, imports, importsAndAliases)
pkg.genFunction(buffer, f)
if err := pkg.genFunction(buffer, f); err != nil {
return "", err
}
pkg.genFunctionOutputVersion(buffer, f)
return buffer.String()
return buffer.String(), nil
}
func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) {
func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) error {
name := pkg.functionName(f)
printCommentWithDeprecationMessage(w, f.Comment, f.DeprecationMessage, false)
@ -1801,6 +1900,8 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) {
var inputsVar string
if f.Inputs == nil {
inputsVar = "nil"
} else if codegen.IsProvideDefaultsFuncRequired(f.Inputs) && !pkg.disableObjectDefaults {
inputsVar = "args.Defaults()"
} else {
inputsVar = "args"
}
@ -1824,19 +1925,38 @@ func (pkg *pkgContext) genFunction(w io.Writer, f *schema.Function) {
fmt.Fprintf(w, "\t}\n")
// Return the result.
fmt.Fprintf(w, "\treturn &rv, nil\n")
var retValue string
if codegen.IsProvideDefaultsFuncRequired(f.Outputs) && !pkg.disableObjectDefaults {
retValue = "rv.Defaults()"
} else {
retValue = "&rv"
}
fmt.Fprintf(w, "\treturn %s, nil\n", retValue)
}
fmt.Fprintf(w, "}\n")
// If there are argument and/or return types, emit them.
if f.Inputs != nil {
fmt.Fprintf(w, "\n")
pkg.genPlainType(w, pkg.functionArgsTypeName(f), f.Inputs.Comment, "", f.Inputs.Properties)
fnInputsName := pkg.functionArgsTypeName(f)
pkg.genPlainType(w, fnInputsName, f.Inputs.Comment, "", f.Inputs.Properties)
if codegen.IsProvideDefaultsFuncRequired(f.Inputs) && !pkg.disableObjectDefaults {
if err := pkg.genPlainObjectDefaultFunc(w, fnInputsName, f.Inputs.Properties); err != nil {
return err
}
}
}
if f.Outputs != nil {
fmt.Fprintf(w, "\n")
pkg.genPlainType(w, pkg.functionResultTypeName(f), f.Outputs.Comment, "", f.Outputs.Properties)
fnOutputsName := pkg.functionResultTypeName(f)
pkg.genPlainType(w, fnOutputsName, f.Outputs.Comment, "", f.Outputs.Properties)
if codegen.IsProvideDefaultsFuncRequired(f.Outputs) && !pkg.disableObjectDefaults {
if err := pkg.genPlainObjectDefaultFunc(w, fnOutputsName, f.Outputs.Properties); err != nil {
return err
}
}
}
return nil
}
func (pkg *pkgContext) functionName(f *schema.Function) string {
@ -2015,16 +2135,24 @@ func rewriteCyclicObjectFields(pkg *schema.Package) {
}
}
func (pkg *pkgContext) genType(w io.Writer, obj *schema.ObjectType) {
func (pkg *pkgContext) genType(w io.Writer, obj *schema.ObjectType) error {
contract.Assert(!obj.IsInputShape())
if obj.IsOverlay {
// This type is generated by the provider, so no further action is required.
return
return nil
}
plainName := pkg.tokenToType(obj.Token)
pkg.genPlainType(w, plainName, obj.Comment, "", obj.Properties)
if !pkg.disableObjectDefaults {
if err := pkg.genPlainObjectDefaultFunc(w, plainName, obj.Properties); err != nil {
return err
}
}
pkg.genPlainType(w, pkg.tokenToType(obj.Token), obj.Comment, "", obj.Properties)
pkg.genInputTypes(w, obj.InputShape, pkg.detailsForType(obj))
pkg.genOutputTypes(w, genOutputTypesArgs{t: obj})
return nil
}
func (pkg *pkgContext) addSuffixesToName(typ schema.Type, name string) []string {
@ -2096,16 +2224,16 @@ func (pkg *pkgContext) genNestedCollectionTypes(w io.Writer, types map[string]ma
names = append(names, name)
if strings.HasSuffix(name, "Array") {
fmt.Fprintf(w, "type %s []%sInput\n\n", name, elementTypeName)
genInputImplementation(w, name, name, elementTypeName, false, false)
genInputImplementation(w, name, name, elementTypeName, false)
genArrayOutput(w, strings.TrimSuffix(name, "Array"), elementTypeName, false)
genArrayOutput(w, strings.TrimSuffix(name, "Array"), elementTypeName)
}
if strings.HasSuffix(name, "Map") {
fmt.Fprintf(w, "type %s map[string]%sInput\n\n", name, elementTypeName)
genInputImplementation(w, name, name, elementTypeName, false, false)
genInputImplementation(w, name, name, elementTypeName, false)
genMapOutput(w, strings.TrimSuffix(name, "Map"), elementTypeName, false)
genMapOutput(w, strings.TrimSuffix(name, "Map"), elementTypeName)
}
pkg.genInputInterface(w, name)
}
@ -2232,18 +2360,13 @@ func (pkg *pkgContext) genResourceRegistrations(w io.Writer, r *schema.Resource,
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sInput)(nil)).Elem(), &%[1]s{})\n",
name)
if generateResourceContainerTypes {
if generateResourceContainerTypes && !r.IsProvider {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sPtrInput)(nil)).Elem(), &%[1]s{})\n",
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sArrayInput)(nil)).Elem(), %[1]sArray{})\n",
name)
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sMapInput)(nil)).Elem(), %[1]sMap{})\n",
name)
if !r.IsProvider {
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sArrayInput)(nil)).Elem(), %[1]sArray{})\n",
name)
fmt.Fprintf(w,
"\tpulumi.RegisterInputType(reflect.TypeOf((*%[1]sMapInput)(nil)).Elem(), %[1]sMap{})\n",
name)
}
}
}
// Register all output types
@ -2258,12 +2381,9 @@ func (pkg *pkgContext) genResourceRegistrations(w io.Writer, r *schema.Resource,
}
}
if generateResourceContainerTypes {
fmt.Fprintf(w, "\tpulumi.RegisterOutputType(%sPtrOutput{})\n", name)
if !r.IsProvider {
fmt.Fprintf(w, "\tpulumi.RegisterOutputType(%sArrayOutput{})\n", name)
fmt.Fprintf(w, "\tpulumi.RegisterOutputType(%sMapOutput{})\n", name)
}
if generateResourceContainerTypes && !r.IsProvider {
fmt.Fprintf(w, "\tpulumi.RegisterOutputType(%sArrayOutput{})\n", name)
fmt.Fprintf(w, "\tpulumi.RegisterOutputType(%sMapOutput{})\n", name)
}
fmt.Fprintf(w, "}\n\n")
}
@ -2666,6 +2786,7 @@ func generatePackageContextMap(tool string, pkg *schema.Package, goInfo GoPackag
packages: packages,
liftSingleValueMethodReturns: goInfo.LiftSingleValueMethodReturns,
disableInputTypeRegistrations: goInfo.DisableInputTypeRegistrations,
disableObjectDefaults: goInfo.DisableObjectDefaults,
}
packages[mod] = pack
}
@ -2989,8 +3110,10 @@ func generatePackageContextMap(tool string, pkg *schema.Package, goInfo GoPackag
pkg.functions = append(pkg.functions, f)
name := tokenToName(f.Token)
originalName := name
if pkg.names.Has(name) {
if pkg.names.Has(name) ||
pkg.names.Has(name+"Args") ||
pkg.names.Has(name+"Result") {
switch {
case strings.HasPrefix(name, "New"):
name = "Create" + name[3:]
@ -3003,15 +3126,9 @@ func generatePackageContextMap(tool string, pkg *schema.Package, goInfo GoPackag
if f.Inputs != nil {
pkg.names.Add(name + "Args")
if originalName != name {
pkg.renamed[originalName+"Args"] = name + "Args"
}
}
if f.Outputs != nil {
pkg.names.Add(name + "Result")
if originalName != name {
pkg.renamed[originalName+"Result"] = name + "Result"
}
}
}
@ -3200,7 +3317,10 @@ func GeneratePackage(tool string, pkg *schema.Package) (map[string][]byte, error
}
fileName := path.Join(mod, camel(tokenToName(f.Token))+".go")
code := pkg.genFunctionCodeFile(f)
code, err := pkg.genFunctionCodeFile(f)
if err != nil {
return nil, err
}
setFile(fileName, code)
}
@ -3240,7 +3360,9 @@ func GeneratePackage(tool string, pkg *schema.Package) (map[string][]byte, error
pkg.genHeader(buffer, []string{"context", "reflect"}, importsAndAliases)
for _, t := range pkg.types {
pkg.genType(buffer, t)
if err := pkg.genType(buffer, t); err != nil {
return nil, err
}
delete(knownTypes, t)
}
@ -3376,4 +3498,12 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %%s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}
`

View file

@ -43,7 +43,9 @@ func CRDTypes(tool string, pkg *schema.Package) (map[string]*bytes.Buffer, error
if len(pkg.types) > 0 {
for _, t := range pkg.types {
pkg.genType(buffer, t)
if err := pkg.genType(buffer, t); err != nil {
return nil, err
}
}
pkg.genTypeRegistrations(buffer, pkg.types)
}

View file

@ -244,9 +244,7 @@ func (g *generator) collectImports(
}
pulumiImports.Add(g.getPulumiImport(pkg, vPath, mod))
} else if call.Name == pcl.IntrinsicConvert {
if schemaType, ok := pcl.GetSchemaForType(call.Type()); ok {
g.collectTypeImports(program, schemaType, pulumiImports)
}
g.collectConvertImports(program, call, pulumiImports)
}
// Checking to see if this function call deserves its own dedicated helper method in the preamble
@ -277,6 +275,30 @@ func (g *generator) collectImports(
return stdImports, pulumiImports, preambleHelperMethods
}
func (g *generator) collectConvertImports(
program *pcl.Program,
call *model.FunctionCallExpression,
pulumiImports codegen.StringSet) {
if schemaType, ok := pcl.GetSchemaForType(call.Type()); ok {
// Sometimes code for a `__convert` call does not
// really use the import of the result type. In such
// cases it is important not to generate a
// non-compiling unused import. Detect some of these
// cases here.
//
// Fully solving this is deferred for later:
// TODO[pulumi/pulumi#8324].
if expr, ok := call.Args[0].(*model.TemplateExpression); ok {
if lit, ok := expr.Parts[0].(*model.LiteralValueExpression); ok &&
model.StringType.AssignableFrom(lit.Type()) &&
call.Type().AssignableFrom(lit.Type()) {
return
}
}
g.collectTypeImports(program, schemaType, pulumiImports)
}
}
func (g *generator) getVersionPath(program *pcl.Program, pkg string) (string, error) {
for _, p := range program.Packages() {
if p.Name == pkg {
@ -614,11 +636,17 @@ func (g *generator) genLocalVariable(w io.Writer, v *pcl.LocalVariable) {
case *model.FunctionCallExpression:
switch expr.Name {
case pcl.Invoke:
g.Fgenf(w, "%s, err %s %.3v;\n", name, assignment, expr)
g.isErrAssigned = true
g.Fgenf(w, "if err != nil {\n")
g.Fgenf(w, "return err\n")
g.Fgenf(w, "}\n")
// OutputVersionedInvoke does not return an error
noError, _, _ := pcl.RecognizeOutputVersionedInvoke(expr)
if noError {
g.Fgenf(w, "%s %s %.3v;\n", name, assignment, expr)
} else {
g.Fgenf(w, "%s, err %s %.3v;\n", name, assignment, expr)
g.isErrAssigned = true
g.Fgenf(w, "if err != nil {\n")
g.Fgenf(w, "return err\n")
g.Fgenf(w, "}\n")
}
case "join", "toBase64", "mimeType", "fileAsset":
g.Fgenf(w, "%s := %.3v;\n", name, expr)
}

View file

@ -195,7 +195,18 @@ func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionC
if module == "" {
module = pkg
}
name := fmt.Sprintf("%s.%s", module, fn)
isOut, outArgs, outArgsType := pcl.RecognizeOutputVersionedInvoke(expr)
if isOut {
outTypeName, err := outputVersionFunctionArgTypeName(outArgsType)
if err != nil {
panic(fmt.Errorf("Error when generating an output-versioned Invoke: %w", err))
}
g.Fgenf(w, "%s.%sOutput(ctx, ", module, fn)
g.genObjectConsExpressionWithTypeName(w, outArgs, outArgsType, outTypeName)
} else {
g.Fgenf(w, "%s.%s(ctx, ", module, fn)
g.Fgenf(w, "%.v", expr.Args[1])
}
optionsBag := ""
var buf bytes.Buffer
@ -205,9 +216,6 @@ func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionC
g.Fgenf(&buf, ", nil")
}
optionsBag = buf.String()
g.Fgenf(w, "%s(ctx, ", name)
g.Fgenf(w, "%.v", expr.Args[1])
g.Fgenf(w, "%v)", optionsBag)
case "join":
g.Fgenf(w, "strings.Join(%v, %v)", expr.Args[1], expr.Args[0])
@ -246,6 +254,32 @@ func (g *generator) GenFunctionCallExpression(w io.Writer, expr *model.FunctionC
}
}
// Currently args type for output-versioned invokes are named
// `FOutputArgs`, but this is not yet understood by `tokenToType`. Use
// this function to compensate.
func outputVersionFunctionArgTypeName(t model.Type) (string, error) {
schemaType, ok := pcl.GetSchemaForType(t)
if !ok {
return "", fmt.Errorf("No schema.Type type found for the given model.Type")
}
objType, ok := schemaType.(*schema.ObjectType)
if !ok {
return "", fmt.Errorf("Expected a schema.ObjectType, got %s", schemaType.String())
}
pkg := &pkgContext{pkg: &schema.Package{Name: "main"}}
var ty string
if pkg.isExternalReference(objType) {
ty = pkg.contextForExternalReferenceType(objType).tokenToType(objType.Token)
} else {
ty = pkg.tokenToType(objType.Token)
}
return fmt.Sprintf("%sOutputArgs", strings.TrimSuffix(ty, "Args")), nil
}
func (g *generator) GenIndexExpression(w io.Writer, expr *model.IndexExpression) {
g.Fgenf(w, "%.20v[%.v]", expr.Collection, expr.Key)
}
@ -316,15 +350,10 @@ func (g *generator) genObjectConsExpression(
w io.Writer,
expr *model.ObjectConsExpression,
destType model.Type,
isInput bool,
) {
if len(expr.Items) == 0 {
g.Fgenf(w, "nil")
return
}
isInput bool) {
var temps []interface{}
isInput = isInput || isInputty(destType)
typeName := g.argumentTypeName(expr, destType, isInput)
if schemaType, ok := pcl.GetSchemaForType(destType); ok {
if obj, ok := codegen.UnwrapType(schemaType).(*schema.ObjectType); ok {
@ -334,6 +363,21 @@ func (g *generator) genObjectConsExpression(
}
}
g.genObjectConsExpressionWithTypeName(w, expr, destType, typeName)
}
func (g *generator) genObjectConsExpressionWithTypeName(
w io.Writer,
expr *model.ObjectConsExpression,
destType model.Type,
typeName string) {
if len(expr.Items) == 0 {
g.Fgenf(w, "nil")
return
}
var temps []interface{}
// TODO: @pgavlin --- ineffectual assignment, was there some work in flight here?
// if strings.HasSuffix(typeName, "Args") {
// isInput = true
@ -360,7 +404,7 @@ func (g *generator) genObjectConsExpression(
}
g.genTemps(w, temps)
if isMap || !strings.HasSuffix(typeName, "Args") {
if isMap || !strings.HasSuffix(typeName, "Args") || strings.HasSuffix(typeName, "OutputArgs") {
g.Fgenf(w, "%s", typeName)
} else {
g.Fgenf(w, "&%s", typeName)
@ -814,9 +858,15 @@ func (g *generator) genApply(w io.Writer, expr *model.FunctionCallExpression) {
isInput := false
retType := g.argumentTypeName(nil, then.Signature.ReturnType, isInput)
// TODO account for outputs in other namespaces like aws
typeAssertion := fmt.Sprintf(".(%sOutput)", retType)
if !strings.HasPrefix(retType, "pulumi.") {
typeAssertion = fmt.Sprintf(".(pulumi.%sOutput)", Title(retType))
// TODO[pulumi/pulumi#8453] incomplete pattern code below.
var typeAssertion string
if retType == "[]string" {
typeAssertion = ".(pulumi.StringArrayOutput)"
} else {
typeAssertion = fmt.Sprintf(".(%sOutput)", retType)
if !strings.HasPrefix(retType, "pulumi.") {
typeAssertion = fmt.Sprintf(".(pulumi.%sOutput)", Title(retType))
}
}
if len(applyArgs) == 1 {

View file

@ -44,7 +44,9 @@ func (os *optionalSpiller) spillExpressionHelper(
case *model.FunctionCallExpression:
if x.Name == "invoke" {
// recurse into invoke args
isInvoke = true
isOutputInvoke, _, _ := pcl.RecognizeOutputVersionedInvoke(x)
// ignore output-versioned invokes as they do not need converting
isInvoke = !isOutputInvoke
_, diags := os.spillExpressionHelper(x.Args[1], x.Args[1].Type(), isInvoke)
return x, diags
}

View file

@ -60,6 +60,10 @@ type GoPackageInfo struct {
// Feature flag to disable generating input type registration. This is a
// space saving measure.
DisableInputTypeRegistrations bool `json:"disableInputTypeRegistrations,omitempty"`
// Feature flag to disable generating Pulumi object default functions. This is a
// space saving measure.
DisableObjectDefaults bool `json:"disableObjectDefaults,omitempty"`
}
// Importer implements schema.Language for Go.

View file

@ -49,8 +49,9 @@ var programTests = []programTest{
{
Name: "aws-fargate",
Description: "AWS Fargate",
// TODO[pulumi/pulumi#8440]
SkipCompile: codegen.NewStringSet("go"),
Skip: codegen.NewStringSet("go", "python", "dotnet"),
},
{
Name: "aws-s3-logging",
@ -127,7 +128,6 @@ var programTests = []programTest{
{
Name: "output-funcs-aws",
Description: "Output Versioned Functions",
Skip: codegen.NewStringSet("go", "python", "dotnet"),
},
}

View file

@ -192,11 +192,22 @@ var sdkTests = []sdkTest{
SkipCompileCheck: codegen.NewStringSet(nodejs),
},
{
Directory: "env-helper",
Description: "Ensure that eviromental helpers are generated (repro #8132)",
Directory: "plain-object-defaults",
Description: "Ensure that object defaults are generated (repro #8132)",
Skip: codegen.NewStringSet("python/test", "nodejs/test"),
SkipCompileCheck: codegen.NewStringSet(dotnet),
},
{
Directory: "plain-object-disable-defaults",
Description: "Ensure that we can still compile safely when defaults are disabled",
Skip: codegen.NewStringSet("python/test", "nodejs/test"),
SkipCompileCheck: codegen.NewStringSet(dotnet),
},
{
Directory: "regress-8403",
Description: "Regress pulumi/pulumi#8403",
SkipCompileCheck: codegen.NewStringSet(dotnet, python, nodejs),
},
}
var genSDKOnly bool

View file

@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ecs"
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/elasticloadbalancingv2"

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -76,7 +76,7 @@ type ModuleResourceInput interface {
}
func (*ModuleResource) ElementType() reflect.Type {
return reflect.TypeOf((*ModuleResource)(nil))
return reflect.TypeOf((**ModuleResource)(nil)).Elem()
}
func (i *ModuleResource) ToModuleResourceOutput() ModuleResourceOutput {
@ -90,7 +90,7 @@ func (i *ModuleResource) ToModuleResourceOutputWithContext(ctx context.Context)
type ModuleResourceOutput struct{ *pulumi.OutputState }
func (ModuleResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*ModuleResource)(nil))
return reflect.TypeOf((**ModuleResource)(nil)).Elem()
}
func (o ModuleResourceOutput) ToModuleResourceOutput() ModuleResourceOutput {

View file

@ -9,6 +9,7 @@
"plant-provider/tree/v1/init.go",
"plant-provider/tree/v1/nursery.go",
"plant-provider/tree/v1/pulumiEnums.go",
"plant-provider/tree/v1/pulumiUtilities.go",
"plant-provider/tree/v1/rubberTree.go"
]
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -17,6 +17,19 @@ type Container struct {
Size ContainerSize `pulumi:"size"`
}
// Defaults sets the appropriate defaults for Container
func (val *Container) Defaults() *Container {
if val == nil {
return nil
}
tmp := *val
if isZero(tmp.Brightness) {
brightness_ := ContainerBrightness(1.0)
tmp.Brightness = &brightness_
}
return &tmp
}
// ContainerInput is an input type that accepts ContainerArgs and ContainerOutput values.
// You can construct a concrete instance of `ContainerInput` via:
//

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -83,7 +83,7 @@ type NurseryInput interface {
}
func (*Nursery) ElementType() reflect.Type {
return reflect.TypeOf((*Nursery)(nil))
return reflect.TypeOf((**Nursery)(nil)).Elem()
}
func (i *Nursery) ToNurseryOutput() NurseryOutput {
@ -97,7 +97,7 @@ func (i *Nursery) ToNurseryOutputWithContext(ctx context.Context) NurseryOutput
type NurseryOutput struct{ *pulumi.OutputState }
func (NurseryOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Nursery)(nil))
return reflect.TypeOf((**Nursery)(nil)).Elem()
}
func (o NurseryOutput) ToNurseryOutput() NurseryOutput {

View file

@ -0,0 +1,85 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package v1
import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"github.com/blang/semver"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type envParser func(v string) interface{}
func parseEnvBool(v string) interface{} {
b, err := strconv.ParseBool(v)
if err != nil {
return nil
}
return b
}
func parseEnvInt(v string) interface{} {
i, err := strconv.ParseInt(v, 0, 0)
if err != nil {
return nil
}
return int(i)
}
func parseEnvFloat(v string) interface{} {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return nil
}
return f
}
func parseEnvStringArray(v string) interface{} {
var result pulumi.StringArray
for _, item := range strings.Split(v, ";") {
result = append(result, pulumi.String(item))
}
return result
}
func getEnvOrDefault(def interface{}, parser envParser, vars ...string) interface{} {
for _, v := range vars {
if value := os.Getenv(v); value != "" {
if parser != nil {
return parser(value)
}
return value
}
}
return def
}
// PkgVersion uses reflection to determine the version of the current package.
func PkgVersion() (semver.Version, error) {
type sentinal struct{}
pkgPath := reflect.TypeOf(sentinal{}).PkgPath()
re := regexp.MustCompile("^.*/pulumi-plant/sdk(/v\\d+)?")
if match := re.FindStringSubmatch(pkgPath); match != nil {
vStr := match[1]
if len(vStr) == 0 { // If the version capture group was empty, default to v1.
return semver.Version{Major: 1}, nil
}
return semver.MustParse(fmt.Sprintf("%s.0.0", vStr[2:])), nil
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -29,16 +29,20 @@ func NewRubberTree(ctx *pulumi.Context,
return nil, errors.New("missing one or more required arguments")
}
if args.Diameter == nil {
containerApplier := func(v plantprovider.Container) *plantprovider.Container { return v.Defaults() }
if args.Container != nil {
args.Container = args.Container.ToContainerPtrOutput().Elem().ApplyT(containerApplier).(plantprovider.ContainerPtrOutput)
}
if isZero(args.Diameter) {
args.Diameter = Diameter(6.0)
}
if args.Farm == nil {
if isZero(args.Farm) {
args.Farm = pulumi.StringPtr("(unknown)")
}
if args.Size == nil {
if isZero(args.Size) {
args.Size = TreeSize("medium")
}
if args.Type == nil {
if isZero(args.Type) {
args.Type = RubberTreeVariety("Burgundy")
}
var resource RubberTree
@ -103,7 +107,7 @@ type RubberTreeInput interface {
}
func (*RubberTree) ElementType() reflect.Type {
return reflect.TypeOf((*RubberTree)(nil))
return reflect.TypeOf((**RubberTree)(nil)).Elem()
}
func (i *RubberTree) ToRubberTreeOutput() RubberTreeOutput {
@ -117,7 +121,7 @@ func (i *RubberTree) ToRubberTreeOutputWithContext(ctx context.Context) RubberTr
type RubberTreeOutput struct{ *pulumi.OutputState }
func (RubberTreeOutput) ElementType() reflect.Type {
return reflect.TypeOf((*RubberTree)(nil))
return reflect.TypeOf((**RubberTree)(nil)).Elem()
}
func (o RubberTreeOutput) ToRubberTreeOutput() RubberTreeOutput {

View file

@ -77,7 +77,7 @@ type CatInput interface {
}
func (*Cat) ElementType() reflect.Type {
return reflect.TypeOf((*Cat)(nil))
return reflect.TypeOf((**Cat)(nil)).Elem()
}
func (i *Cat) ToCatOutput() CatOutput {
@ -88,35 +88,6 @@ func (i *Cat) ToCatOutputWithContext(ctx context.Context) CatOutput {
return pulumi.ToOutputWithContext(ctx, i).(CatOutput)
}
func (i *Cat) ToCatPtrOutput() CatPtrOutput {
return i.ToCatPtrOutputWithContext(context.Background())
}
func (i *Cat) ToCatPtrOutputWithContext(ctx context.Context) CatPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(CatPtrOutput)
}
type CatPtrInput interface {
pulumi.Input
ToCatPtrOutput() CatPtrOutput
ToCatPtrOutputWithContext(ctx context.Context) CatPtrOutput
}
type catPtrType CatArgs
func (*catPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Cat)(nil))
}
func (i *catPtrType) ToCatPtrOutput() CatPtrOutput {
return i.ToCatPtrOutputWithContext(context.Background())
}
func (i *catPtrType) ToCatPtrOutputWithContext(ctx context.Context) CatPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(CatPtrOutput)
}
// CatArrayInput is an input type that accepts CatArray and CatArrayOutput values.
// You can construct a concrete instance of `CatArrayInput` via:
//
@ -170,7 +141,7 @@ func (i CatMap) ToCatMapOutputWithContext(ctx context.Context) CatMapOutput {
type CatOutput struct{ *pulumi.OutputState }
func (CatOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Cat)(nil))
return reflect.TypeOf((**Cat)(nil)).Elem()
}
func (o CatOutput) ToCatOutput() CatOutput {
@ -181,44 +152,10 @@ func (o CatOutput) ToCatOutputWithContext(ctx context.Context) CatOutput {
return o
}
func (o CatOutput) ToCatPtrOutput() CatPtrOutput {
return o.ToCatPtrOutputWithContext(context.Background())
}
func (o CatOutput) ToCatPtrOutputWithContext(ctx context.Context) CatPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Cat) *Cat {
return &v
}).(CatPtrOutput)
}
type CatPtrOutput struct{ *pulumi.OutputState }
func (CatPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Cat)(nil))
}
func (o CatPtrOutput) ToCatPtrOutput() CatPtrOutput {
return o
}
func (o CatPtrOutput) ToCatPtrOutputWithContext(ctx context.Context) CatPtrOutput {
return o
}
func (o CatPtrOutput) Elem() CatOutput {
return o.ApplyT(func(v *Cat) Cat {
if v != nil {
return *v
}
var ret Cat
return ret
}).(CatOutput)
}
type CatArrayOutput struct{ *pulumi.OutputState }
func (CatArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Cat)(nil))
return reflect.TypeOf((*[]*Cat)(nil)).Elem()
}
func (o CatArrayOutput) ToCatArrayOutput() CatArrayOutput {
@ -230,15 +167,15 @@ func (o CatArrayOutput) ToCatArrayOutputWithContext(ctx context.Context) CatArra
}
func (o CatArrayOutput) Index(i pulumi.IntInput) CatOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) Cat {
return vs[0].([]Cat)[vs[1].(int)]
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Cat {
return vs[0].([]*Cat)[vs[1].(int)]
}).(CatOutput)
}
type CatMapOutput struct{ *pulumi.OutputState }
func (CatMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]Cat)(nil))
return reflect.TypeOf((*map[string]*Cat)(nil)).Elem()
}
func (o CatMapOutput) ToCatMapOutput() CatMapOutput {
@ -250,18 +187,16 @@ func (o CatMapOutput) ToCatMapOutputWithContext(ctx context.Context) CatMapOutpu
}
func (o CatMapOutput) MapIndex(k pulumi.StringInput) CatOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) Cat {
return vs[0].(map[string]Cat)[vs[1].(string)]
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Cat {
return vs[0].(map[string]*Cat)[vs[1].(string)]
}).(CatOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*CatInput)(nil)).Elem(), &Cat{})
pulumi.RegisterInputType(reflect.TypeOf((*CatPtrInput)(nil)).Elem(), &Cat{})
pulumi.RegisterInputType(reflect.TypeOf((*CatArrayInput)(nil)).Elem(), CatArray{})
pulumi.RegisterInputType(reflect.TypeOf((*CatMapInput)(nil)).Elem(), CatMap{})
pulumi.RegisterOutputType(CatOutput{})
pulumi.RegisterOutputType(CatPtrOutput{})
pulumi.RegisterOutputType(CatArrayOutput{})
pulumi.RegisterOutputType(CatMapOutput{})
}

View file

@ -101,7 +101,7 @@ type ComponentInput interface {
}
func (*Component) ElementType() reflect.Type {
return reflect.TypeOf((*Component)(nil))
return reflect.TypeOf((**Component)(nil)).Elem()
}
func (i *Component) ToComponentOutput() ComponentOutput {
@ -112,35 +112,6 @@ func (i *Component) ToComponentOutputWithContext(ctx context.Context) ComponentO
return pulumi.ToOutputWithContext(ctx, i).(ComponentOutput)
}
func (i *Component) ToComponentPtrOutput() ComponentPtrOutput {
return i.ToComponentPtrOutputWithContext(context.Background())
}
func (i *Component) ToComponentPtrOutputWithContext(ctx context.Context) ComponentPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ComponentPtrOutput)
}
type ComponentPtrInput interface {
pulumi.Input
ToComponentPtrOutput() ComponentPtrOutput
ToComponentPtrOutputWithContext(ctx context.Context) ComponentPtrOutput
}
type componentPtrType ComponentArgs
func (*componentPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Component)(nil))
}
func (i *componentPtrType) ToComponentPtrOutput() ComponentPtrOutput {
return i.ToComponentPtrOutputWithContext(context.Background())
}
func (i *componentPtrType) ToComponentPtrOutputWithContext(ctx context.Context) ComponentPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ComponentPtrOutput)
}
// ComponentArrayInput is an input type that accepts ComponentArray and ComponentArrayOutput values.
// You can construct a concrete instance of `ComponentArrayInput` via:
//
@ -194,7 +165,7 @@ func (i ComponentMap) ToComponentMapOutputWithContext(ctx context.Context) Compo
type ComponentOutput struct{ *pulumi.OutputState }
func (ComponentOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Component)(nil))
return reflect.TypeOf((**Component)(nil)).Elem()
}
func (o ComponentOutput) ToComponentOutput() ComponentOutput {
@ -205,44 +176,10 @@ func (o ComponentOutput) ToComponentOutputWithContext(ctx context.Context) Compo
return o
}
func (o ComponentOutput) ToComponentPtrOutput() ComponentPtrOutput {
return o.ToComponentPtrOutputWithContext(context.Background())
}
func (o ComponentOutput) ToComponentPtrOutputWithContext(ctx context.Context) ComponentPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Component) *Component {
return &v
}).(ComponentPtrOutput)
}
type ComponentPtrOutput struct{ *pulumi.OutputState }
func (ComponentPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Component)(nil))
}
func (o ComponentPtrOutput) ToComponentPtrOutput() ComponentPtrOutput {
return o
}
func (o ComponentPtrOutput) ToComponentPtrOutputWithContext(ctx context.Context) ComponentPtrOutput {
return o
}
func (o ComponentPtrOutput) Elem() ComponentOutput {
return o.ApplyT(func(v *Component) Component {
if v != nil {
return *v
}
var ret Component
return ret
}).(ComponentOutput)
}
type ComponentArrayOutput struct{ *pulumi.OutputState }
func (ComponentArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Component)(nil))
return reflect.TypeOf((*[]*Component)(nil)).Elem()
}
func (o ComponentArrayOutput) ToComponentArrayOutput() ComponentArrayOutput {
@ -254,15 +191,15 @@ func (o ComponentArrayOutput) ToComponentArrayOutputWithContext(ctx context.Cont
}
func (o ComponentArrayOutput) Index(i pulumi.IntInput) ComponentOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) Component {
return vs[0].([]Component)[vs[1].(int)]
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Component {
return vs[0].([]*Component)[vs[1].(int)]
}).(ComponentOutput)
}
type ComponentMapOutput struct{ *pulumi.OutputState }
func (ComponentMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]Component)(nil))
return reflect.TypeOf((*map[string]*Component)(nil)).Elem()
}
func (o ComponentMapOutput) ToComponentMapOutput() ComponentMapOutput {
@ -274,18 +211,16 @@ func (o ComponentMapOutput) ToComponentMapOutputWithContext(ctx context.Context)
}
func (o ComponentMapOutput) MapIndex(k pulumi.StringInput) ComponentOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) Component {
return vs[0].(map[string]Component)[vs[1].(string)]
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Component {
return vs[0].(map[string]*Component)[vs[1].(string)]
}).(ComponentOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*ComponentInput)(nil)).Elem(), &Component{})
pulumi.RegisterInputType(reflect.TypeOf((*ComponentPtrInput)(nil)).Elem(), &Component{})
pulumi.RegisterInputType(reflect.TypeOf((*ComponentArrayInput)(nil)).Elem(), ComponentArray{})
pulumi.RegisterInputType(reflect.TypeOf((*ComponentMapInput)(nil)).Elem(), ComponentMap{})
pulumi.RegisterOutputType(ComponentOutput{})
pulumi.RegisterOutputType(ComponentPtrOutput{})
pulumi.RegisterOutputType(ComponentArrayOutput{})
pulumi.RegisterOutputType(ComponentMapOutput{})
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -59,39 +59,10 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
return pulumi.ToOutputWithContext(ctx, i).(ProviderOutput)
}
func (i *Provider) ToProviderPtrOutput() ProviderPtrOutput {
return i.ToProviderPtrOutputWithContext(context.Background())
}
func (i *Provider) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ProviderPtrOutput)
}
type ProviderPtrInput interface {
pulumi.Input
ToProviderPtrOutput() ProviderPtrOutput
ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput
}
type providerPtrType ProviderArgs
func (*providerPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Provider)(nil))
}
func (i *providerPtrType) ToProviderPtrOutput() ProviderPtrOutput {
return i.ToProviderPtrOutputWithContext(context.Background())
}
func (i *providerPtrType) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ProviderPtrOutput)
}
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {
@ -102,43 +73,7 @@ func (o ProviderOutput) ToProviderOutputWithContext(ctx context.Context) Provide
return o
}
func (o ProviderOutput) ToProviderPtrOutput() ProviderPtrOutput {
return o.ToProviderPtrOutputWithContext(context.Background())
}
func (o ProviderOutput) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Provider) *Provider {
return &v
}).(ProviderPtrOutput)
}
type ProviderPtrOutput struct{ *pulumi.OutputState }
func (ProviderPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Provider)(nil))
}
func (o ProviderPtrOutput) ToProviderPtrOutput() ProviderPtrOutput {
return o
}
func (o ProviderPtrOutput) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return o
}
func (o ProviderPtrOutput) Elem() ProviderOutput {
return o.ApplyT(func(v *Provider) Provider {
if v != nil {
return *v
}
var ret Provider
return ret
}).(ProviderOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*ProviderInput)(nil)).Elem(), &Provider{})
pulumi.RegisterInputType(reflect.TypeOf((*ProviderPtrInput)(nil)).Elem(), &Provider{})
pulumi.RegisterOutputType(ProviderOutput{})
pulumi.RegisterOutputType(ProviderPtrOutput{})
}

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -74,7 +74,7 @@ type WorkloadInput interface {
}
func (*Workload) ElementType() reflect.Type {
return reflect.TypeOf((*Workload)(nil))
return reflect.TypeOf((**Workload)(nil)).Elem()
}
func (i *Workload) ToWorkloadOutput() WorkloadOutput {
@ -85,35 +85,6 @@ func (i *Workload) ToWorkloadOutputWithContext(ctx context.Context) WorkloadOutp
return pulumi.ToOutputWithContext(ctx, i).(WorkloadOutput)
}
func (i *Workload) ToWorkloadPtrOutput() WorkloadPtrOutput {
return i.ToWorkloadPtrOutputWithContext(context.Background())
}
func (i *Workload) ToWorkloadPtrOutputWithContext(ctx context.Context) WorkloadPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(WorkloadPtrOutput)
}
type WorkloadPtrInput interface {
pulumi.Input
ToWorkloadPtrOutput() WorkloadPtrOutput
ToWorkloadPtrOutputWithContext(ctx context.Context) WorkloadPtrOutput
}
type workloadPtrType WorkloadArgs
func (*workloadPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Workload)(nil))
}
func (i *workloadPtrType) ToWorkloadPtrOutput() WorkloadPtrOutput {
return i.ToWorkloadPtrOutputWithContext(context.Background())
}
func (i *workloadPtrType) ToWorkloadPtrOutputWithContext(ctx context.Context) WorkloadPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(WorkloadPtrOutput)
}
// WorkloadArrayInput is an input type that accepts WorkloadArray and WorkloadArrayOutput values.
// You can construct a concrete instance of `WorkloadArrayInput` via:
//
@ -167,7 +138,7 @@ func (i WorkloadMap) ToWorkloadMapOutputWithContext(ctx context.Context) Workloa
type WorkloadOutput struct{ *pulumi.OutputState }
func (WorkloadOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Workload)(nil))
return reflect.TypeOf((**Workload)(nil)).Elem()
}
func (o WorkloadOutput) ToWorkloadOutput() WorkloadOutput {
@ -178,44 +149,10 @@ func (o WorkloadOutput) ToWorkloadOutputWithContext(ctx context.Context) Workloa
return o
}
func (o WorkloadOutput) ToWorkloadPtrOutput() WorkloadPtrOutput {
return o.ToWorkloadPtrOutputWithContext(context.Background())
}
func (o WorkloadOutput) ToWorkloadPtrOutputWithContext(ctx context.Context) WorkloadPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Workload) *Workload {
return &v
}).(WorkloadPtrOutput)
}
type WorkloadPtrOutput struct{ *pulumi.OutputState }
func (WorkloadPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Workload)(nil))
}
func (o WorkloadPtrOutput) ToWorkloadPtrOutput() WorkloadPtrOutput {
return o
}
func (o WorkloadPtrOutput) ToWorkloadPtrOutputWithContext(ctx context.Context) WorkloadPtrOutput {
return o
}
func (o WorkloadPtrOutput) Elem() WorkloadOutput {
return o.ApplyT(func(v *Workload) Workload {
if v != nil {
return *v
}
var ret Workload
return ret
}).(WorkloadOutput)
}
type WorkloadArrayOutput struct{ *pulumi.OutputState }
func (WorkloadArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]Workload)(nil))
return reflect.TypeOf((*[]*Workload)(nil)).Elem()
}
func (o WorkloadArrayOutput) ToWorkloadArrayOutput() WorkloadArrayOutput {
@ -227,15 +164,15 @@ func (o WorkloadArrayOutput) ToWorkloadArrayOutputWithContext(ctx context.Contex
}
func (o WorkloadArrayOutput) Index(i pulumi.IntInput) WorkloadOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) Workload {
return vs[0].([]Workload)[vs[1].(int)]
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Workload {
return vs[0].([]*Workload)[vs[1].(int)]
}).(WorkloadOutput)
}
type WorkloadMapOutput struct{ *pulumi.OutputState }
func (WorkloadMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]Workload)(nil))
return reflect.TypeOf((*map[string]*Workload)(nil)).Elem()
}
func (o WorkloadMapOutput) ToWorkloadMapOutput() WorkloadMapOutput {
@ -247,18 +184,16 @@ func (o WorkloadMapOutput) ToWorkloadMapOutputWithContext(ctx context.Context) W
}
func (o WorkloadMapOutput) MapIndex(k pulumi.StringInput) WorkloadOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) Workload {
return vs[0].(map[string]Workload)[vs[1].(string)]
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Workload {
return vs[0].(map[string]*Workload)[vs[1].(string)]
}).(WorkloadOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*WorkloadInput)(nil)).Elem(), &Workload{})
pulumi.RegisterInputType(reflect.TypeOf((*WorkloadPtrInput)(nil)).Elem(), &Workload{})
pulumi.RegisterInputType(reflect.TypeOf((*WorkloadArrayInput)(nil)).Elem(), WorkloadArray{})
pulumi.RegisterInputType(reflect.TypeOf((*WorkloadMapInput)(nil)).Elem(), WorkloadMap{})
pulumi.RegisterOutputType(WorkloadOutput{})
pulumi.RegisterOutputType(WorkloadPtrOutput{})
pulumi.RegisterOutputType(WorkloadArrayOutput{})
pulumi.RegisterOutputType(WorkloadMapOutput{})
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -59,39 +59,10 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
return pulumi.ToOutputWithContext(ctx, i).(ProviderOutput)
}
func (i *Provider) ToProviderPtrOutput() ProviderPtrOutput {
return i.ToProviderPtrOutputWithContext(context.Background())
}
func (i *Provider) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ProviderPtrOutput)
}
type ProviderPtrInput interface {
pulumi.Input
ToProviderPtrOutput() ProviderPtrOutput
ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput
}
type providerPtrType ProviderArgs
func (*providerPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Provider)(nil))
}
func (i *providerPtrType) ToProviderPtrOutput() ProviderPtrOutput {
return i.ToProviderPtrOutputWithContext(context.Background())
}
func (i *providerPtrType) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(ProviderPtrOutput)
}
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {
@ -102,43 +73,7 @@ func (o ProviderOutput) ToProviderOutputWithContext(ctx context.Context) Provide
return o
}
func (o ProviderOutput) ToProviderPtrOutput() ProviderPtrOutput {
return o.ToProviderPtrOutputWithContext(context.Background())
}
func (o ProviderOutput) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Provider) *Provider {
return &v
}).(ProviderPtrOutput)
}
type ProviderPtrOutput struct{ *pulumi.OutputState }
func (ProviderPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Provider)(nil))
}
func (o ProviderPtrOutput) ToProviderPtrOutput() ProviderPtrOutput {
return o
}
func (o ProviderPtrOutput) ToProviderPtrOutputWithContext(ctx context.Context) ProviderPtrOutput {
return o
}
func (o ProviderPtrOutput) Elem() ProviderOutput {
return o.ApplyT(func(v *Provider) Provider {
if v != nil {
return *v
}
var ret Provider
return ret
}).(ProviderOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*ProviderInput)(nil)).Elem(), &Provider{})
pulumi.RegisterInputType(reflect.TypeOf((*ProviderPtrInput)(nil)).Elem(), &Provider{})
pulumi.RegisterOutputType(ProviderOutput{})
pulumi.RegisterOutputType(ProviderPtrOutput{})
}

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -65,7 +65,7 @@ type RegistryGeoReplicationInput interface {
}
func (*RegistryGeoReplication) ElementType() reflect.Type {
return reflect.TypeOf((*RegistryGeoReplication)(nil))
return reflect.TypeOf((**RegistryGeoReplication)(nil)).Elem()
}
func (i *RegistryGeoReplication) ToRegistryGeoReplicationOutput() RegistryGeoReplicationOutput {
@ -76,35 +76,6 @@ func (i *RegistryGeoReplication) ToRegistryGeoReplicationOutputWithContext(ctx c
return pulumi.ToOutputWithContext(ctx, i).(RegistryGeoReplicationOutput)
}
func (i *RegistryGeoReplication) ToRegistryGeoReplicationPtrOutput() RegistryGeoReplicationPtrOutput {
return i.ToRegistryGeoReplicationPtrOutputWithContext(context.Background())
}
func (i *RegistryGeoReplication) ToRegistryGeoReplicationPtrOutputWithContext(ctx context.Context) RegistryGeoReplicationPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(RegistryGeoReplicationPtrOutput)
}
type RegistryGeoReplicationPtrInput interface {
pulumi.Input
ToRegistryGeoReplicationPtrOutput() RegistryGeoReplicationPtrOutput
ToRegistryGeoReplicationPtrOutputWithContext(ctx context.Context) RegistryGeoReplicationPtrOutput
}
type registryGeoReplicationPtrType RegistryGeoReplicationArgs
func (*registryGeoReplicationPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**RegistryGeoReplication)(nil))
}
func (i *registryGeoReplicationPtrType) ToRegistryGeoReplicationPtrOutput() RegistryGeoReplicationPtrOutput {
return i.ToRegistryGeoReplicationPtrOutputWithContext(context.Background())
}
func (i *registryGeoReplicationPtrType) ToRegistryGeoReplicationPtrOutputWithContext(ctx context.Context) RegistryGeoReplicationPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(RegistryGeoReplicationPtrOutput)
}
// RegistryGeoReplicationArrayInput is an input type that accepts RegistryGeoReplicationArray and RegistryGeoReplicationArrayOutput values.
// You can construct a concrete instance of `RegistryGeoReplicationArrayInput` via:
//
@ -158,7 +129,7 @@ func (i RegistryGeoReplicationMap) ToRegistryGeoReplicationMapOutputWithContext(
type RegistryGeoReplicationOutput struct{ *pulumi.OutputState }
func (RegistryGeoReplicationOutput) ElementType() reflect.Type {
return reflect.TypeOf((*RegistryGeoReplication)(nil))
return reflect.TypeOf((**RegistryGeoReplication)(nil)).Elem()
}
func (o RegistryGeoReplicationOutput) ToRegistryGeoReplicationOutput() RegistryGeoReplicationOutput {
@ -169,44 +140,10 @@ func (o RegistryGeoReplicationOutput) ToRegistryGeoReplicationOutputWithContext(
return o
}
func (o RegistryGeoReplicationOutput) ToRegistryGeoReplicationPtrOutput() RegistryGeoReplicationPtrOutput {
return o.ToRegistryGeoReplicationPtrOutputWithContext(context.Background())
}
func (o RegistryGeoReplicationOutput) ToRegistryGeoReplicationPtrOutputWithContext(ctx context.Context) RegistryGeoReplicationPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v RegistryGeoReplication) *RegistryGeoReplication {
return &v
}).(RegistryGeoReplicationPtrOutput)
}
type RegistryGeoReplicationPtrOutput struct{ *pulumi.OutputState }
func (RegistryGeoReplicationPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**RegistryGeoReplication)(nil))
}
func (o RegistryGeoReplicationPtrOutput) ToRegistryGeoReplicationPtrOutput() RegistryGeoReplicationPtrOutput {
return o
}
func (o RegistryGeoReplicationPtrOutput) ToRegistryGeoReplicationPtrOutputWithContext(ctx context.Context) RegistryGeoReplicationPtrOutput {
return o
}
func (o RegistryGeoReplicationPtrOutput) Elem() RegistryGeoReplicationOutput {
return o.ApplyT(func(v *RegistryGeoReplication) RegistryGeoReplication {
if v != nil {
return *v
}
var ret RegistryGeoReplication
return ret
}).(RegistryGeoReplicationOutput)
}
type RegistryGeoReplicationArrayOutput struct{ *pulumi.OutputState }
func (RegistryGeoReplicationArrayOutput) ElementType() reflect.Type {
return reflect.TypeOf((*[]RegistryGeoReplication)(nil))
return reflect.TypeOf((*[]*RegistryGeoReplication)(nil)).Elem()
}
func (o RegistryGeoReplicationArrayOutput) ToRegistryGeoReplicationArrayOutput() RegistryGeoReplicationArrayOutput {
@ -218,15 +155,15 @@ func (o RegistryGeoReplicationArrayOutput) ToRegistryGeoReplicationArrayOutputWi
}
func (o RegistryGeoReplicationArrayOutput) Index(i pulumi.IntInput) RegistryGeoReplicationOutput {
return pulumi.All(o, i).ApplyT(func(vs []interface{}) RegistryGeoReplication {
return vs[0].([]RegistryGeoReplication)[vs[1].(int)]
return pulumi.All(o, i).ApplyT(func(vs []interface{}) *RegistryGeoReplication {
return vs[0].([]*RegistryGeoReplication)[vs[1].(int)]
}).(RegistryGeoReplicationOutput)
}
type RegistryGeoReplicationMapOutput struct{ *pulumi.OutputState }
func (RegistryGeoReplicationMapOutput) ElementType() reflect.Type {
return reflect.TypeOf((*map[string]RegistryGeoReplication)(nil))
return reflect.TypeOf((*map[string]*RegistryGeoReplication)(nil)).Elem()
}
func (o RegistryGeoReplicationMapOutput) ToRegistryGeoReplicationMapOutput() RegistryGeoReplicationMapOutput {
@ -238,18 +175,16 @@ func (o RegistryGeoReplicationMapOutput) ToRegistryGeoReplicationMapOutputWithCo
}
func (o RegistryGeoReplicationMapOutput) MapIndex(k pulumi.StringInput) RegistryGeoReplicationOutput {
return pulumi.All(o, k).ApplyT(func(vs []interface{}) RegistryGeoReplication {
return vs[0].(map[string]RegistryGeoReplication)[vs[1].(string)]
return pulumi.All(o, k).ApplyT(func(vs []interface{}) *RegistryGeoReplication {
return vs[0].(map[string]*RegistryGeoReplication)[vs[1].(string)]
}).(RegistryGeoReplicationOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*RegistryGeoReplicationInput)(nil)).Elem(), &RegistryGeoReplication{})
pulumi.RegisterInputType(reflect.TypeOf((*RegistryGeoReplicationPtrInput)(nil)).Elem(), &RegistryGeoReplication{})
pulumi.RegisterInputType(reflect.TypeOf((*RegistryGeoReplicationArrayInput)(nil)).Elem(), RegistryGeoReplicationArray{})
pulumi.RegisterInputType(reflect.TypeOf((*RegistryGeoReplicationMapInput)(nil)).Elem(), RegistryGeoReplicationMap{})
pulumi.RegisterOutputType(RegistryGeoReplicationOutput{})
pulumi.RegisterOutputType(RegistryGeoReplicationPtrOutput{})
pulumi.RegisterOutputType(RegistryGeoReplicationArrayOutput{})
pulumi.RegisterOutputType(RegistryGeoReplicationMapOutput{})
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -73,7 +73,7 @@ type ResourceInput interface {
}
func (*Resource) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (i *Resource) ToResourceOutput() ResourceOutput {
@ -87,7 +87,7 @@ func (i *Resource) ToResourceOutputWithContext(ctx context.Context) ResourceOutp
type ResourceOutput struct{ *pulumi.OutputState }
func (ResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (o ResourceOutput) ToResourceOutput() ResourceOutput {

View file

@ -73,7 +73,7 @@ type ResourceInputResourceInput interface {
}
func (*ResourceInputResource) ElementType() reflect.Type {
return reflect.TypeOf((*ResourceInputResource)(nil))
return reflect.TypeOf((**ResourceInputResource)(nil)).Elem()
}
func (i *ResourceInputResource) ToResourceInputResourceOutput() ResourceInputResourceOutput {
@ -87,7 +87,7 @@ func (i *ResourceInputResource) ToResourceInputResourceOutputWithContext(ctx con
type ResourceInputResourceOutput struct{ *pulumi.OutputState }
func (ResourceInputResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*ResourceInputResource)(nil))
return reflect.TypeOf((**ResourceInputResource)(nil)).Elem()
}
func (o ResourceInputResourceOutput) ToResourceInputResourceOutput() ResourceInputResourceOutput {

View file

@ -82,7 +82,7 @@ type ResourceInput interface {
}
func (*Resource) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (i *Resource) ToResourceOutput() ResourceOutput {
@ -96,7 +96,7 @@ func (i *Resource) ToResourceOutputWithContext(ctx context.Context) ResourceOutp
type ResourceOutput struct{ *pulumi.OutputState }
func (ResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (o ResourceOutput) ToResourceOutput() ResourceOutput {

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -82,7 +82,7 @@ type ResourceInput interface {
}
func (*Resource) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (i *Resource) ToResourceOutput() ResourceOutput {
@ -96,7 +96,7 @@ func (i *Resource) ToResourceOutputWithContext(ctx context.Context) ResourceOutp
type ResourceOutput struct{ *pulumi.OutputState }
func (ResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Resource)(nil))
return reflect.TypeOf((**Resource)(nil)).Elem()
}
func (o ResourceOutput) ToResourceOutput() ResourceOutput {

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -0,0 +1,57 @@
using Pulumi;
using Aws = Pulumi.Aws;
class MyStack : Stack
{
public MyStack()
{
var aws_vpc = new Aws.Ec2.Vpc("aws_vpc", new Aws.Ec2.VpcArgs
{
CidrBlock = "10.0.0.0/16",
InstanceTenancy = "default",
});
var privateS3VpcEndpoint = new Aws.Ec2.VpcEndpoint("privateS3VpcEndpoint", new Aws.Ec2.VpcEndpointArgs
{
VpcId = aws_vpc.Id,
ServiceName = "com.amazonaws.us-west-2.s3",
});
var privateS3PrefixList = Aws.Ec2.GetPrefixList.Invoke(new Aws.Ec2.GetPrefixListInvokeArgs
{
PrefixListId = privateS3VpcEndpoint.PrefixListId,
});
var bar = new Aws.Ec2.NetworkAcl("bar", new Aws.Ec2.NetworkAclArgs
{
VpcId = aws_vpc.Id,
});
var privateS3NetworkAclRule = new Aws.Ec2.NetworkAclRule("privateS3NetworkAclRule", new Aws.Ec2.NetworkAclRuleArgs
{
NetworkAclId = bar.Id,
RuleNumber = 200,
Egress = false,
Protocol = "tcp",
RuleAction = "allow",
CidrBlock = privateS3PrefixList.Apply(privateS3PrefixList => privateS3PrefixList.CidrBlocks[0]),
FromPort = 443,
ToPort = 443,
});
var amis = Aws.Ec2.GetAmiIds.Invoke(new Aws.Ec2.GetAmiIdsInvokeArgs
{
Owners =
{
bar.Id,
},
Filters =
{
new Aws.Ec2.Inputs.GetAmiIdsFilterInputArgs
{
Name = bar.Id,
Values =
{
"pulumi*",
},
},
},
});
}
}

View file

@ -0,0 +1,63 @@
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
aws_vpc, err := ec2.NewVpc(ctx, "aws_vpc", &ec2.VpcArgs{
CidrBlock: pulumi.String("10.0.0.0/16"),
InstanceTenancy: pulumi.String("default"),
})
if err != nil {
return err
}
privateS3VpcEndpoint, err := ec2.NewVpcEndpoint(ctx, "privateS3VpcEndpoint", &ec2.VpcEndpointArgs{
VpcId: aws_vpc.ID(),
ServiceName: pulumi.String("com.amazonaws.us-west-2.s3"),
})
if err != nil {
return err
}
privateS3PrefixList := ec2.GetPrefixListOutput(ctx, ec2.GetPrefixListOutputArgs{
PrefixListId: privateS3VpcEndpoint.PrefixListId,
}, nil)
bar, err := ec2.NewNetworkAcl(ctx, "bar", &ec2.NetworkAclArgs{
VpcId: aws_vpc.ID(),
})
if err != nil {
return err
}
_, err = ec2.NewNetworkAclRule(ctx, "privateS3NetworkAclRule", &ec2.NetworkAclRuleArgs{
NetworkAclId: bar.ID(),
RuleNumber: pulumi.Int(200),
Egress: pulumi.Bool(false),
Protocol: pulumi.String("tcp"),
RuleAction: pulumi.String("allow"),
CidrBlock: privateS3PrefixList.ApplyT(func(privateS3PrefixList ec2.GetPrefixListResult) (string, error) {
return privateS3PrefixList.CidrBlocks[0], nil
}).(pulumi.StringOutput),
FromPort: pulumi.Int(443),
ToPort: pulumi.Int(443),
})
if err != nil {
return err
}
_ = ec2.GetAmiIdsOutput(ctx, ec2.GetAmiIdsOutputArgs{
Owners: pulumi.StringArray{
bar.ID(),
},
Filters: ec2.GetAmiIdsFilterArray{
&ec2.GetAmiIdsFilterArgs{
Name: bar.ID(),
Values: pulumi.StringArray{
pulumi.String("pulumi*"),
},
},
},
}, nil)
return nil
})
}

View file

@ -0,0 +1,25 @@
import pulumi
import pulumi_aws as aws
aws_vpc = aws.ec2.Vpc("aws_vpc",
cidr_block="10.0.0.0/16",
instance_tenancy="default")
private_s3_vpc_endpoint = aws.ec2.VpcEndpoint("privateS3VpcEndpoint",
vpc_id=aws_vpc.id,
service_name="com.amazonaws.us-west-2.s3")
private_s3_prefix_list = aws.ec2.get_prefix_list_output(prefix_list_id=private_s3_vpc_endpoint.prefix_list_id)
bar = aws.ec2.NetworkAcl("bar", vpc_id=aws_vpc.id)
private_s3_network_acl_rule = aws.ec2.NetworkAclRule("privateS3NetworkAclRule",
network_acl_id=bar.id,
rule_number=200,
egress=False,
protocol="tcp",
rule_action="allow",
cidr_block=private_s3_prefix_list.cidr_blocks[0],
from_port=443,
to_port=443)
amis = aws.ec2.get_ami_ids_output(owners=[bar.id],
filters=[aws.ec2.GetAmiIdsFilterArgs(
name=bar.id,
values=["pulumi*"],
)])

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -35,8 +35,8 @@ func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.Propert
}
func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
if args.Token == "mypkg::listStorageAccountKeys" {
switch args.Token {
case "mypkg::listStorageAccountKeys":
targs := mypkg.ListStorageAccountKeysArgs{}
for k, v := range args.Args {
switch k {
@ -72,12 +72,11 @@ func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
"keys": result.Keys,
}
return resource.NewPropertyMapFromMap(outputs), nil
}
if args.Token == "mypkg::funcWithDefaultValue" ||
args.Token == "mypkg::funcWithAllOptionalInputs" ||
args.Token == "mypkg::funcWithListParam" ||
args.Token == "mypkg::funcWithDictParam" {
case "mypkg::funcWithDefaultValue",
"mypkg::funcWithAllOptionalInputs",
"mypkg::funcWithListParam",
"mypkg::funcWithDictParam":
result := mypkg.FuncWithDefaultValueResult{
R: fmt.Sprintf("%v", args.Args),
}
@ -85,9 +84,8 @@ func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
"r": result.R,
}
return resource.NewPropertyMapFromMap(outputs), nil
}
if args.Token == "mypkg::getIntegrationRuntimeObjectMetadatum" {
case "mypkg::getIntegrationRuntimeObjectMetadatum":
targs := mypkg.GetIntegrationRuntimeObjectMetadatumArgs{}
for k, v := range args.Args {
switch k {
@ -151,16 +149,13 @@ func TestListStorageAccountKeysOutput(t *testing.T) {
})
}
// TODO[pulumi/pulumi#7811]: it seems that default values are not
// supported by Go codegen yet, hence we do not observe "B" populated
// to default at all here.
func TestFuncWithDefaultValueOutput(t *testing.T) {
pulumiTest(t, func(ctx *pulumi.Context) error {
output := mypkg.FuncWithDefaultValueOutput(ctx, mypkg.FuncWithDefaultValueOutputArgs{
A: pulumi.String("my-a"),
})
r := waitOut(t, output.R())
assert.Equal(t, "map[a:{my-a}]", r)
assert.Equal(t, "map[a:{my-a} b:{b-default}]", r)
return nil
})
}

View file

@ -13,7 +13,7 @@ import (
// Check codegen of functions with default values.
func FuncWithDefaultValue(ctx *pulumi.Context, args *FuncWithDefaultValueArgs, opts ...pulumi.InvokeOption) (*FuncWithDefaultValueResult, error) {
var rv FuncWithDefaultValueResult
err := ctx.Invoke("mypkg::funcWithDefaultValue", args, &rv, opts...)
err := ctx.Invoke("mypkg::funcWithDefaultValue", args.Defaults(), &rv, opts...)
if err != nil {
return nil, err
}
@ -25,6 +25,19 @@ type FuncWithDefaultValueArgs struct {
B *string `pulumi:"b"`
}
// Defaults sets the appropriate defaults for FuncWithDefaultValueArgs
func (val *FuncWithDefaultValueArgs) Defaults() *FuncWithDefaultValueArgs {
if val == nil {
return nil
}
tmp := *val
if isZero(tmp.B) {
b_ := "b-default"
tmp.B = &b_
}
return &tmp
}
type FuncWithDefaultValueResult struct {
R string `pulumi:"r"`
}

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -22,53 +22,53 @@ func NewModuleResource(ctx *pulumi.Context,
return nil, errors.New("missing one or more required arguments")
}
if args.Optional_bool == nil {
if isZero(args.Optional_bool) {
args.Optional_bool = pulumi.BoolPtr(true)
}
args.Optional_const = pulumi.StringPtr("val")
if args.Optional_enum == nil {
if isZero(args.Optional_enum) {
args.Optional_enum = EnumThing(8)
}
if args.Optional_number == nil {
if isZero(args.Optional_number) {
args.Optional_number = pulumi.Float64Ptr(42.0)
}
if args.Optional_string == nil {
if isZero(args.Optional_string) {
args.Optional_string = pulumi.StringPtr("buzzer")
}
if args.Plain_optional_bool == nil {
if isZero(args.Plain_optional_bool) {
plain_optional_bool_ := true
args.Plain_optional_bool = &plain_optional_bool_
}
plain_optional_const_ := "val"
args.Plain_optional_const = &plain_optional_const_
if args.Plain_optional_number == nil {
if isZero(args.Plain_optional_number) {
plain_optional_number_ := 42.0
args.Plain_optional_number = &plain_optional_number_
}
if args.Plain_optional_string == nil {
if isZero(args.Plain_optional_string) {
plain_optional_string_ := "buzzer"
args.Plain_optional_string = &plain_optional_string_
}
if args.Plain_required_bool == false {
if isZero(args.Plain_required_bool) {
args.Plain_required_bool = true
}
args.Plain_required_const = "val"
if args.Plain_required_number == 0.0 {
if isZero(args.Plain_required_number) {
args.Plain_required_number = 42.0
}
if args.Plain_required_string == "" {
if isZero(args.Plain_required_string) {
args.Plain_required_string = "buzzer"
}
if args.Required_bool == nil {
if isZero(args.Required_bool) {
args.Required_bool = pulumi.Bool(true)
}
if args.Required_enum == nil {
if isZero(args.Required_enum) {
args.Required_enum = EnumThing(4)
}
if args.Required_number == nil {
if isZero(args.Required_number) {
args.Required_number = pulumi.Float64(42.0)
}
if args.Required_string == nil {
if isZero(args.Required_string) {
args.Required_string = pulumi.String("buzzer")
}
var resource ModuleResource
@ -155,7 +155,7 @@ type ModuleResourceInput interface {
}
func (*ModuleResource) ElementType() reflect.Type {
return reflect.TypeOf((*ModuleResource)(nil))
return reflect.TypeOf((**ModuleResource)(nil)).Elem()
}
func (i *ModuleResource) ToModuleResourceOutput() ModuleResourceOutput {
@ -169,7 +169,7 @@ func (i *ModuleResource) ToModuleResourceOutputWithContext(ctx context.Context)
type ModuleResourceOutput struct{ *pulumi.OutputState }
func (ModuleResourceOutput) ElementType() reflect.Type {
return reflect.TypeOf((*ModuleResource)(nil))
return reflect.TypeOf((**ModuleResource)(nil)).Elem()
}
func (o ModuleResourceOutput) ToModuleResourceOutput() ModuleResourceOutput {

View file

@ -48,7 +48,7 @@ type ProviderInput interface {
}
func (*Provider) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (i *Provider) ToProviderOutput() ProviderOutput {
@ -62,7 +62,7 @@ func (i *Provider) ToProviderOutputWithContext(ctx context.Context) ProviderOutp
type ProviderOutput struct{ *pulumi.OutputState }
func (ProviderOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Provider)(nil))
return reflect.TypeOf((**Provider)(nil)).Elem()
}
func (o ProviderOutput) ToProviderOutput() ProviderOutput {

View file

@ -75,3 +75,11 @@ func PkgVersion() (semver.Version, error) {
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -300,56 +300,6 @@ All [input](#inputs) properties are implicitly available as output properties. A
<h4 id="typ">Typ</h4>
{{% choosable language csharp %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_csharp">
<a href="#val_csharp" style="color: inherit; text-decoration: inherit;">Val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language go %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_go">
<a href="#val_go" style="color: inherit; text-decoration: inherit;">Val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language nodejs %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_nodejs">
<a href="#val_nodejs" style="color: inherit; text-decoration: inherit;">val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language python %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_python">
<a href="#val_python" style="color: inherit; text-decoration: inherit;">val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">str</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
<h4 id="typ">Typ</h4>
{{% choosable language csharp %}}
@ -466,6 +416,56 @@ All [input](#inputs) properties are implicitly available as output properties. A
<h4 id="typ">Typ</h4>
{{% choosable language csharp %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_csharp">
<a href="#val_csharp" style="color: inherit; text-decoration: inherit;">Val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language go %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_go">
<a href="#val_go" style="color: inherit; text-decoration: inherit;">Val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language nodejs %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_nodejs">
<a href="#val_nodejs" style="color: inherit; text-decoration: inherit;">val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">string</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
{{% choosable language python %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">
<span id="val_python">
<a href="#val_python" style="color: inherit; text-decoration: inherit;">val</a>
</span>
<span class="property-indicator"></span>
<span class="property-type">str</span>
</dt>
<dd>{{% md %}}{{% /md %}}</dd></dl>
{{% /choosable %}}
<h4 id="typ">Typ</h4>
{{% choosable language csharp %}}
<dl class="resources-properties"><dt class="property-optional"
title="Optional">

View file

@ -0,0 +1,26 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;
namespace Pulumi.Example.Mod1.Inputs
{
/// <summary>
/// A test for namespaces (mod 1)
/// </summary>
public sealed class TypArgs : Pulumi.ResourceArgs
{
[Input("val")]
public Input<string>? Val { get; set; }
public TypArgs()
{
Val = Utilities.GetEnv("PULUMI_EXAMPLE_MOD1_DEFAULT") ?? "mod1";
}
}
}

View file

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.7 KiB

View file

@ -0,0 +1,118 @@
// Copyright 2016-2021, Pulumi Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package codegentest
import (
"fmt"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"plain-object-defaults/example"
)
type mocks int
// We assert that default values were passed to our constuctor
func (mocks) NewResource(args pulumi.MockResourceArgs) (string, resource.PropertyMap, error) {
checkFloat64 := func(v resource.PropertyValue, k string, expected float64) {
m := v.V.(resource.PropertyMap)
if m[resource.PropertyKey(k)].V.(float64) != expected {
panic(fmt.Sprintf("Expected %s to have value %.2f", k, expected))
}
}
for k, v := range args.Inputs {
switch k {
case "kubeClientSettings":
checkFloat64(v, "burst", 42)
case "backupKubeClientSettings":
checkFloat64(v, "qps", 7)
}
}
return args.Name, args.Inputs.Copy(), nil
}
func (mocks) Call(args pulumi.MockCallArgs) (resource.PropertyMap, error) {
panic("Call not supported")
}
func TestObjectDefaults(t *testing.T) {
path := "thePath"
defaultDriver := "secret"
kcs := example.HelmReleaseSettings{
PluginsPath: &path,
RequiredArg: "This is required",
}
withDefaults := kcs.Defaults()
assert.Equal(t, kcs.RequiredArg, withDefaults.RequiredArg)
assert.Equal(t, kcs.PluginsPath, withDefaults.PluginsPath)
assert.Nil(t, kcs.Driver)
assert.Equal(t, withDefaults.Driver, &defaultDriver)
}
func TestTransitiveObjectDefaults(t *testing.T) {
layered := example.LayeredType{
Other: example.HelmReleaseSettings{},
}
withDefaults := layered.Defaults()
assert.Equal(t, "secret", *withDefaults.Other.Driver)
}
// We already have that defaults for resources. We test that they translate through objects.
func TestDefaultResource(t *testing.T) {
os.Setenv("PULUMI_K8S_CLIENT_BURST", "42")
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := example.NewFoo(ctx, "foo", &example.FooArgs{
KubeClientSettings: example.KubeClientSettingsPtr(&example.KubeClientSettingsArgs{}),
BackupKubeClientSettings: &example.KubeClientSettingsArgs{Qps: pulumi.Float64(7)},
})
assert.NoError(t, err)
return nil
}, pulumi.WithMocks("example", "stack", mocks(0)))
}
func waitOut(t *testing.T, output pulumi.Output) interface{} {
result, err := waitOutput(output, 1*time.Second)
if err != nil {
t.Error(err)
return nil
}
return result
}
func waitOutput(output pulumi.Output, timeout time.Duration) (interface{}, error) {
c := make(chan interface{}, 2)
output.ApplyT(func(v interface{}) interface{} {
c <- v
return v
})
var timeoutMarker *int = new(int)
go func() {
time.Sleep(timeout)
c <- timeoutMarker
}()
result := <-c
if result == timeoutMarker {
return nil, fmt.Errorf("Timed out waiting for pulumi.Output after %v", timeout)
} else {
return result, nil
}
}

View file

@ -0,0 +1,16 @@
{
"emittedFiles": [
"example/doc.go",
"example/foo.go",
"example/funcWithAllOptionalInputs.go",
"example/init.go",
"example/mod1/pulumiTypes.go",
"example/mod1/pulumiUtilities.go",
"example/mod2/pulumiTypes.go",
"example/mod2/pulumiUtilities.go",
"example/moduleTest.go",
"example/provider.go",
"example/pulumiTypes.go",
"example/pulumiUtilities.go"
]
}

View file

@ -0,0 +1,134 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package example
import (
"context"
"reflect"
"github.com/pkg/errors"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// test new feature with resoruces
type Foo struct {
pulumi.CustomResourceState
// A test for plain types
DefaultKubeClientSettings KubeClientSettingsPtrOutput `pulumi:"defaultKubeClientSettings"`
}
// NewFoo registers a new resource with the given unique name, arguments, and options.
func NewFoo(ctx *pulumi.Context,
name string, args *FooArgs, opts ...pulumi.ResourceOption) (*Foo, error) {
if args == nil {
return nil, errors.New("missing one or more required arguments")
}
if args.BackupKubeClientSettings == nil {
return nil, errors.New("invalid value for required argument 'BackupKubeClientSettings'")
}
backupKubeClientSettingsApplier := func(v KubeClientSettings) *KubeClientSettings { return v.Defaults() }
args.BackupKubeClientSettings = args.BackupKubeClientSettings.ToKubeClientSettingsOutput().ApplyT(backupKubeClientSettingsApplier).(KubeClientSettingsPtrOutput).Elem()
kubeClientSettingsApplier := func(v KubeClientSettings) *KubeClientSettings { return v.Defaults() }
if args.KubeClientSettings != nil {
args.KubeClientSettings = args.KubeClientSettings.ToKubeClientSettingsPtrOutput().Elem().ApplyT(kubeClientSettingsApplier).(KubeClientSettingsPtrOutput)
}
settingsApplier := func(v LayeredType) *LayeredType { return v.Defaults() }
if args.Settings != nil {
args.Settings = args.Settings.ToLayeredTypePtrOutput().Elem().ApplyT(settingsApplier).(LayeredTypePtrOutput)
}
var resource Foo
err := ctx.RegisterResource("example:index:Foo", name, args, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// GetFoo gets an existing Foo resource's state with the given name, ID, and optional
// state properties that are used to uniquely qualify the lookup (nil if not required).
func GetFoo(ctx *pulumi.Context,
name string, id pulumi.IDInput, state *FooState, opts ...pulumi.ResourceOption) (*Foo, error) {
var resource Foo
err := ctx.ReadResource("example:index:Foo", name, id, state, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
// Input properties used for looking up and filtering Foo resources.
type fooState struct {
}
type FooState struct {
}
func (FooState) ElementType() reflect.Type {
return reflect.TypeOf((*fooState)(nil)).Elem()
}
type fooArgs struct {
Argument *string `pulumi:"argument"`
// Options for tuning the Kubernetes client used by a Provider.
BackupKubeClientSettings KubeClientSettings `pulumi:"backupKubeClientSettings"`
// Options for tuning the Kubernetes client used by a Provider.
KubeClientSettings *KubeClientSettings `pulumi:"kubeClientSettings"`
// describing things
Settings *LayeredType `pulumi:"settings"`
}
// The set of arguments for constructing a Foo resource.
type FooArgs struct {
Argument *string
// Options for tuning the Kubernetes client used by a Provider.
BackupKubeClientSettings KubeClientSettingsInput
// Options for tuning the Kubernetes client used by a Provider.
KubeClientSettings KubeClientSettingsPtrInput
// describing things
Settings LayeredTypePtrInput
}
func (FooArgs) ElementType() reflect.Type {
return reflect.TypeOf((*fooArgs)(nil)).Elem()
}
type FooInput interface {
pulumi.Input
ToFooOutput() FooOutput
ToFooOutputWithContext(ctx context.Context) FooOutput
}
func (*Foo) ElementType() reflect.Type {
return reflect.TypeOf((**Foo)(nil)).Elem()
}
func (i *Foo) ToFooOutput() FooOutput {
return i.ToFooOutputWithContext(context.Background())
}
func (i *Foo) ToFooOutputWithContext(ctx context.Context) FooOutput {
return pulumi.ToOutputWithContext(ctx, i).(FooOutput)
}
type FooOutput struct{ *pulumi.OutputState }
func (FooOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Foo)(nil)).Elem()
}
func (o FooOutput) ToFooOutput() FooOutput {
return o
}
func (o FooOutput) ToFooOutputWithContext(ctx context.Context) FooOutput {
return o
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*FooInput)(nil)).Elem(), &Foo{})
pulumi.RegisterOutputType(FooOutput{})
}

View file

@ -0,0 +1,89 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package example
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// Check codegen of functions with all optional inputs.
func FuncWithAllOptionalInputs(ctx *pulumi.Context, args *FuncWithAllOptionalInputsArgs, opts ...pulumi.InvokeOption) (*FuncWithAllOptionalInputsResult, error) {
var rv FuncWithAllOptionalInputsResult
err := ctx.Invoke("mypkg::funcWithAllOptionalInputs", args.Defaults(), &rv, opts...)
if err != nil {
return nil, err
}
return &rv, nil
}
type FuncWithAllOptionalInputsArgs struct {
// Property A
A *HelmReleaseSettings `pulumi:"a"`
// Property B
B *string `pulumi:"b"`
}
// Defaults sets the appropriate defaults for FuncWithAllOptionalInputsArgs
func (val *FuncWithAllOptionalInputsArgs) Defaults() *FuncWithAllOptionalInputsArgs {
if val == nil {
return nil
}
tmp := *val
tmp.A = tmp.A.Defaults()
if isZero(tmp.B) {
b_ := "defValue"
tmp.B = &b_
}
return &tmp
}
type FuncWithAllOptionalInputsResult struct {
R string `pulumi:"r"`
}
func FuncWithAllOptionalInputsOutput(ctx *pulumi.Context, args FuncWithAllOptionalInputsOutputArgs, opts ...pulumi.InvokeOption) FuncWithAllOptionalInputsResultOutput {
return pulumi.ToOutputWithContext(context.Background(), args).
ApplyT(func(v interface{}) (FuncWithAllOptionalInputsResult, error) {
args := v.(FuncWithAllOptionalInputsArgs)
r, err := FuncWithAllOptionalInputs(ctx, &args, opts...)
return *r, err
}).(FuncWithAllOptionalInputsResultOutput)
}
type FuncWithAllOptionalInputsOutputArgs struct {
// Property A
A HelmReleaseSettingsPtrInput `pulumi:"a"`
// Property B
B pulumi.StringPtrInput `pulumi:"b"`
}
func (FuncWithAllOptionalInputsOutputArgs) ElementType() reflect.Type {
return reflect.TypeOf((*FuncWithAllOptionalInputsArgs)(nil)).Elem()
}
type FuncWithAllOptionalInputsResultOutput struct{ *pulumi.OutputState }
func (FuncWithAllOptionalInputsResultOutput) ElementType() reflect.Type {
return reflect.TypeOf((*FuncWithAllOptionalInputsResult)(nil)).Elem()
}
func (o FuncWithAllOptionalInputsResultOutput) ToFuncWithAllOptionalInputsResultOutput() FuncWithAllOptionalInputsResultOutput {
return o
}
func (o FuncWithAllOptionalInputsResultOutput) ToFuncWithAllOptionalInputsResultOutputWithContext(ctx context.Context) FuncWithAllOptionalInputsResultOutput {
return o
}
func (o FuncWithAllOptionalInputsResultOutput) R() pulumi.StringOutput {
return o.ApplyT(func(v FuncWithAllOptionalInputsResult) string { return v.R }).(pulumi.StringOutput)
}
func init() {
pulumi.RegisterOutputType(FuncWithAllOptionalInputsResultOutput{})
}

View file

@ -0,0 +1,167 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package mod1
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
// A test for namespaces (mod 1)
type Typ struct {
Val *string `pulumi:"val"`
}
// Defaults sets the appropriate defaults for Typ
func (val *Typ) Defaults() *Typ {
if val == nil {
return nil
}
tmp := *val
if isZero(tmp.Val) {
val_ := getEnvOrDefault("mod1", nil, "PULUMI_EXAMPLE_MOD1_DEFAULT").(string)
tmp.Val = &val_
}
return &tmp
}
// TypInput is an input type that accepts TypArgs and TypOutput values.
// You can construct a concrete instance of `TypInput` via:
//
// TypArgs{...}
type TypInput interface {
pulumi.Input
ToTypOutput() TypOutput
ToTypOutputWithContext(context.Context) TypOutput
}
// A test for namespaces (mod 1)
type TypArgs struct {
Val pulumi.StringPtrInput `pulumi:"val"`
}
func (TypArgs) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (i TypArgs) ToTypOutput() TypOutput {
return i.ToTypOutputWithContext(context.Background())
}
func (i TypArgs) ToTypOutputWithContext(ctx context.Context) TypOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput)
}
func (i TypArgs) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i TypArgs) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput).ToTypPtrOutputWithContext(ctx)
}
// TypPtrInput is an input type that accepts TypArgs, TypPtr and TypPtrOutput values.
// You can construct a concrete instance of `TypPtrInput` via:
//
// TypArgs{...}
//
// or:
//
// nil
type TypPtrInput interface {
pulumi.Input
ToTypPtrOutput() TypPtrOutput
ToTypPtrOutputWithContext(context.Context) TypPtrOutput
}
type typPtrType TypArgs
func TypPtr(v *TypArgs) TypPtrInput {
return (*typPtrType)(v)
}
func (*typPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (i *typPtrType) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i *typPtrType) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypPtrOutput)
}
// A test for namespaces (mod 1)
type TypOutput struct{ *pulumi.OutputState }
func (TypOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (o TypOutput) ToTypOutput() TypOutput {
return o
}
func (o TypOutput) ToTypOutputWithContext(ctx context.Context) TypOutput {
return o
}
func (o TypOutput) ToTypPtrOutput() TypPtrOutput {
return o.ToTypPtrOutputWithContext(context.Background())
}
func (o TypOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Typ) *Typ {
return &v
}).(TypPtrOutput)
}
func (o TypOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v Typ) *string { return v.Val }).(pulumi.StringPtrOutput)
}
type TypPtrOutput struct{ *pulumi.OutputState }
func (TypPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (o TypPtrOutput) ToTypPtrOutput() TypPtrOutput {
return o
}
func (o TypPtrOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o
}
func (o TypPtrOutput) Elem() TypOutput {
return o.ApplyT(func(v *Typ) Typ {
if v != nil {
return *v
}
var ret Typ
return ret
}).(TypOutput)
}
func (o TypPtrOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Typ) *string {
if v == nil {
return nil
}
return v.Val
}).(pulumi.StringPtrOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*TypInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*TypPtrInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterOutputType(TypOutput{})
pulumi.RegisterOutputType(TypPtrOutput{})
}

View file

@ -0,0 +1,85 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package mod1
import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"github.com/blang/semver"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type envParser func(v string) interface{}
func parseEnvBool(v string) interface{} {
b, err := strconv.ParseBool(v)
if err != nil {
return nil
}
return b
}
func parseEnvInt(v string) interface{} {
i, err := strconv.ParseInt(v, 0, 0)
if err != nil {
return nil
}
return int(i)
}
func parseEnvFloat(v string) interface{} {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return nil
}
return f
}
func parseEnvStringArray(v string) interface{} {
var result pulumi.StringArray
for _, item := range strings.Split(v, ";") {
result = append(result, pulumi.String(item))
}
return result
}
func getEnvOrDefault(def interface{}, parser envParser, vars ...string) interface{} {
for _, v := range vars {
if value := os.Getenv(v); value != "" {
if parser != nil {
return parser(value)
}
return value
}
}
return def
}
// PkgVersion uses reflection to determine the version of the current package.
func PkgVersion() (semver.Version, error) {
type sentinal struct{}
pkgPath := reflect.TypeOf(sentinal{}).PkgPath()
re := regexp.MustCompile("^.*/pulumi-example/sdk(/v\\d+)?")
if match := re.FindStringSubmatch(pkgPath); match != nil {
vStr := match[1]
if len(vStr) == 0 { // If the version capture group was empty, default to v1.
return semver.Version{Major: 1}, nil
}
return semver.MustParse(fmt.Sprintf("%s.0.0", vStr[2:])), nil
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

View file

@ -0,0 +1,185 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package mod2
import (
"context"
"reflect"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"plain-object-defaults/example/mod1"
)
// A test for namespaces (mod 2)
type Typ struct {
Mod1 *mod1.Typ `pulumi:"mod1"`
Val *string `pulumi:"val"`
}
// Defaults sets the appropriate defaults for Typ
func (val *Typ) Defaults() *Typ {
if val == nil {
return nil
}
tmp := *val
tmp.Mod1 = tmp.Mod1.Defaults()
if isZero(tmp.Val) {
val_ := "mod2"
tmp.Val = &val_
}
return &tmp
}
// TypInput is an input type that accepts TypArgs and TypOutput values.
// You can construct a concrete instance of `TypInput` via:
//
// TypArgs{...}
type TypInput interface {
pulumi.Input
ToTypOutput() TypOutput
ToTypOutputWithContext(context.Context) TypOutput
}
// A test for namespaces (mod 2)
type TypArgs struct {
Mod1 mod1.TypPtrInput `pulumi:"mod1"`
Val pulumi.StringPtrInput `pulumi:"val"`
}
func (TypArgs) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (i TypArgs) ToTypOutput() TypOutput {
return i.ToTypOutputWithContext(context.Background())
}
func (i TypArgs) ToTypOutputWithContext(ctx context.Context) TypOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput)
}
func (i TypArgs) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i TypArgs) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypOutput).ToTypPtrOutputWithContext(ctx)
}
// TypPtrInput is an input type that accepts TypArgs, TypPtr and TypPtrOutput values.
// You can construct a concrete instance of `TypPtrInput` via:
//
// TypArgs{...}
//
// or:
//
// nil
type TypPtrInput interface {
pulumi.Input
ToTypPtrOutput() TypPtrOutput
ToTypPtrOutputWithContext(context.Context) TypPtrOutput
}
type typPtrType TypArgs
func TypPtr(v *TypArgs) TypPtrInput {
return (*typPtrType)(v)
}
func (*typPtrType) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (i *typPtrType) ToTypPtrOutput() TypPtrOutput {
return i.ToTypPtrOutputWithContext(context.Background())
}
func (i *typPtrType) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return pulumi.ToOutputWithContext(ctx, i).(TypPtrOutput)
}
// A test for namespaces (mod 2)
type TypOutput struct{ *pulumi.OutputState }
func (TypOutput) ElementType() reflect.Type {
return reflect.TypeOf((*Typ)(nil)).Elem()
}
func (o TypOutput) ToTypOutput() TypOutput {
return o
}
func (o TypOutput) ToTypOutputWithContext(ctx context.Context) TypOutput {
return o
}
func (o TypOutput) ToTypPtrOutput() TypPtrOutput {
return o.ToTypPtrOutputWithContext(context.Background())
}
func (o TypOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o.ApplyTWithContext(ctx, func(_ context.Context, v Typ) *Typ {
return &v
}).(TypPtrOutput)
}
func (o TypOutput) Mod1() mod1.TypPtrOutput {
return o.ApplyT(func(v Typ) *mod1.Typ { return v.Mod1 }).(mod1.TypPtrOutput)
}
func (o TypOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v Typ) *string { return v.Val }).(pulumi.StringPtrOutput)
}
type TypPtrOutput struct{ *pulumi.OutputState }
func (TypPtrOutput) ElementType() reflect.Type {
return reflect.TypeOf((**Typ)(nil)).Elem()
}
func (o TypPtrOutput) ToTypPtrOutput() TypPtrOutput {
return o
}
func (o TypPtrOutput) ToTypPtrOutputWithContext(ctx context.Context) TypPtrOutput {
return o
}
func (o TypPtrOutput) Elem() TypOutput {
return o.ApplyT(func(v *Typ) Typ {
if v != nil {
return *v
}
var ret Typ
return ret
}).(TypOutput)
}
func (o TypPtrOutput) Mod1() mod1.TypPtrOutput {
return o.ApplyT(func(v *Typ) *mod1.Typ {
if v == nil {
return nil
}
return v.Mod1
}).(mod1.TypPtrOutput)
}
func (o TypPtrOutput) Val() pulumi.StringPtrOutput {
return o.ApplyT(func(v *Typ) *string {
if v == nil {
return nil
}
return v.Val
}).(pulumi.StringPtrOutput)
}
func init() {
pulumi.RegisterInputType(reflect.TypeOf((*TypInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterInputType(reflect.TypeOf((*TypPtrInput)(nil)).Elem(), TypArgs{})
pulumi.RegisterOutputType(TypOutput{})
pulumi.RegisterOutputType(TypPtrOutput{})
}

View file

@ -0,0 +1,85 @@
// *** WARNING: this file was generated by test. ***
// *** Do not edit by hand unless you're certain you know what you are doing! ***
package mod2
import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"github.com/blang/semver"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type envParser func(v string) interface{}
func parseEnvBool(v string) interface{} {
b, err := strconv.ParseBool(v)
if err != nil {
return nil
}
return b
}
func parseEnvInt(v string) interface{} {
i, err := strconv.ParseInt(v, 0, 0)
if err != nil {
return nil
}
return int(i)
}
func parseEnvFloat(v string) interface{} {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return nil
}
return f
}
func parseEnvStringArray(v string) interface{} {
var result pulumi.StringArray
for _, item := range strings.Split(v, ";") {
result = append(result, pulumi.String(item))
}
return result
}
func getEnvOrDefault(def interface{}, parser envParser, vars ...string) interface{} {
for _, v := range vars {
if value := os.Getenv(v); value != "" {
if parser != nil {
return parser(value)
}
return value
}
}
return def
}
// PkgVersion uses reflection to determine the version of the current package.
func PkgVersion() (semver.Version, error) {
type sentinal struct{}
pkgPath := reflect.TypeOf(sentinal{}).PkgPath()
re := regexp.MustCompile("^.*/pulumi-example/sdk(/v\\d+)?")
if match := re.FindStringSubmatch(pkgPath); match != nil {
vStr := match[1]
if len(vStr) == 0 { // If the version capture group was empty, default to v1.
return semver.Version{Major: 1}, nil
}
return semver.MustParse(fmt.Sprintf("%s.0.0", vStr[2:])), nil
}
return semver.Version{}, fmt.Errorf("failed to determine the package version from %s", pkgPath)
}
// isZero is a null safe check for if a value is it's types zero value.
func isZero(v interface{}) bool {
if v == nil {
return true
}
return reflect.ValueOf(v).IsZero()
}

Some files were not shown because too many files have changed in this diff Show more