Skip to content

Commit

Permalink
Enforce validation with a custom generator
Browse files Browse the repository at this point in the history
This commit unifies the functionality of `Generator.Generate` and `GenerateWithOptions`,
so that they now both call `ProviderInfo.Validate` (previously, only `Generator.Generate`
called `ProviderInfo.Validate`).

This caused 2 unrelated tests to fail. Both can be fixed by removing the invalid mappings
they used to have.
  • Loading branch information
iwahbe committed Aug 15, 2024
1 parent 823fd88 commit 8a98bfb
Show file tree
Hide file tree
Showing 16 changed files with 799 additions and 42 deletions.
6 changes: 5 additions & 1 deletion pf/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/hashicorp/terraform-plugin-go v0.22.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0
github.com/hexops/autogold/v2 v2.2.1
github.com/pulumi/pulumi-terraform-bridge/v3 v3.89.0
github.com/pulumi/pulumi-terraform-bridge/x/muxer v0.0.8
github.com/stretchr/testify v1.9.0
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/deckarep/golang-set/v2 v2.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/frankban/quicktest v1.14.4 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -55,12 +55,15 @@ require (
github.com/google/s2a-go v0.1.7 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/logutils v1.0.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/hexops/valast v1.4.4 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/nightlyone/lockfile v1.0.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
Expand All @@ -82,6 +85,7 @@ require (
golang.org/x/tools v0.22.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
mvdan.cc/gofumpt v0.5.0 // indirect
)

require (
Expand Down
7 changes: 7 additions & 0 deletions pf/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1373,12 +1373,14 @@ github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -1668,6 +1670,7 @@ github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKe
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/hexops/autogold v0.8.1/go.mod h1:97HLDXyG23akzAoRYJh/2OBs3kd80eHyKPvZw0S5ZBY=
github.com/hexops/autogold v1.3.0 h1:IEtGNPxBeBu8RMn8eKWh/Ll9dVNgSnJ7bp/qHgMQ14o=
github.com/hexops/autogold v1.3.0/go.mod h1:d4hwi2rid66Sag+BVuHgwakW/EmaFr8vdTSbWDbrDRI=
github.com/hexops/autogold/v2 v2.2.1 h1:JPUXuZQGkcQMv7eeDXuNMovjfoRYaa0yVcm+F3voaGY=
Expand Down Expand Up @@ -1758,6 +1761,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
Expand Down Expand Up @@ -1930,6 +1934,7 @@ github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYe
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
Expand Down Expand Up @@ -2559,6 +2564,7 @@ golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc=
golang.org/x/tools v0.10.0/go.mod h1:UJwyiVBsOA2uwvK/e5OY3GTpDUJriEd+/YlqAwLPmyM=
golang.org/x/tools v0.12.0/go.mod h1:Sc0INKfu04TlqNoRA1hgpFZbhYXHPr4V5DzpSBTPqQM=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
Expand Down Expand Up @@ -3011,6 +3017,7 @@ modernc.org/token v1.0.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/token v1.0.1/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
modernc.org/z v1.5.1/go.mod h1:eWFB510QWW5Th9YGZT81s+LwvaAs3Q2yr4sP0rmLkv8=
mvdan.cc/gofumpt v0.4.0/go.mod h1:PljLOHDeZqgS8opHRKLzp2It2VBuSdteAgqUfzMTxlQ=
mvdan.cc/gofumpt v0.5.0 h1:0EQ+Z56k8tXjj/6TQD25BFNKQXpCvT0rnansIc7Ug5E=
mvdan.cc/gofumpt v0.5.0/go.mod h1:HBeVDtMKRZpXyxFciAirzdKklDlGu8aAy1wEbH5Y9js=
pgregory.net/rapid v0.6.1 h1:4eyrDxyht86tT4Ztm+kvlyNBLIk071gR+ZQdhphc9dQ=
Expand Down
41 changes: 41 additions & 0 deletions pf/tfgen/testdata/TestTypeOverride/attr-list-element.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"inputProperties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"type": "object"
}
}
}
}
32 changes: 32 additions & 0 deletions pf/tfgen/testdata/TestTypeOverride/attr-list-max-items-one.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1": {
"type": "string"
}
},
"inputProperties": {
"a1": {
"type": "string"
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1": {
"type": "string"
}
},
"type": "object"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"types": {
"testprovider:index/ResA1:ResA1": {
"properties": {
"foo": {
"type": "string"
}
},
"type": "object"
}
},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
},
"required": [
"a1"
],
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
},
"type": "object"
}
}
}
}
41 changes: 41 additions & 0 deletions pf/tfgen/testdata/TestTypeOverride/attr-map-element.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1": {
"type": "object",
"additionalProperties": {
"type": "number"
}
}
},
"inputProperties": {
"a1": {
"type": "object",
"additionalProperties": {
"type": "number"
}
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1": {
"type": "object",
"additionalProperties": {
"type": "number"
}
}
},
"type": "object"
}
}
}
}
51 changes: 51 additions & 0 deletions pf/tfgen/testdata/TestTypeOverride/attr-map-object-element.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"types": {
"testprovider:index/ResA1:ResA1": {
"properties": {
"n1": {
"type": "number"
}
},
"type": "object"
}
},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1": {
"type": "object",
"additionalProperties": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
}
},
"inputProperties": {
"a1": {
"type": "object",
"additionalProperties": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1": {
"type": "object",
"additionalProperties": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
}
},
"type": "object"
}
}
}
}
41 changes: 41 additions & 0 deletions pf/tfgen/testdata/TestTypeOverride/attr-set-element.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"inputProperties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1s": {
"type": "array",
"items": {
"type": "number"
}
}
},
"type": "object"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "testprovider",
"attribution": "This Pulumi package is based on the [`testprovider` Terraform Provider](https://github.com/terraform-providers/terraform-provider-testprovider).",
"meta": {
"moduleFormat": "(.*)(?:/[^/]*)"
},
"config": {},
"types": {
"testprovider:index/ResA1:ResA1": {
"properties": {
"n1": {
"type": "number"
}
},
"type": "object"
}
},
"provider": {},
"resources": {
"testprovider:index:Res": {
"properties": {
"a1": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
},
"inputProperties": {
"a1": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
},
"stateInputs": {
"description": "Input properties used for looking up and filtering Res resources.\n",
"properties": {
"a1": {
"$ref": "#/types/testprovider:index/ResA1:ResA1"
}
},
"type": "object"
}
}
}
}
Loading

0 comments on commit 8a98bfb

Please sign in to comment.