Skip to content

Commit cd8e947

Browse files
repros
1 parent 10b34b1 commit cd8e947

File tree

6 files changed

+366
-0
lines changed

6 files changed

+366
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2016-2022, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package testprovider
16+
17+
import (
18+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19+
)
20+
21+
func ProviderNestedFullyComputed() *schema.Provider {
22+
resourceNestedFullyComputedFunc := func() *schema.Resource {
23+
return &schema.Resource{
24+
Schema: resourceNestedFullyComputedSchema(),
25+
}
26+
}
27+
28+
return &schema.Provider{
29+
Schema: map[string]*schema.Schema{},
30+
ResourcesMap: map[string]*schema.Resource{
31+
"testprovider_res": resourceNestedFullyComputedFunc(),
32+
},
33+
}
34+
}
35+
36+
func resourceNestedFullyComputedSchema() map[string]*schema.Schema {
37+
return map[string]*schema.Schema{
38+
"block": {
39+
Type: schema.TypeList,
40+
Required: true,
41+
Elem: &schema.Resource{
42+
Schema: map[string]*schema.Schema{
43+
"a1": {
44+
Type: schema.TypeString,
45+
Computed: true,
46+
},
47+
"a2": {
48+
Type: schema.TypeString,
49+
Optional: true,
50+
},
51+
},
52+
},
53+
},
54+
}
55+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
{
2+
"name": "testprovider",
3+
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
4+
"meta": {
5+
"moduleFormat": "(.*)(?:/[^/]*)"
6+
},
7+
"language": {
8+
"nodejs": {
9+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\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 please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
10+
"compatibility": "tfbridge20",
11+
"disableUnionOutputTypes": true
12+
},
13+
"python": {
14+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\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 please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
15+
"compatibility": "tfbridge20",
16+
"pyproject": {}
17+
}
18+
},
19+
"config": {},
20+
"types": {
21+
"testprovider:index/ResB1:ResB1": {
22+
"properties": {
23+
"a1": {
24+
"type": "string"
25+
},
26+
"a2": {
27+
"type": "string"
28+
}
29+
},
30+
"type": "object",
31+
"language": {
32+
"nodejs": {
33+
"requiredOutputs": [
34+
"a1"
35+
]
36+
}
37+
}
38+
}
39+
},
40+
"provider": {
41+
"description": "The provider type for the testprovider 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",
42+
"methods": {
43+
"terraformConfig": "pulumi:providers:testprovider/terraformConfig"
44+
}
45+
},
46+
"resources": {
47+
"testprovider:index:Res": {
48+
"properties": {
49+
"b1": {
50+
"$ref": "#/types/testprovider:index/ResB1:ResB1"
51+
}
52+
},
53+
"inputProperties": {
54+
"b1": {
55+
"$ref": "#/types/testprovider:index/ResB1:ResB1"
56+
}
57+
},
58+
"stateInputs": {
59+
"description": "Input properties used for looking up and filtering Res resources.\n",
60+
"properties": {
61+
"b1": {
62+
"$ref": "#/types/testprovider:index/ResB1:ResB1"
63+
}
64+
},
65+
"type": "object"
66+
}
67+
}
68+
},
69+
"functions": {
70+
"pulumi:providers:testprovider/terraformConfig": {
71+
"description": "This function returns a Terraform config object with terraform-namecased keys,to be used with the Terraform Module Provider.",
72+
"inputs": {
73+
"properties": {
74+
"__self__": {
75+
"type": "ref",
76+
"$ref": "#/resources/pulumi:providers:testprovider"
77+
}
78+
},
79+
"type": "pulumi:providers:testprovider/terraformConfig",
80+
"required": [
81+
"__self__"
82+
]
83+
},
84+
"outputs": {
85+
"properties": {
86+
"result": {
87+
"additionalProperties": {
88+
"$ref": "pulumi.json#/Any"
89+
},
90+
"type": "object"
91+
}
92+
},
93+
"required": [
94+
"result"
95+
],
96+
"type": "object"
97+
}
98+
}
99+
}
100+
}

pkg/pf/tfgen/tfgen_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,45 @@ func TestPFRequiredInputWithDefault(t *testing.T) {
567567
require.NoError(t, json.Indent(&b, res.ProviderMetadata.PackageSchema, "", " "))
568568
autogold.ExpectFile(t, autogold.Raw(b.String()))
569569
}
570+
571+
func TestPFNestedFullyComputed(t *testing.T) {
572+
t.Parallel()
573+
574+
schema := rschema.Schema{
575+
Attributes: map[string]rschema.Attribute{
576+
"id": rschema.StringAttribute{Computed: true},
577+
},
578+
Blocks: map[string]rschema.Block{
579+
"b1": rschema.SingleNestedBlock{
580+
Attributes: map[string]rschema.Attribute{
581+
"a1": rschema.StringAttribute{Computed: true},
582+
"a2": rschema.StringAttribute{Optional: true},
583+
},
584+
},
585+
},
586+
}
587+
588+
info := &tfbridge.ResourceInfo{
589+
Tok: "testprovider:index:Res",
590+
Docs: &tfbridge.DocInfo{Markdown: []byte{' '}},
591+
}
592+
593+
res, err := GenerateSchema(context.Background(), GenerateSchemaOptions{
594+
ProviderInfo: tfbridge.ProviderInfo{
595+
Name: "testprovider",
596+
UpstreamRepoPath: ".", // no invalid mappings warnings
597+
P: pftfbridge.ShimProvider(&schemaTestProvider{
598+
resources: map[string]rschema.Schema{
599+
"res": schema,
600+
},
601+
}),
602+
Resources: map[string]*tfbridge.ResourceInfo{
603+
"test_res": info,
604+
},
605+
},
606+
})
607+
require.NoError(t, err)
608+
var b bytes.Buffer
609+
require.NoError(t, json.Indent(&b, res.ProviderMetadata.PackageSchema, "", " "))
610+
autogold.ExpectFile(t, autogold.Raw(b.String()))
611+
}

pkg/tfgen/generate_schema_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ func TestRequiredInputWithDefault(t *testing.T) {
449449
bridgetesting.AssertEqualsJSONFile(t, "test_data/required-input-with-default-schema.json", schema)
450450
}
451451

452+
func TestNestedFullyComputed(t *testing.T) {
453+
t.Parallel()
454+
provider := testprovider.ProviderNestedFullyComputed()
455+
schema, err := GenerateSchema(provider, diag.DefaultSink(io.Discard, io.Discard, diag.FormatOptions{
456+
Color: colors.Never,
457+
}))
458+
require.NoError(t, err)
459+
bridgetesting.AssertEqualsJSONFile(t, "test_data/nested-fully-computed-schema.json", schema)
460+
}
461+
452462
func TestAppendExample_InsertMiddle(t *testing.T) {
453463
t.Parallel()
454464
descTmpl := `Description text
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2016-2022, Pulumi Corporation.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package testprovider
16+
17+
import (
18+
testproviderdata "github.com/pulumi/pulumi-terraform-bridge/v3/internal/testprovider"
19+
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
20+
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
21+
)
22+
23+
func ProviderNestedFullyComputed() tfbridge.ProviderInfo {
24+
return tfbridge.ProviderInfo{
25+
P: shimv2.NewProvider(testproviderdata.ProviderNestedFullyComputed()),
26+
Name: "testprovider",
27+
Keywords: []string{"pulumi", "testprovider"},
28+
License: "Apache-2.0",
29+
Homepage: "https://pulumi.io",
30+
Repository: "https://github.com/pulumi/pulumi-testprovider",
31+
Resources: map[string]*tfbridge.ResourceInfo{
32+
"testprovider_res": {
33+
Tok: tfbridge.MakeResource("testprovider", "index", "Res"),
34+
},
35+
},
36+
}
37+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"name": "testprovider",
3+
"keywords": [
4+
"pulumi",
5+
"testprovider"
6+
],
7+
"homepage": "https://pulumi.io",
8+
"license": "Apache-2.0",
9+
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
10+
"repository": "https://github.com/pulumi/pulumi-testprovider",
11+
"meta": {
12+
"moduleFormat": "(.*)(?:/[^/]*)"
13+
},
14+
"language": {
15+
"nodejs": {
16+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\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-testprovider` repo](https://github.com/pulumi/pulumi-testprovider/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
17+
"compatibility": "tfbridge20",
18+
"disableUnionOutputTypes": true
19+
},
20+
"python": {
21+
"readme": "\u003e This provider is a derived work of the [Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider)\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-testprovider` repo](https://github.com/pulumi/pulumi-testprovider/issues); however, if that doesn't turn up anything,\n\u003e please consult the source [`terraform-provider-testprovider` repo](https://github.com/terraform-providers/terraform-provider-testprovider/issues).",
22+
"compatibility": "tfbridge20",
23+
"pyproject": {}
24+
}
25+
},
26+
"config": {},
27+
"types": {
28+
"testprovider:index/ResBlock:ResBlock": {
29+
"properties": {
30+
"a1": {
31+
"type": "string"
32+
},
33+
"a2": {
34+
"type": "string"
35+
}
36+
},
37+
"type": "object",
38+
"language": {
39+
"nodejs": {
40+
"requiredOutputs": [
41+
"a1"
42+
]
43+
}
44+
}
45+
}
46+
},
47+
"provider": {
48+
"description": "The provider type for the testprovider 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",
49+
"methods": {
50+
"terraformConfig": "pulumi:providers:testprovider/terraformConfig"
51+
}
52+
},
53+
"resources": {
54+
"testprovider:index/res:Res": {
55+
"properties": {
56+
"blocks": {
57+
"type": "array",
58+
"items": {
59+
"$ref": "#/types/testprovider:index/ResBlock:ResBlock"
60+
}
61+
}
62+
},
63+
"required": [
64+
"blocks"
65+
],
66+
"inputProperties": {
67+
"blocks": {
68+
"type": "array",
69+
"items": {
70+
"$ref": "#/types/testprovider:index/ResBlock:ResBlock"
71+
}
72+
}
73+
},
74+
"requiredInputs": [
75+
"blocks"
76+
],
77+
"stateInputs": {
78+
"description": "Input properties used for looking up and filtering Res resources.\n",
79+
"properties": {
80+
"blocks": {
81+
"type": "array",
82+
"items": {
83+
"$ref": "#/types/testprovider:index/ResBlock:ResBlock"
84+
}
85+
}
86+
},
87+
"type": "object"
88+
}
89+
}
90+
},
91+
"functions": {
92+
"pulumi:providers:testprovider/terraformConfig": {
93+
"description": "This function returns a Terraform config object with terraform-namecased keys,to be used with the Terraform Module Provider.",
94+
"inputs": {
95+
"properties": {
96+
"__self__": {
97+
"type": "ref",
98+
"$ref": "#/resources/pulumi:providers:testprovider"
99+
}
100+
},
101+
"type": "pulumi:providers:testprovider/terraformConfig",
102+
"required": [
103+
"__self__"
104+
]
105+
},
106+
"outputs": {
107+
"properties": {
108+
"result": {
109+
"additionalProperties": {
110+
"$ref": "pulumi.json#/Any"
111+
},
112+
"type": "object"
113+
}
114+
},
115+
"required": [
116+
"result"
117+
],
118+
"type": "object"
119+
}
120+
}
121+
}
122+
}

0 commit comments

Comments
 (0)