diff --git a/go.mod b/go.mod index a65fc5e0..e34455c3 100644 --- a/go.mod +++ b/go.mod @@ -1,42 +1,42 @@ module github.com/hashicorp/terraform-plugin-codegen-framework -go 1.20 +go 1.21 require ( github.com/google/go-cmp v0.6.0 github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc - github.com/hashicorp/terraform-plugin-framework v1.4.0 - github.com/hashicorp/terraform-plugin-go v0.19.0 - github.com/mattn/go-colorable v0.1.12 + github.com/hashicorp/terraform-plugin-framework v1.4.2 + github.com/mattn/go-colorable v0.1.13 github.com/mitchellh/cli v1.1.5 ) require ( github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.1.1 // indirect - github.com/Masterminds/sprig/v3 v3.2.1 // indirect - github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 // indirect + github.com/Masterminds/semver/v3 v3.2.1 // indirect + github.com/Masterminds/sprig/v3 v3.2.3 // indirect + github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/fatih/color v1.13.0 // indirect - github.com/google/uuid v1.1.2 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/fatih/color v1.15.0 // indirect + github.com/google/uuid v1.4.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect - github.com/hashicorp/go-multierror v1.0.0 // indirect + github.com/hashicorp/go-multierror v1.1.1 // indirect + github.com/hashicorp/terraform-plugin-go v0.19.0 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect - github.com/huandu/xstrings v1.3.2 // indirect - github.com/imdario/mergo v0.3.11 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect + github.com/huandu/xstrings v1.4.0 // indirect + github.com/imdario/mergo v0.3.16 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect - github.com/posener/complete v1.1.1 // indirect - github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.3.1 // indirect - github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect + github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/posener/complete v1.2.3 // indirect + github.com/shopspring/decimal v1.3.1 // indirect + github.com/spf13/cast v1.5.1 // indirect + github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect + github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect - golang.org/x/crypto v0.11.0 // indirect - golang.org/x/sys v0.10.0 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/sys v0.13.0 // indirect ) diff --git a/go.sum b/go.sum index 53729703..767538f2 100644 --- a/go.sum +++ b/go.sum @@ -1,103 +1,158 @@ github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/Masterminds/sprig/v3 v3.2.1 h1:n6EPaDyLSvCEa3frruQvAiHuNp2dhBlMSmkEr+HuzGc= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0= +github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310 h1:BUAU3CGlLvorLI26FmByPp2eC2qla6E1Tw+scpcg/to= +github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= +github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= +github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= +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/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc h1:VmMk5vOSJgpWOuBsI4ZBZkcsrkLq0fKoyKvKFnbBuxk= github.com/hashicorp/terraform-plugin-codegen-spec v0.1.1-0.20231024091233-c659ac8a54fc/go.mod h1:PQn6bDD8UWoAVJoHXqFk2i/RmLbeQBjbiP38i+E+YIw= -github.com/hashicorp/terraform-plugin-framework v1.4.0 h1:WKbtCRtNrjsh10eA7NZvC/Qyr7zp77j+D21aDO5th9c= -github.com/hashicorp/terraform-plugin-framework v1.4.0/go.mod h1:XC0hPcQbBvlbxwmjxuV/8sn8SbZRg4XwGMs22f+kqV0= +github.com/hashicorp/terraform-plugin-framework v1.4.2 h1:P7a7VP1GZbjc4rv921Xy5OckzhoiO3ig6SGxwelD2sI= +github.com/hashicorp/terraform-plugin-framework v1.4.2/go.mod h1:GWl3InPFZi2wVQmdVnINPKys09s9mLmTZr95/ngLnbY= github.com/hashicorp/terraform-plugin-go v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU= github.com/hashicorp/terraform-plugin-go v0.19.0/go.mod h1:EhRSkEPNoylLQntYsk5KrDHTZJh9HQoumZXbOGOXmec= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU= +github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= +github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= +github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 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.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw= +github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ= +github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1 h1:ccV59UEOTzVDnDUEFdT95ZzHVZ+5+158q8+SJb2QV5w= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= +github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= +github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= -github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= -github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc= +github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= +github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= -github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= +github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= -golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= -golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/cmd/generate_all.go b/internal/cmd/generate_all.go index 1b1097de..a97ed3e3 100644 --- a/internal/cmd/generate_all.go +++ b/internal/cmd/generate_all.go @@ -7,6 +7,8 @@ import ( "context" "flag" "fmt" + "log/slog" + "os" "strings" "github.com/hashicorp/terraform-plugin-codegen-spec/spec" @@ -70,30 +72,34 @@ func (cmd *GenerateAllCommand) Help() string { return strBuilder.String() } -func (a *GenerateAllCommand) Synopsis() string { +func (cmd *GenerateAllCommand) Synopsis() string { return "Generate code for provider, resources, and data sources from an Intermediate Representation (IR) JSON file." } func (cmd *GenerateAllCommand) Run(args []string) int { ctx := context.Background() + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelWarn, + })) + fs := cmd.Flags() err := fs.Parse(args) if err != nil { - cmd.UI.Error(fmt.Sprintf("error parsing command flags: %s", err)) + logger.Error("error parsing command flags", "err", err) return 1 } - err = cmd.runInternal(ctx) + err = cmd.runInternal(ctx, logger) if err != nil { - cmd.UI.Error(fmt.Sprintf("Error executing command: %s\n", err)) + logger.Error("error executing command", "err", err) return 1 } return 0 } -func (cmd *GenerateAllCommand) runInternal(ctx context.Context) error { +func (cmd *GenerateAllCommand) runInternal(ctx context.Context, logger *slog.Logger) error { // read input file src, err := input.Read(cmd.flagIRInputPath) if err != nil { @@ -112,15 +118,17 @@ func (cmd *GenerateAllCommand) runInternal(ctx context.Context) error { return fmt.Errorf("error parsing IR JSON: %w", err) } - err = generateDataSourceCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "DataSource") + err = generateDataSourceCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "DataSource", logger) if err != nil { return fmt.Errorf("error generating data source code: %w", err) } - err = generateResourceCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "Resource") + + err = generateResourceCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "Resource", logger) if err != nil { return fmt.Errorf("error generating resource code: %w", err) } - err = generateProviderCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "Provider") + + err = generateProviderCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "Provider", logger) if err != nil { return fmt.Errorf("error generating provider code: %w", err) } diff --git a/internal/cmd/generate_data_sources.go b/internal/cmd/generate_data_sources.go index 0741fc84..524b474e 100644 --- a/internal/cmd/generate_data_sources.go +++ b/internal/cmd/generate_data_sources.go @@ -8,6 +8,8 @@ import ( "flag" "fmt" "log" + "log/slog" + "os" "strings" "github.com/hashicorp/terraform-plugin-codegen-spec/spec" @@ -16,6 +18,7 @@ import ( "github.com/hashicorp/terraform-plugin-codegen-framework/internal/datasource_convert" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/format" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/input" + "github.com/hashicorp/terraform-plugin-codegen-framework/internal/logging" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/output" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/schema" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/validate" @@ -82,6 +85,10 @@ func (a *GenerateDataSourcesCommand) Synopsis() string { func (cmd *GenerateDataSourcesCommand) Run(args []string) int { ctx := context.Background() + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelWarn, + })) + fs := cmd.Flags() err := fs.Parse(args) if err != nil { @@ -89,7 +96,7 @@ func (cmd *GenerateDataSourcesCommand) Run(args []string) int { return 1 } - err = cmd.runInternal(ctx) + err = cmd.runInternal(ctx, logger) if err != nil { cmd.UI.Error(fmt.Sprintf("Error executing command: %s\n", err)) return 1 @@ -98,7 +105,7 @@ func (cmd *GenerateDataSourcesCommand) Run(args []string) int { return 0 } -func (cmd *GenerateDataSourcesCommand) runInternal(ctx context.Context) error { +func (cmd *GenerateDataSourcesCommand) runInternal(ctx context.Context, logger *slog.Logger) error { // read input file src, err := input.Read(cmd.flagIRInputPath) if err != nil { @@ -117,7 +124,7 @@ func (cmd *GenerateDataSourcesCommand) runInternal(ctx context.Context) error { return fmt.Errorf("error parsing IR JSON: %w", err) } - err = generateDataSourceCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "DataSource") + err = generateDataSourceCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "DataSource", logger) if err != nil { return fmt.Errorf("error generating data source code: %w", err) } @@ -125,7 +132,9 @@ func (cmd *GenerateDataSourcesCommand) runInternal(ctx context.Context) error { return nil } -func generateDataSourceCode(spec spec.Specification, outputPath, packageName, generatorType string) error { +func generateDataSourceCode(ctx context.Context, spec spec.Specification, outputPath, packageName, generatorType string, logger *slog.Logger) error { + ctxWithPath := logging.SetPathInContext(ctx, "data_source") + // convert IR to framework schema c := datasource_convert.NewConverter(spec) s, err := c.ToGeneratorDataSourceSchema() @@ -153,7 +162,7 @@ func generateDataSourceCode(spec spec.Specification, outputPath, packageName, ge } // generate "expand" and "flatten" code - toFromFunctions, err := g.ToFromFunctions() + toFromFunctions, err := g.ToFromFunctions(ctxWithPath, logger) if err != nil { log.Fatal(err) } diff --git a/internal/cmd/generate_provider.go b/internal/cmd/generate_provider.go index 7d8ae240..b099f5d8 100644 --- a/internal/cmd/generate_provider.go +++ b/internal/cmd/generate_provider.go @@ -8,6 +8,8 @@ import ( "flag" "fmt" "log" + "log/slog" + "os" "strings" "github.com/hashicorp/terraform-plugin-codegen-spec/spec" @@ -15,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-codegen-framework/internal/format" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/input" + "github.com/hashicorp/terraform-plugin-codegen-framework/internal/logging" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/output" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/provider_convert" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/schema" @@ -82,6 +85,10 @@ func (a *GenerateProviderCommand) Synopsis() string { func (cmd *GenerateProviderCommand) Run(args []string) int { ctx := context.Background() + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelWarn, + })) + fs := cmd.Flags() err := fs.Parse(args) if err != nil { @@ -89,7 +96,7 @@ func (cmd *GenerateProviderCommand) Run(args []string) int { return 1 } - err = cmd.runInternal(ctx) + err = cmd.runInternal(ctx, logger) if err != nil { cmd.UI.Error(fmt.Sprintf("Error executing command: %s\n", err)) return 1 @@ -98,7 +105,7 @@ func (cmd *GenerateProviderCommand) Run(args []string) int { return 0 } -func (cmd *GenerateProviderCommand) runInternal(ctx context.Context) error { +func (cmd *GenerateProviderCommand) runInternal(ctx context.Context, logger *slog.Logger) error { // read input file src, err := input.Read(cmd.flagIRInputPath) if err != nil { @@ -117,7 +124,7 @@ func (cmd *GenerateProviderCommand) runInternal(ctx context.Context) error { return fmt.Errorf("error parsing IR JSON: %w", err) } - err = generateProviderCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "Provider") + err = generateProviderCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "Provider", logger) if err != nil { return fmt.Errorf("error generating provider code: %w", err) } @@ -125,7 +132,9 @@ func (cmd *GenerateProviderCommand) runInternal(ctx context.Context) error { return nil } -func generateProviderCode(spec spec.Specification, outputPath, packageName, generatorType string) error { +func generateProviderCode(ctx context.Context, spec spec.Specification, outputPath, packageName, generatorType string, logger *slog.Logger) error { + ctx = logging.SetPathInContext(ctx, "provider") + // convert IR to framework schema c := provider_convert.NewConverter(spec) s, err := c.ToGeneratorProviderSchema() @@ -153,7 +162,7 @@ func generateProviderCode(spec spec.Specification, outputPath, packageName, gene } // generate "expand" and "flatten" code - toFromFunctions, err := g.ToFromFunctions() + toFromFunctions, err := g.ToFromFunctions(ctx, logger) if err != nil { log.Fatal(err) } diff --git a/internal/cmd/generate_resources.go b/internal/cmd/generate_resources.go index e02b6580..70d23107 100644 --- a/internal/cmd/generate_resources.go +++ b/internal/cmd/generate_resources.go @@ -8,6 +8,8 @@ import ( "flag" "fmt" "log" + "log/slog" + "os" "strings" "github.com/hashicorp/terraform-plugin-codegen-spec/spec" @@ -15,6 +17,7 @@ import ( "github.com/hashicorp/terraform-plugin-codegen-framework/internal/format" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/input" + "github.com/hashicorp/terraform-plugin-codegen-framework/internal/logging" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/output" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/resource_convert" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/schema" @@ -82,6 +85,10 @@ func (a *GenerateResourcesCommand) Synopsis() string { func (cmd *GenerateResourcesCommand) Run(args []string) int { ctx := context.Background() + logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ + Level: slog.LevelWarn, + })) + fs := cmd.Flags() err := fs.Parse(args) if err != nil { @@ -89,7 +96,7 @@ func (cmd *GenerateResourcesCommand) Run(args []string) int { return 1 } - err = cmd.runInternal(ctx) + err = cmd.runInternal(ctx, logger) if err != nil { cmd.UI.Error(fmt.Sprintf("Error executing command: %s\n", err)) return 1 @@ -98,7 +105,7 @@ func (cmd *GenerateResourcesCommand) Run(args []string) int { return 0 } -func (cmd *GenerateResourcesCommand) runInternal(ctx context.Context) error { +func (cmd *GenerateResourcesCommand) runInternal(ctx context.Context, logger *slog.Logger) error { // read input file src, err := input.Read(cmd.flagIRInputPath) if err != nil { @@ -117,7 +124,7 @@ func (cmd *GenerateResourcesCommand) runInternal(ctx context.Context) error { return fmt.Errorf("error parsing IR JSON: %w", err) } - err = generateResourceCode(spec, cmd.flagOutputPath, cmd.flagPackageName, "Resource") + err = generateResourceCode(ctx, spec, cmd.flagOutputPath, cmd.flagPackageName, "Resource", logger) if err != nil { return fmt.Errorf("error generating resource code: %w", err) } @@ -125,7 +132,9 @@ func (cmd *GenerateResourcesCommand) runInternal(ctx context.Context) error { return nil } -func generateResourceCode(spec spec.Specification, outputPath, packageName, generatorType string) error { +func generateResourceCode(ctx context.Context, spec spec.Specification, outputPath, packageName, generatorType string, logger *slog.Logger) error { + ctx = logging.SetPathInContext(ctx, "resource") + // convert IR to framework schema c := resource_convert.NewConverter(spec) s, err := c.ToGeneratorResourceSchema() @@ -153,7 +162,7 @@ func generateResourceCode(spec spec.Specification, outputPath, packageName, gene } // generate "expand" and "flatten" code - toFromFunctions, err := g.ToFromFunctions() + toFromFunctions, err := g.ToFromFunctions(ctx, logger) if err != nil { log.Fatal(err) } diff --git a/internal/datasource_generate/list_attribute.go b/internal/datasource_generate/list_attribute.go index 7097f24c..c0f2dff5 100644 --- a/internal/datasource_generate/list_attribute.go +++ b/internal/datasource_generate/list_attribute.go @@ -205,7 +205,12 @@ func (g GeneratorListAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromList(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/datasource_generate/list_nested_attribute.go b/internal/datasource_generate/list_nested_attribute.go index 792769c9..3cabbdb2 100644 --- a/internal/datasource_generate/list_nested_attribute.go +++ b/internal/datasource_generate/list_nested_attribute.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro return buf.Bytes(), nil } + +func (g GeneratorListNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/list_nested_block.go b/internal/datasource_generate/list_nested_block.go index c947a85e..d8bd5b88 100644 --- a/internal/datasource_generate/list_nested_block.go +++ b/internal/datasource_generate/list_nested_block.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -296,9 +297,17 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -328,3 +337,11 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorListNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/map_attribute.go b/internal/datasource_generate/map_attribute.go index 767d06f1..82ed7e4e 100644 --- a/internal/datasource_generate/map_attribute.go +++ b/internal/datasource_generate/map_attribute.go @@ -205,7 +205,12 @@ func (g GeneratorMapAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromMap(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/datasource_generate/map_nested_attribute.go b/internal/datasource_generate/map_nested_attribute.go index a32fd45c..4767362e 100644 --- a/internal/datasource_generate/map_nested_attribute.go +++ b/internal/datasource_generate/map_nested_attribute.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorMapNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} + +func (g GeneratorMapNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/object_attribute.go b/internal/datasource_generate/object_attribute.go index 326813dc..12ea7cb0 100644 --- a/internal/datasource_generate/object_attribute.go +++ b/internal/datasource_generate/object_attribute.go @@ -174,9 +174,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) { return nil, nil } - attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) + attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) - attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + if err != nil { + return nil, err + } + + attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs) diff --git a/internal/datasource_generate/set_attribute.go b/internal/datasource_generate/set_attribute.go index 53c1fe27..b4bed7a9 100644 --- a/internal/datasource_generate/set_attribute.go +++ b/internal/datasource_generate/set_attribute.go @@ -205,7 +205,12 @@ func (g GeneratorSetAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromSet(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/datasource_generate/set_nested_attribute.go b/internal/datasource_generate/set_nested_attribute.go index 988094c5..69cbdc43 100644 --- a/internal/datasource_generate/set_nested_attribute.go +++ b/internal/datasource_generate/set_nested_attribute.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorSetNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/set_nested_block.go b/internal/datasource_generate/set_nested_block.go index 641bed02..3c626be4 100644 --- a/internal/datasource_generate/set_nested_block.go +++ b/internal/datasource_generate/set_nested_block.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -296,9 +297,17 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -328,3 +337,11 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorSetNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/single_nested_attribute.go b/internal/datasource_generate/single_nested_attribute.go index d2bca25b..416ea7ff 100644 --- a/internal/datasource_generate/single_nested_attribute.go +++ b/internal/datasource_generate/single_nested_attribute.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -220,9 +221,13 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -252,3 +257,11 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er return buf.Bytes(), nil } + +func (g GeneratorSingleNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/datasource_generate/single_nested_block.go b/internal/datasource_generate/single_nested_block.go index f41618fc..c66e5d00 100644 --- a/internal/datasource_generate/single_nested_block.go +++ b/internal/datasource_generate/single_nested_block.go @@ -5,6 +5,7 @@ package datasource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -310,9 +311,13 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -342,3 +347,11 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) return buf.Bytes(), nil } + +func (g GeneratorSingleNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/logging/context.go b/internal/logging/context.go new file mode 100644 index 00000000..41cdaa69 --- /dev/null +++ b/internal/logging/context.go @@ -0,0 +1,34 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package logging + +import ( + "context" + "strings" +) + +type pathstring string + +const path pathstring = "path" + +type Path []string + +// SetPathInContext is used to maintain a path indicating the current +// location within the schema that is being processed. +func SetPathInContext(ctx context.Context, pathStep string) context.Context { + if v, ok := ctx.Value(path).(Path); ok { + return context.WithValue(ctx, path, append(v, pathStep)) + } + + return context.WithValue(ctx, path, Path{pathStep}) +} + +// GetPathFromContext returns a dot-separated path. +func GetPathFromContext(ctx context.Context) string { + if v, ok := ctx.Value(path).(Path); ok { + return strings.Join(v, ".") + } + + return "" +} diff --git a/internal/provider_generate/list_attribute.go b/internal/provider_generate/list_attribute.go index d12baf08..f791b4c0 100644 --- a/internal/provider_generate/list_attribute.go +++ b/internal/provider_generate/list_attribute.go @@ -201,7 +201,12 @@ func (g GeneratorListAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromList(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/provider_generate/list_nested_attribute.go b/internal/provider_generate/list_nested_attribute.go index 3c188672..35296a47 100644 --- a/internal/provider_generate/list_nested_attribute.go +++ b/internal/provider_generate/list_nested_attribute.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro return buf.Bytes(), nil } + +func (g GeneratorListNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/provider_generate/list_nested_block.go b/internal/provider_generate/list_nested_block.go index 650ff4d6..37357122 100644 --- a/internal/provider_generate/list_nested_block.go +++ b/internal/provider_generate/list_nested_block.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -296,9 +297,17 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -328,3 +337,11 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorListNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/provider_generate/map_attribute.go b/internal/provider_generate/map_attribute.go index c0308a22..bf51d493 100644 --- a/internal/provider_generate/map_attribute.go +++ b/internal/provider_generate/map_attribute.go @@ -201,7 +201,12 @@ func (g GeneratorMapAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromMap(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/provider_generate/map_nested_attribute.go b/internal/provider_generate/map_nested_attribute.go index eb903ccd..9e4a5a7d 100644 --- a/internal/provider_generate/map_nested_attribute.go +++ b/internal/provider_generate/map_nested_attribute.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorMapNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} + +func (g GeneratorMapNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} diff --git a/internal/provider_generate/object_attribute.go b/internal/provider_generate/object_attribute.go index b37ed7d6..40b43edf 100644 --- a/internal/provider_generate/object_attribute.go +++ b/internal/provider_generate/object_attribute.go @@ -174,9 +174,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) { return nil, nil } - attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) + attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) - attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + if err != nil { + return nil, err + } + + attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs) diff --git a/internal/provider_generate/set_attribute.go b/internal/provider_generate/set_attribute.go index 5154a08e..b796aec1 100644 --- a/internal/provider_generate/set_attribute.go +++ b/internal/provider_generate/set_attribute.go @@ -201,7 +201,12 @@ func (g GeneratorSetAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromSet(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/provider_generate/set_nested_attribute.go b/internal/provider_generate/set_nested_attribute.go index a9e88df4..6d269764 100644 --- a/internal/provider_generate/set_nested_attribute.go +++ b/internal/provider_generate/set_nested_attribute.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -217,9 +218,17 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -249,3 +258,11 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorSetNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/provider_generate/set_nested_block.go b/internal/provider_generate/set_nested_block.go index a1ae7ba6..b8745b3b 100644 --- a/internal/provider_generate/set_nested_block.go +++ b/internal/provider_generate/set_nested_block.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -296,9 +297,17 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -328,3 +337,11 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorSetNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/provider_generate/single_nested_attribute.go b/internal/provider_generate/single_nested_attribute.go index 7dda7464..381f2d1a 100644 --- a/internal/provider_generate/single_nested_attribute.go +++ b/internal/provider_generate/single_nested_attribute.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -220,9 +221,13 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -252,3 +257,11 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er return buf.Bytes(), nil } + +func (g GeneratorSingleNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/provider_generate/single_nested_block.go b/internal/provider_generate/single_nested_block.go index 01a392ed..304d55d9 100644 --- a/internal/provider_generate/single_nested_block.go +++ b/internal/provider_generate/single_nested_block.go @@ -5,6 +5,7 @@ package provider_generate import ( "bytes" + "errors" "strings" "text/template" @@ -310,9 +311,13 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -342,3 +347,11 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) return buf.Bytes(), nil } + +func (g GeneratorSingleNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/resource_generate/list_attribute.go b/internal/resource_generate/list_attribute.go index 1a176260..983ea240 100644 --- a/internal/resource_generate/list_attribute.go +++ b/internal/resource_generate/list_attribute.go @@ -235,7 +235,12 @@ func (g GeneratorListAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromList(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/resource_generate/list_nested_attribute.go b/internal/resource_generate/list_nested_attribute.go index 116534fc..619ecde6 100644 --- a/internal/resource_generate/list_nested_attribute.go +++ b/internal/resource_generate/list_nested_attribute.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -242,9 +243,17 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -274,3 +283,11 @@ func (g GeneratorListNestedAttribute) ToFromFunctions(name string) ([]byte, erro return buf.Bytes(), nil } + +func (g GeneratorListNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/resource_generate/list_nested_block.go b/internal/resource_generate/list_nested_block.go index 2e2e48dc..483bdfac 100644 --- a/internal/resource_generate/list_nested_block.go +++ b/internal/resource_generate/list_nested_block.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -313,9 +314,17 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -345,3 +354,11 @@ func (g GeneratorListNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorListNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} + +func (g GeneratorListNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("list nested type is not yet implemented")) +} diff --git a/internal/resource_generate/map_attribute.go b/internal/resource_generate/map_attribute.go index 65d36158..6ff3dbc7 100644 --- a/internal/resource_generate/map_attribute.go +++ b/internal/resource_generate/map_attribute.go @@ -239,7 +239,12 @@ func (g GeneratorMapAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromMap(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/resource_generate/map_nested_attribute.go b/internal/resource_generate/map_nested_attribute.go index 47d936e3..ebb09e23 100644 --- a/internal/resource_generate/map_nested_attribute.go +++ b/internal/resource_generate/map_nested_attribute.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -242,9 +243,17 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -274,3 +283,11 @@ func (g GeneratorMapNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorMapNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} + +func (g GeneratorMapNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("map nested type is not yet implemented")) +} diff --git a/internal/resource_generate/object_attribute.go b/internal/resource_generate/object_attribute.go index 15c073e6..4f7b0901 100644 --- a/internal/resource_generate/object_attribute.go +++ b/internal/resource_generate/object_attribute.go @@ -207,9 +207,17 @@ func (g GeneratorObjectAttribute) ToFromFunctions(name string) ([]byte, error) { return nil, nil } - attrTypesToFuncs := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) + attrTypesToFuncs, err := generatorschema.GetAttrTypesToFuncs(g.AttributeTypes) - attrTypesFromFuncs := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + if err != nil { + return nil, err + } + + attrTypesFromFuncs, err := generatorschema.GetAttrTypesFromFuncs(g.AttributeTypes) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromObject(name, g.AssociatedExternalType, attrTypesToFuncs, attrTypesFromFuncs) diff --git a/internal/resource_generate/set_attribute.go b/internal/resource_generate/set_attribute.go index 8aa8818e..60ea9484 100644 --- a/internal/resource_generate/set_attribute.go +++ b/internal/resource_generate/set_attribute.go @@ -239,7 +239,12 @@ func (g GeneratorSetAttribute) ToFromFunctions(name string) ([]byte, error) { elementTypeType := generatorschema.GetElementType(g.ElementType) elementTypeValue := generatorschema.GetElementValueType(g.ElementType) - elementFrom := generatorschema.GetElementFromFunc(g.ElementType) + + elementFrom, err := generatorschema.GetElementFromFunc(g.ElementType) + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromSet(name, g.AssociatedExternalType, elementTypeType, elementTypeValue, elementFrom) diff --git a/internal/resource_generate/set_nested_attribute.go b/internal/resource_generate/set_nested_attribute.go index 8befce83..02efad5c 100644 --- a/internal/resource_generate/set_nested_attribute.go +++ b/internal/resource_generate/set_nested_attribute.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -242,9 +243,17 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -274,3 +283,11 @@ func (g GeneratorSetNestedAttribute) ToFromFunctions(name string) ([]byte, error return buf.Bytes(), nil } + +func (g GeneratorSetNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/resource_generate/set_nested_block.go b/internal/resource_generate/set_nested_block.go index 8361462f..2db087d4 100644 --- a/internal/resource_generate/set_nested_block.go +++ b/internal/resource_generate/set_nested_block.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -311,9 +312,17 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { var buf bytes.Buffer - toFuncs := g.NestedObject.Attributes.ToFuncs() + toFuncs, err := g.NestedObject.Attributes.ToFuncs() - fromFuncs := g.NestedObject.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, err := g.NestedObject.Attributes.FromFuncs() + + if err != nil { + return nil, err + } toFrom := generatorschema.NewToFromNestedObject(name, g.NestedObject.AssociatedExternalType, toFuncs, fromFuncs) @@ -343,3 +352,11 @@ func (g GeneratorSetNestedBlock) ToFromFunctions(name string) ([]byte, error) { return buf.Bytes(), nil } + +func (g GeneratorSetNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} + +func (g GeneratorSetNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("set nested type is not yet implemented")) +} diff --git a/internal/resource_generate/single_nested_attribute.go b/internal/resource_generate/single_nested_attribute.go index 263f2fc5..27439643 100644 --- a/internal/resource_generate/single_nested_attribute.go +++ b/internal/resource_generate/single_nested_attribute.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -240,9 +241,13 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -272,3 +277,11 @@ func (g GeneratorSingleNestedAttribute) ToFromFunctions(name string) ([]byte, er return buf.Bytes(), nil } + +func (g GeneratorSingleNestedAttribute) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedAttribute) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/resource_generate/single_nested_block.go b/internal/resource_generate/single_nested_block.go index a81e49dd..39fd03d7 100644 --- a/internal/resource_generate/single_nested_block.go +++ b/internal/resource_generate/single_nested_block.go @@ -5,6 +5,7 @@ package resource_generate import ( "bytes" + "errors" "strings" "text/template" @@ -320,9 +321,13 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) var buf bytes.Buffer - toFuncs := g.Attributes.ToFuncs() + toFuncs, err := g.Attributes.ToFuncs() - fromFuncs := g.Attributes.FromFuncs() + if err != nil { + return nil, err + } + + fromFuncs, _ := g.Attributes.FromFuncs() toFrom := generatorschema.NewToFromNestedObject(name, g.AssociatedExternalType, toFuncs, fromFuncs) @@ -352,3 +357,11 @@ func (g GeneratorSingleNestedBlock) ToFromFunctions(name string) ([]byte, error) return buf.Bytes(), nil } + +func (g GeneratorSingleNestedBlock) To() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} + +func (g GeneratorSingleNestedBlock) From() (generatorschema.ToFromConversion, error) { + return generatorschema.ToFromConversion{}, generatorschema.NewUnimplementedError(errors.New("single nested type is not yet implemented")) +} diff --git a/internal/schema/attributes.go b/internal/schema/attributes.go index 6df69636..b0cc85f3 100644 --- a/internal/schema/attributes.go +++ b/internal/schema/attributes.go @@ -4,6 +4,7 @@ package schema import ( + "errors" "fmt" "sort" "strings" @@ -150,18 +151,30 @@ func (g GeneratorAttributes) CollectionTypes() (map[string]map[string]string, er // FromFuncs returns a mapping of attribute names to string representations of the // function that converts a Go value to a framework value. -func (g GeneratorAttributes) FromFuncs() map[string]ToFromConversion { +func (g GeneratorAttributes) FromFuncs() (map[string]ToFromConversion, error) { attributeKeys := g.SortedKeys() fromFuncs := make(map[string]ToFromConversion, len(g)) for _, k := range attributeKeys { if a, ok := g[k].(From); ok { - fromFuncs[k], _ = a.From() + v, err := a.From() + + var unimplError *UnimplementedError + + if errors.As(err, &unimplError) { + err = unimplError.NestedUnimplementedError(k) + } + + if err != nil { + return nil, err + } + + fromFuncs[k] = v } } - return fromFuncs + return fromFuncs, nil } func (g GeneratorAttributes) Schema() (string, error) { @@ -194,19 +207,32 @@ func (g GeneratorAttributes) Schema() (string, error) { } // ToFuncs returns a mapping of attribute names to string representations of the -// function that converts a framework value to a Go value. -func (g GeneratorAttributes) ToFuncs() map[string]ToFromConversion { +// function that converts a framework value to a Go value. If an UnimplementedError +// is encountered, it is logged and execution continues. +func (g GeneratorAttributes) ToFuncs() (map[string]ToFromConversion, error) { attributeKeys := g.SortedKeys() toFuncs := make(map[string]ToFromConversion, len(g)) for _, k := range attributeKeys { if a, ok := g[k].(To); ok { - toFuncs[k], _ = a.To() + v, err := a.To() + + var unimplError *UnimplementedError + + if errors.As(err, &unimplError) { + err = unimplError.NestedUnimplementedError(k) + } + + if err != nil { + return nil, err + } + + toFuncs[k] = v } } - return toFuncs + return toFuncs, nil } func (g GeneratorAttributes) SortedKeys() []string { diff --git a/internal/schema/attrtypes.go b/internal/schema/attrtypes.go index e145db62..178d1962 100644 --- a/internal/schema/attrtypes.go +++ b/internal/schema/attrtypes.go @@ -4,6 +4,7 @@ package schema import ( + "errors" "fmt" "strings" @@ -93,7 +94,7 @@ type AttrTypesToFuncs struct { // GetAttrTypesToFuncs returns string representations of the function that is used // for converting to an API Go type from a framework type. // TODO: Handle custom type, and types other than primitives. -func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypesToFuncs { +func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) (map[string]AttrTypesToFuncs, error) { attrTypesFuncs := make(map[string]AttrTypesToFuncs, len(a)) for _, v := range a { @@ -113,11 +114,20 @@ func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypes AttrValue: "types.Int64", ToFunc: "ValueInt64Pointer", } + case v.List != nil: + return nil, NewUnimplementedError(errors.New("list attribute type is not yet implemented")) + case v.Map != nil: + return nil, NewUnimplementedError(errors.New("map attribute type is not yet implemented")) + case v.Number != nil: attrTypesFuncs[v.Name] = AttrTypesToFuncs{ AttrValue: "types.Number", ToFunc: "ValueBigFloat", } + case v.Object != nil: + return nil, NewUnimplementedError(errors.New("object attribute type is not yet implemented")) + case v.Set != nil: + return nil, NewUnimplementedError(errors.New("set attribute type is not yet implemented")) case v.String != nil: attrTypesFuncs[v.Name] = AttrTypesToFuncs{ AttrValue: "types.String", @@ -126,13 +136,13 @@ func GetAttrTypesToFuncs(a specschema.ObjectAttributeTypes) map[string]AttrTypes } } - return attrTypesFuncs + return attrTypesFuncs, nil } // GetAttrTypesFromFuncs returns string representations of the function that is used // for converting from an API Go type to a framework type. // TODO: Handle custom type, and types other than primitives. -func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) map[string]string { +func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) (map[string]string, error) { attrTypesFuncs := make(map[string]string, len(a)) for _, v := range a { @@ -143,12 +153,20 @@ func GetAttrTypesFromFuncs(a specschema.ObjectAttributeTypes) map[string]string attrTypesFuncs[v.Name] = "types.Float64PointerValue" case v.Int64 != nil: attrTypesFuncs[v.Name] = "types.Int64PointerValue" + case v.List != nil: + return nil, NewUnimplementedError(errors.New("list attribute type is not yet implemented")) + case v.Map != nil: + return nil, NewUnimplementedError(errors.New("map attribute type is not yet implemented")) case v.Number != nil: attrTypesFuncs[v.Name] = "types.NumberValue" + case v.Object != nil: + return nil, NewUnimplementedError(errors.New("object attribute type is not yet implemented")) + case v.Set != nil: + return nil, NewUnimplementedError(errors.New("set attribute type is not yet implemented")) case v.String != nil: attrTypesFuncs[v.Name] = "types.StringPointerValue" } } - return attrTypesFuncs + return attrTypesFuncs, nil } diff --git a/internal/schema/elements.go b/internal/schema/elements.go index 51d58d87..bae3fabf 100644 --- a/internal/schema/elements.go +++ b/internal/schema/elements.go @@ -4,6 +4,7 @@ package schema import ( + "errors" "fmt" specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema" @@ -120,19 +121,27 @@ func GetElementValueType(e specschema.ElementType) string { // GetElementFromFunc returns a string representation of the function that is used // for converting from an API Go type to a framework type. // TODO: Handle custom type, and types other than primitives. -func GetElementFromFunc(e specschema.ElementType) string { +func GetElementFromFunc(e specschema.ElementType) (string, error) { switch { case e.Bool != nil: - return "types.BoolPointerValue" + return "types.BoolPointerValue", nil case e.Float64 != nil: - return "types.Float64PointerValue" + return "types.Float64PointerValue", nil case e.Int64 != nil: - return "types.Int64PointerValue" + return "types.Int64PointerValue", nil + case e.List != nil: + return "", NewUnimplementedError(errors.New("list element type is not yet implemented")) + case e.Map != nil: + return "", NewUnimplementedError(errors.New("map element type is not yet implemented")) case e.Number != nil: - return "types.NumberValue" + return "types.NumberValue", nil + case e.Object != nil: + return "", NewUnimplementedError(errors.New("object element type is not yet implemented")) + case e.Set != nil: + return "", NewUnimplementedError(errors.New("set element type is not yet implemented")) case e.String != nil: - return "types.StringPointerValue" + return "types.StringPointerValue", nil } - return "" + return "", nil } diff --git a/internal/schema/errors.go b/internal/schema/errors.go new file mode 100644 index 00000000..77e4d0e4 --- /dev/null +++ b/internal/schema/errors.go @@ -0,0 +1,45 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package schema + +import "strings" + +// UnimplementedError is used to indicate that the operation +// being performed is not yet implemented. It is primarily used +// to permit execution of code generation to continue whilst +// logging any unimplemented operations. +type UnimplementedError struct { + err error + path []string +} + +// Error returns the underlying error string. +func (e *UnimplementedError) Error() string { + return e.err.Error() +} + +// Path returns a dot-separated path. +func (e *UnimplementedError) Path() string { + return strings.Join(e.path, ".") +} + +// NewUnimplementedError returns an UnimplementedError populated with the +// supplied error and path. +func NewUnimplementedError(err error, path ...string) *UnimplementedError { + return &UnimplementedError{ + err: err, + path: path, + } +} + +// NestedUnimplementedError returns an UnimplementedError with a path that includes +// the supplied parentPath. +func (e *UnimplementedError) NestedUnimplementedError(parentPath string) *UnimplementedError { + newErr := &UnimplementedError{ + err: e.err, + path: append([]string{parentPath}, e.path...), + } + + return newErr +} diff --git a/internal/schema/schema.go b/internal/schema/schema.go index f1879f6a..17310b1b 100644 --- a/internal/schema/schema.go +++ b/internal/schema/schema.go @@ -5,14 +5,17 @@ package schema import ( "bytes" + "context" "errors" "fmt" + "log/slog" "strings" "text/template" "github.com/hashicorp/terraform-plugin-codegen-spec/code" specschema "github.com/hashicorp/terraform-plugin-codegen-spec/schema" + "github.com/hashicorp/terraform-plugin-codegen-framework/internal/logging" "github.com/hashicorp/terraform-plugin-codegen-framework/internal/model" ) @@ -266,7 +269,7 @@ func (g GeneratorSchema) CustomTypeValueBytes() ([]byte, error) { // ToFromFunctions generates code for converting to an associated // external type from a framework type, and from an associated // external type to a framework type. -func (g GeneratorSchema) ToFromFunctions() ([]byte, error) { +func (g GeneratorSchema) ToFromFunctions(ctx context.Context, logger *slog.Logger) ([]byte, error) { var buf bytes.Buffer attributeKeys := g.Attributes.SortedKeys() @@ -279,7 +282,11 @@ func (g GeneratorSchema) ToFromFunctions() ([]byte, error) { if t, ok := g.Attributes[k].(ToFrom); ok { b, err := t.ToFromFunctions(k) - if err != nil { + var unimplErr *UnimplementedError + + if errors.As(err, &unimplErr) { + logger.Error("error generating to/from methods", "path", fmt.Sprintf("%s.%s.%s", logging.GetPathFromContext(ctx), k, unimplErr.Path()), "err", err) + } else if err != nil { return nil, err } @@ -301,7 +308,11 @@ func (g GeneratorSchema) ToFromFunctions() ([]byte, error) { if t, ok := g.Blocks[k].(ToFrom); ok { b, err := t.ToFromFunctions(k) - if err != nil { + var unimplErr *UnimplementedError + + if errors.As(err, &unimplErr) { + logger.Error("error generating to/from methods", "path", fmt.Sprintf("%s.%s.%s", logging.GetPathFromContext(ctx), k, unimplErr.Path()), "err", err) + } else if err != nil { return nil, err } @@ -365,8 +376,16 @@ func ElementTypeGoType(elementType specschema.ElementType) (string, error) { return "*float64", nil case elementType.Int64 != nil: return "*int64", nil + case elementType.List != nil: + return "", NewUnimplementedError(errors.New("list element type is not yet implemented")) + case elementType.Map != nil: + return "", NewUnimplementedError(errors.New("map element type is not yet implemented")) case elementType.Number != nil: return "*big.Float", nil + case elementType.Object != nil: + return "", NewUnimplementedError(errors.New("object element type is not yet implemented")) + case elementType.Set != nil: + return "", NewUnimplementedError(errors.New("set element type is not yet implemented")) case elementType.String != nil: return "*string", nil } @@ -439,12 +458,20 @@ func ObjectFieldTo(o specschema.ObjectAttributeType) (ObjectField, error) { Type: "types.Int64", ToFunc: "ValueInt64Pointer", }, nil + case o.List != nil: + return ObjectField{}, NewUnimplementedError(errors.New("list attribute type is not yet implemented")) + case o.Map != nil: + return ObjectField{}, NewUnimplementedError(errors.New("map attribute type is not yet implemented")) case o.Number != nil: return ObjectField{ GoType: "*big.Float", Type: "types.Number", ToFunc: "ValueBigFloat", }, nil + case o.Object != nil: + return ObjectField{}, NewUnimplementedError(errors.New("object attribute type is not yet implemented")) + case o.Set != nil: + return ObjectField{}, NewUnimplementedError(errors.New("set attribute type is not yet implemented")) case o.String != nil: return ObjectField{ GoType: "*string", @@ -473,11 +500,19 @@ func ObjectFieldFrom(o specschema.ObjectAttributeType) (ObjectField, error) { Type: "types.Int64Type", FromFunc: "Int64PointerValue", }, nil + case o.List != nil: + return ObjectField{}, NewUnimplementedError(errors.New("list attribute type is not yet implemented")) + case o.Map != nil: + return ObjectField{}, NewUnimplementedError(errors.New("map attribute type is not yet implemented")) case o.Number != nil: return ObjectField{ Type: "types.NumberType", FromFunc: "NumberValue", }, nil + case o.Object != nil: + return ObjectField{}, NewUnimplementedError(errors.New("object attribute type is not yet implemented")) + case o.Set != nil: + return ObjectField{}, NewUnimplementedError(errors.New("set attribute type is not yet implemented")) case o.String != nil: return ObjectField{ Type: "types.StringType", diff --git a/internal/schema/schemas.go b/internal/schema/schemas.go index 32260c86..54aaa8a0 100644 --- a/internal/schema/schemas.go +++ b/internal/schema/schemas.go @@ -5,8 +5,12 @@ package schema import ( "bytes" + "context" "fmt" + "log/slog" "strings" + + "github.com/hashicorp/terraform-plugin-codegen-framework/internal/logging" ) // TODO: Field(s) could be added to handle end-user supplying their own templates to allow overriding. @@ -82,11 +86,13 @@ func (g GeneratorSchemas) CustomTypeValue() (map[string][]byte, error) { return customTypeValueBytes, nil } -func (g GeneratorSchemas) ToFromFunctions() (map[string][]byte, error) { +func (g GeneratorSchemas) ToFromFunctions(ctx context.Context, logger *slog.Logger) (map[string][]byte, error) { modelsExpandFlattenBytes := make(map[string][]byte, len(g.schemas)) for name, s := range g.schemas { - b, err := s.ToFromFunctions() + ctxWithPath := logging.SetPathInContext(ctx, name) + + b, err := s.ToFromFunctions(ctxWithPath, logger) if err != nil { return nil, err }