Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate optional+computed #1901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions pkg/tfgen/generate_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
bridgetesting "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testing"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfgen/internal/testprovider"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi-terraform-bridge/v3/unstable/metadata"
"github.com/pulumi/pulumi-terraform-bridge/x/muxer"
csgen "github.com/pulumi/pulumi/pkg/v3/codegen/dotnet"
Expand Down Expand Up @@ -472,3 +474,37 @@ func TestRegress1626(t *testing.T) {
t.Logf("SPEC: %v", s)
require.NoError(t, err)
}

func TestOptionalComputed(t *testing.T) {
schemaProvider := &schema.Provider{
Schema: map[string]*schema.Schema{},
ResourcesMap: map[string]*schema.Resource{
"my_resource": {
Schema: map[string]*schema.Schema{
"my_prop": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
},
},
},
}

provider := tfbridge.ProviderInfo{
P: shimv2.NewProvider(schemaProvider),
Name: "my",
Resources: map[string]*tfbridge.ResourceInfo{
"my_resource": {
Tok: tfbridge.MakeResource("my", "index", "Resource"),
Fields: map[string]*tfbridge.SchemaInfo{},
},
},
}

schema, err := GenerateSchema(provider, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{
Color: colors.Never,
}))
assert.NoError(t, err)
bridgetesting.AssertEqualsJSONFile(t, "test_data/computed-optional.json", schema)
}
49 changes: 49 additions & 0 deletions pkg/tfgen/test_data/computed-optional.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "my",
"attribution": "This Pulumi package is based on the [`my` Terraform Provider](https://github.com/terraform-providers/terraform-provider-my).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"language": {
"nodejs": {
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-my)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e first check the [`pulumi-my` repo](/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-my` repo](https://github.com/terraform-providers/terraform-provider-my/issues).",
"compatibility": "tfbridge20",
"disableUnionOutputTypes": true
},
"python": {
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-my)\n\u003e distributed under [MPL 2.0](https://www.mozilla.org/en-US/MPL/2.0/). If you encounter a bug or missing feature,\n\u003e first check the [`pulumi-my` repo](/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-my` repo](https://github.com/terraform-providers/terraform-provider-my/issues).",
"compatibility": "tfbridge20",
"pyproject": {}
}
},
"config": {},
"provider": {
"description": "The provider type for the my package. By default, resources use package-wide configuration\nsettings, however an explicit `Provider` instance may be created and passed during resource\nconstruction to achieve fine-grained programmatic control over provider settings. See the\n[documentation](https://www.pulumi.com/docs/reference/programming-model/#providers) for more information.\n"
},
"resources": {
"my:index/resource:Resource": {
"properties": {
"myProp": {
"type": "string"
}
},
"required": [
"myProp"
],
"inputProperties": {
"myProp": {
"type": "string"
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Resource resources.\n",
"properties": {
"myProp": {
"type": "string"
}
},
"type": "object"
}
}
}
}