diff --git a/go.mod b/go.mod index 4efa3a1c..6c975649 100644 --- a/go.mod +++ b/go.mod @@ -5,46 +5,25 @@ go 1.23.0 toolchain go1.23.2 require ( - github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.22 - github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.2.0 + github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.3.0 github.com/getkin/kin-openapi v0.128.0 github.com/go-oas/docs v1.1.0 github.com/google/go-cmp v0.6.0 github.com/hashicorp/cli v1.1.6 - github.com/hashicorp/terraform-plugin-codegen-spec v0.2.0 github.com/hashicorp/terraform-plugin-framework v1.13.0 - github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 - github.com/hashicorp/terraform-plugin-go v0.25.0 - github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/mattn/go-colorable v0.1.13 github.com/pb33f/libopenapi v0.18.6 golang.org/x/text v0.19.0 - gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/agext/levenshtein v1.2.2 // indirect - github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/golang/protobuf v1.5.4 // indirect - github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect - github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/hashicorp/go-version v1.7.0 // indirect - github.com/hashicorp/hcl/v2 v2.22.0 // indirect - github.com/hashicorp/logutils v1.0.0 // indirect + github.com/hashicorp/terraform-plugin-go v0.25.0 // indirect + github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect - github.com/mitchellh/go-wordwrap v1.0.0 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect - github.com/zclconf/go-cty v1.15.0 // indirect - golang.org/x/mod v0.21.0 // indirect - golang.org/x/net v0.28.0 // indirect - golang.org/x/sync v0.8.0 // indirect - golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/protobuf v1.35.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) require ( diff --git a/go.sum b/go.sum index ea1ff4bd..d49a1f36 100644 --- a/go.sum +++ b/go.sum @@ -5,16 +5,8 @@ github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0 github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= 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/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.22 h1:v3t6KYkqrF/T8TDoVlbgylrsaFWNoGP3Tz1yEpH8Qsw= -github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.6.22/go.mod h1:jRp8KZ64MUevBWNqehghhG2oF5/JU3Dmt/Cu7dp1mQE= -github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.2.0 h1:QRCYtIt/3XL/yddqDV/X6HhFRRXpwKwLu+YyrPhVUd8= -github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.2.0/go.mod h1:IrO3JWDITvly1RNAsC7BXVySOmkTTJDrcm2fxkjRCGc= -github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= -github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= -github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= -github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= -github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= -github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= +github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.3.0 h1:drf9TFDNczX7rOQVSps32NIc9bV7gBOsvgZraRMb96g= +github.com/NaverCloudPlatform/terraform-plugin-codegen-spec v0.3.0/go.mod h1:IrO3JWDITvly1RNAsC7BXVySOmkTTJDrcm2fxkjRCGc= 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/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= @@ -51,7 +43,6 @@ github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= @@ -61,8 +52,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= -github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= @@ -78,27 +67,15 @@ github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ 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-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= -github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= 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/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8= -github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= -github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= -github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= -github.com/hashicorp/logutils v1.0.0 h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= github.com/hashicorp/terraform-plugin-codegen-spec v0.2.0 h1:91dQG1A/DxP6vRz9GiytDTrZTXDbhHPvmpYnAyWA/Vw= github.com/hashicorp/terraform-plugin-codegen-spec v0.2.0/go.mod h1:fywrEKpordQypmAjz/HIfm2LuNVmyJ6KDe8XT9GdJxQ= github.com/hashicorp/terraform-plugin-framework v1.13.0 h1:8OTG4+oZUfKgnfTdPTJwZ532Bh2BobF4H+yBiYJ/scw= github.com/hashicorp/terraform-plugin-framework v1.13.0/go.mod h1:j64rwMGpgM3NYXTKuxrCnyubQb/4VKldEKlcG8cvmjU= -github.com/hashicorp/terraform-plugin-framework-validators v0.15.0 h1:RXMmu7JgpFjnI1a5QjMCBb11usrW2OtAG+iOTIj5c9Y= -github.com/hashicorp/terraform-plugin-framework-validators v0.15.0/go.mod h1:Bh89/hNmqsEWug4/XWKYBwtnw3tbz5BAy1L1OgvbIaY= github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks= github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= @@ -140,10 +117,6 @@ github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa1 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/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= -github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 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= @@ -192,9 +165,6 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= -github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= -github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI= -github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= 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= @@ -212,23 +182,15 @@ github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17 github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= -github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= -github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 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/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.21.0 h1:vvrHzRwRfVKSiLrG+d4FMl/Qi4ukBCE6kZlTUkDYRT0= -golang.org/x/mod v0.21.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 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= @@ -239,18 +201,12 @@ golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= 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/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 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= @@ -274,44 +230,29 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc 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.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 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/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24= +golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= 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.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= -golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -320,10 +261,7 @@ google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzi google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= -google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/internal/ncloud/convert.go b/internal/ncloud/convert.go index b6b3097d..7dc70978 100644 --- a/internal/ncloud/convert.go +++ b/internal/ncloud/convert.go @@ -6,7 +6,7 @@ import ( "unicode" "github.com/NaverCloudPlatform/terraform-plugin-codegen-framework/internal/util" - "github.com/hashicorp/terraform-plugin-codegen-spec/resource" + "github.com/NaverCloudPlatform/terraform-plugin-codegen-spec/resource" ) // generate converter that convert openapi.json schema to terraform type @@ -29,12 +29,30 @@ func Gen_ConvertOAStoTFTypes(data resource.Attributes) (string, string, error) { dto.%[1]s = types.BoolValue(data["%[2]s"].(bool)) }`, util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" m = m + fmt.Sprintf("%[1]s types.Bool `tfsdk:\"%[2]s\"`", util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + } else if val.Int32 != nil { + s = s + fmt.Sprintf(` + if data["%[2]s"] != nil { + dto.%[1]s = types.Int32Value(data["%[2]s"].(int32)) + }`, util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + m = m + fmt.Sprintf("%[1]s types.Int32 `tfsdk:\"%[2]s\"`", util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" } else if val.Int64 != nil { s = s + fmt.Sprintf(` if data["%[2]s"] != nil { dto.%[1]s = types.Int64Value(data["%[2]s"].(int64)) }`, util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" m = m + fmt.Sprintf("%[1]s types.Int64 `tfsdk:\"%[2]s\"`", util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + } else if val.Float32 != nil { + s = s + fmt.Sprintf(` + if data["%[2]s"] != nil { + dto.%[1]s = types.Float32Value(data["%[2]s"].(float32)) + }`, util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + m = m + fmt.Sprintf("%[1]s types.Float32 `tfsdk:\"%[2]s\"`", util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + } else if val.Float64 != nil { + s = s + fmt.Sprintf(` + if data["%[2]s"] != nil { + dto.%[1]s = types.Float64Value(data["%[2]s"].(float64)) + }`, util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" + m = m + fmt.Sprintf("%[1]s types.Float64 `tfsdk:\"%[2]s\"`", util.ToPascalCase(n), PascalToSnakeCase(n)) + "\n" } else if val.List != nil { if val.List.ElementType.String != nil { s = s + fmt.Sprintf(`"%[1]s": types.ListType{ElemType: types.StringType},`, n) + "\n" @@ -103,8 +121,14 @@ func GenArray(d resource.Attributes, pName string) string { t = t + fmt.Sprintf(`"%[1]s": types.StringType,`, n) + "\n" } else if val.Bool != nil { t = t + fmt.Sprintf(`"%[1]s": types.BoolType,`, n) + "\n" + } else if val.Int32 != nil { + t = t + fmt.Sprintf(`"%[1]s": types.Int32Type,`, n) + "\n" } else if val.Int64 != nil { t = t + fmt.Sprintf(`"%[1]s": types.Int64Type,`, n) + "\n" + } else if val.Float32 != nil { + t = t + fmt.Sprintf(`"%[1]s": types.Float32Type,`, n) + "\n" + } else if val.Float64 != nil { + t = t + fmt.Sprintf(`"%[1]s": types.Float64Type,`, n) + "\n" } else if val.SingleNested != nil { s = s + fmt.Sprintf(` "%[1]s": types.ObjectType{AttrTypes: map[string]attr.Type{ @@ -132,8 +156,14 @@ func GenObject(d resource.Attributes, pName string) string { s = s + fmt.Sprintf(`"%[1]s": types.StringType,`, n) + "\n" } else if val.Bool != nil { s = s + fmt.Sprintf(`"%[1]s": types.BoolType,`, n) + "\n" + } else if val.Int32 != nil { + s = s + fmt.Sprintf(`"%[1]s": types.Int32Type,`, n) + "\n" } else if val.Int64 != nil { s = s + fmt.Sprintf(`"%[1]s": types.Int64Type,`, n) + "\n" + } else if val.Float32 != nil { + s = s + fmt.Sprintf(`"%[1]s": types.Float32Type,`, n) + "\n" + } else if val.Float64 != nil { + s = s + fmt.Sprintf(`"%[1]s": types.Float64Type,`, n) + "\n" } else if val.List != nil { if val.List.ElementType.String != nil { s = s + fmt.Sprintf(`"%[1]s": types.ListType{ElemType: types.StringType},`, n) + "\n" diff --git a/internal/ncloud/template.go b/internal/ncloud/template.go index b2eea51c..8d314f36 100644 --- a/internal/ncloud/template.go +++ b/internal/ncloud/template.go @@ -9,45 +9,80 @@ import ( "github.com/NaverCloudPlatform/terraform-plugin-codegen-framework/internal/util" "github.com/hashicorp/terraform-plugin-codegen-spec/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" ) // To generate actual data, extract data from config.yml and code-spec.json, and render code for each receiver based on that data. -// New(): Extracts the data Required for code generation. Currently, it extracts data from config.yml and code-spec.json, but it is planned to unify everything into code-spec.json in the future. -// RenderInitial(): Generates small code blocks Required initially. -// RenderCreate(): Generates the Create function. -// RenderRead(): Generates the Read function. -// RenderUpdate(): Generates the Update function. -// RenderDelete(): Generates the Delete function. -// Calculates the necessary data during initialization and performs rendering for each method. +type BaseTemplate interface { + + // RenderInitial generates small code blocks needed initially. + RenderInitial() []byte + + // RenderCreate generates the Create function. + RenderCreate() []byte + + // RenderRead generates the Read function. + RenderRead() []byte + + // RenderUpdate generates the Update function. + RenderUpdate() []byte + + // RenderDelete generates the Delete function. + RenderDelete() []byte + + // RenderModel generates the model. + RenderModel() []byte + + // RenderRefresh generates the Refresh function. + RenderRefresh() []byte + + // RenderWait generates the Waiting Logic. + // Will be Rendered in refresh file. + RenderWait() []byte + + // RenderTest generates the Test logic. + RenderTest() []byte + + // RenderImportState generates the ImportState function. + RenderImportState() []byte +} + type Template struct { - spec util.NcloudSpecification - providerName string - resourceName string - packageName string - importStateLogic string - refreshObjectName string - model string - refreshLogic string - refreshWithResponse string - endpoint string - deletePathParams string - updatePathParams string - readPathParams string - createPathParams string - deleteMethod string - updateMethod string - readMethod string - createMethod string - createReqBody string - updateReqBody string - readReqBody string - deleteReqBody string - createMethodName string - readMethodName string - updateMethodName string - deleteMethodName string - idGetter string - funcMap template.FuncMap + spec util.NcloudSpecification + providerName string + resourceName string + packageName string + importStateLogic string + refreshObjectName string + model string + refreshLogic string + refreshWithResponse string + endpoint string + deletePathParams string + updatePathParams string + readPathParams string + createPathParams string + deleteMethod string + updateMethod string + readMethod string + createMethod string + createReqBody string + updateReqBody string + readReqBody string + deleteReqBody string + createMethodName string + readMethodName string + updateMethodName string + deleteMethodName string + idGetter string + funcMap template.FuncMap + isUpdateExists bool + configParams string + readReqBodyForCheckExist string + readReqBodyForCheckDestroy string + createOpOptionalParams string + updateOpOptionalParams string + readOpOptionalParams string } func (t *Template) RenderInitial() []byte { @@ -107,23 +142,25 @@ func (t *Template) RenderCreate() []byte { } data := struct { - ResourceName string - RefreshObjectName string - CreateReqBody string - CreateMethod string - CreateMethodName string - Endpoint string - CreatePathParams string - IdGetter string + ResourceName string + RefreshObjectName string + CreateReqBody string + CreateReqOptionalParam string + CreateMethod string + CreateMethodName string + Endpoint string + CreatePathParams string + IdGetter string }{ - ResourceName: t.resourceName, - RefreshObjectName: t.refreshObjectName, - CreateReqBody: t.createReqBody, - CreateMethod: t.createMethod, - CreateMethodName: t.createMethodName, - Endpoint: t.endpoint, - CreatePathParams: t.createPathParams, - IdGetter: t.idGetter, + ResourceName: t.resourceName, + RefreshObjectName: t.refreshObjectName, + CreateReqBody: t.createReqBody, + CreateReqOptionalParam: t.createOpOptionalParams, + CreateMethod: t.createMethod, + CreateMethodName: t.createMethodName, + Endpoint: t.endpoint, + CreatePathParams: t.createPathParams, + IdGetter: t.idGetter, } err = createTemplate.ExecuteTemplate(&b, "Create", data) @@ -167,23 +204,27 @@ func (t *Template) RenderUpdate() []byte { } data := struct { - ResourceName string - RefreshObjectName string - UpdateReqBody string - UpdateMethod string - UpdateMethodName string - Endpoint string - UpdatePathParams string - ReadPathParams string + IsUpdateExists bool + ResourceName string + RefreshObjectName string + UpdateReqBody string + UpdateReqOptionalParam string + UpdateMethod string + UpdateMethodName string + Endpoint string + UpdatePathParams string + ReadPathParams string }{ - ResourceName: t.resourceName, - RefreshObjectName: t.refreshObjectName, - UpdateReqBody: t.updateReqBody, - UpdateMethod: t.updateMethod, - UpdateMethodName: t.updateMethodName, - Endpoint: t.endpoint, - UpdatePathParams: t.updatePathParams, - ReadPathParams: t.readPathParams, + IsUpdateExists: t.isUpdateExists, + ResourceName: t.resourceName, + RefreshObjectName: t.refreshObjectName, + UpdateReqBody: t.updateReqBody, + UpdateReqOptionalParam: t.updateOpOptionalParams, + UpdateMethod: t.updateMethod, + UpdateMethodName: t.updateMethodName, + Endpoint: t.endpoint, + UpdatePathParams: t.updatePathParams, + ReadPathParams: t.readPathParams, } err = updateTemplate.ExecuteTemplate(&b, "Update", data) @@ -331,25 +372,31 @@ func (t *Template) RenderTest() []byte { } data := struct { - ProviderName string - ResourceName string - PackageName string - RefreshObjectName string - ReadMethod string - ReadMethodName string - ReadReqBody string - Endpoint string - ReadPathParams string + ProviderName string + ResourceName string + PackageName string + RefreshObjectName string + ReadMethod string + ReadMethodName string + ReadReqBody string + Endpoint string + ReadPathParams string + ConfigParams string + ReadReqBodyForCheckExist string + ReadReqBodyForCheckDestroy string }{ - ProviderName: t.providerName, - ResourceName: t.resourceName, - PackageName: t.packageName, - RefreshObjectName: t.refreshObjectName, - ReadMethod: t.readMethod, - ReadMethodName: t.readMethodName, - ReadReqBody: t.readReqBody, - Endpoint: t.endpoint, - ReadPathParams: t.readPathParams, + ProviderName: t.providerName, + ResourceName: t.resourceName, + PackageName: t.packageName, + RefreshObjectName: t.refreshObjectName, + ReadMethod: t.readMethod, + ReadMethodName: t.readMethodName, + ReadReqBody: t.readReqBody, + Endpoint: t.endpoint, + ReadPathParams: t.readPathParams, + ConfigParams: t.configParams, + ReadReqBodyForCheckExist: t.readReqBodyForCheckExist, + ReadReqBodyForCheckDestroy: t.readReqBodyForCheckDestroy, } err = testTemplate.ExecuteTemplate(&b, "Test", data) @@ -360,15 +407,33 @@ func (t *Template) RenderTest() []byte { return b.Bytes() } -// Allocate prerequisite values -func New(spec util.NcloudSpecification, resourceName, packageName string) *Template { +type RequestType struct { + Parameters []string `json:"parameters,omitempty"` + RequestBody *RequestBodyWithOptional `json:"request_body,omitempty"` + Response string `json:"response,omitempty"` +} + +type RequestBodyWithOptional struct { + Name string `json:"name,omitempty"` + Required []string `json:"required,omitempty"` + Optional []string `json:"optional,omitempty"` +} + +// Extracts the data needed for code generation. Currently, it extracts data from config.yml and code-spec.json, but it is planned to unify everything into code-spec.json in the future. +func NewResource(spec util.NcloudSpecification, resourceName, packageName string) BaseTemplate { + var b BaseTemplate var refreshObjectName string var id string var attributes resource.Attributes var createReqBody string var updateReqBody string var readReqBody string + var readReqBodyForCheckExist string + var readReqBodyForCheckDestroy string var deleteReqBody string + var createOpOptionalParams string + var updateOpOptionalParams string + var readOpOptionalParams string var importStateOverride string var targetResourceRequest util.RequestWithRefreshObjectName @@ -394,63 +459,430 @@ func New(spec util.NcloudSpecification, resourceName, packageName string) *Templ } } - refreshLogic, model, err := Gen_ConvertOAStoTFTypes(attributes) + refreshLogic, model, err := Gen_ConvertOAStoTFTypes_Resource(attributes) if err != nil { log.Fatalf("error occurred with Gen_ConvertOAStoTFTypes: %v", err) } - for _, val := range targetResourceRequest.Create.RequestBody.Required { - createReqBody = createReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.FirstAlphabetToUpperCase(val), util.FirstAlphabetToUpperCase(val)) + "\n" - } + if targetResourceRequest.Create.RequestBody != nil { + + for _, val := range targetResourceRequest.Create.RequestBody.Required { + + switch val.Type { + case "string": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "integer": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "number": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "number": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "boolean": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.FormatBool(plan.%[2]s.ValueBool()),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + if targetResourceRequest.Create.RequestBody.Optional != nil { + for _, val := range targetResourceRequest.Create.RequestBody.Optional { + + switch val.Type { + case "string": + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "integer": + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueInt64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "number": + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueFloat64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "boolean": + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.FormatBool(plan.%[1]s.ValueBool()) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "array": + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + // Array and Object are treated as string with serialization + default: + createOpOptionalParams = createOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + } - for _, val := range targetResourceRequest.Update[0].RequestBody.Required { - updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.FirstAlphabetToUpperCase(val), util.FirstAlphabetToUpperCase(val)) + "\n" } - for _, val := range targetResourceRequest.Read.Parameters { - readReqBody = readReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val), util.PathToPascal(val)) + "\n" + if targetResourceRequest.Read.Parameters != nil { + + for _, val := range targetResourceRequest.Read.Parameters.Required { + + switch val.Type { + case "string": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "int32": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "float32": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + } + } + + case "boolean": + readReqBody = readReqBody + fmt.Sprintf(`%[1]s: strconv.FormatBool(plan.%[2]s.ValueBool()),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + + readReqBodyForCheckExist = readReqBodyForCheckExist + fmt.Sprintf(` %[1]s: resource.Primary.Attributes["%[2]s"],`, util.PathToPascal(val.Name), util.FirstAlphabetToLowerCase(util.PathToPascal(val.Name))) + "\n" + readReqBodyForCheckDestroy = readReqBodyForCheckDestroy + fmt.Sprintf(` %[1]s: rs.Primary.Attributes["%[2]s"],`, util.PathToPascal(val.Name), util.FirstAlphabetToLowerCase(util.PathToPascal(val.Name))) + "\n" + } + + if targetResourceRequest.Read.Parameters.Optional != nil { + for _, val := range targetResourceRequest.Read.Parameters.Optional { + + switch val.Type { + case "string": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueInt64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "int32": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueInt32())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueFloat64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "float32": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueFloat32())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "boolean": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.FormatBool(plan.%[1]s.ValueBool()) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "array": + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + // Array and Object are treated as string with serialization + default: + readOpOptionalParams = readOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + } } - for _, val := range targetResourceRequest.Create.Parameters { - createReqBody = createReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val), util.PathToPascal(val)) + "\n" + if targetResourceRequest.Create.Parameters != nil { + for _, val := range targetResourceRequest.Create.Parameters.Required { + switch val.Type { + case "string": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "int32": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "float32": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "boolean": + createReqBody = createReqBody + fmt.Sprintf(`%[1]s: strconv.Formatbool(plan.%[2]s.ValueBool()),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } } - for _, val := range targetResourceRequest.Update[0].Parameters { - updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val), util.PathToPascal(val)) + "\n" + if len(targetResourceRequest.Update) > 0 { + if targetResourceRequest.Update[0].Parameters != nil { + for _, val := range targetResourceRequest.Update[0].Parameters.Required { + switch val.Type { + case "string": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "int32": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "float32": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "boolean": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.FormatBool(plan.%[2]s.ValueBool()),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + if targetResourceRequest.Update[0].RequestBody != nil { + for _, val := range targetResourceRequest.Update[0].RequestBody.Required { + switch val.Type { + case "string": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "int32": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt32())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "float32": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat32())),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "boolean": + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: strconv.FormatBool(plan.%[2]s.ValueBool()),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + updateReqBody = updateReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.FirstAlphabetToUpperCase(val.Name), util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + for _, val := range targetResourceRequest.Update[0].RequestBody.Optional { + + switch val.Type { + case "string": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueInt64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "int32": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueInt32())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueFloat64())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "float32": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.Itoa(int(plan.%[1]s.ValueFloat32())) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + case "boolean": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = strconv.FormatBool(plan.%[1]s.ValueBool()) + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + case "array": + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + + // Array and Object are treated as string with serialization + default: + updateOpOptionalParams = updateOpOptionalParams + fmt.Sprintf(` + if !plan.%[1]s.IsNull() && !plan.%[1]s.IsUnknown() { + reqParams.%[1]s = plan.%[1]s.ValueString() + }`, util.FirstAlphabetToUpperCase(val.Name)) + "\n" + } + } + + t.isUpdateExists = true + t.updatePathParams = extractPathParams(targetResourceRequest.Update[0].Path) + t.updateMethod = targetResourceRequest.Update[0].Method + t.updateReqBody = updateReqBody + t.updateOpOptionalParams = updateOpOptionalParams + t.updateMethodName = strings.ToUpper(targetResourceRequest.Update[0].Method) + getMethodName(targetResourceRequest.Update[0].Path) } - for _, val := range targetResourceRequest.Delete.Parameters { - deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val), util.PathToPascal(val)) + "\n" + if targetResourceRequest.Delete.Parameters != nil { + for _, val := range targetResourceRequest.Delete.Parameters.Required { + switch val.Type { + case "string": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: plan.%[2]s.ValueString(),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "integer": + if val.Format != nil { + switch val.Format { + case "int64": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "int32": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueInt32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "number": + if val.Format != nil { + switch val.Format { + case "float64": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "float32": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat32())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } + + case "number": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.Itoa(int(plan.%[2]s.ValueFloat64())),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + + case "boolean": + deleteReqBody = deleteReqBody + fmt.Sprintf(`%[1]s: strconv.FormatBool(plan.%[2]s.ValueBool()),`, util.PathToPascal(val.Name), util.PathToPascal(val.Name)) + "\n" + } + } } t.funcMap = funcMap t.providerName = spec.Provider.Name t.packageName = packageName t.refreshObjectName = refreshObjectName - t.importStateLogic = MakeImportStateLogic(importStateOverride) + t.importStateLogic = makeImportStateLogic(importStateOverride) t.model = model t.refreshLogic = refreshLogic t.refreshWithResponse = MakeRefreshFromResponse(attributes, resourceName) t.endpoint = spec.Provider.Endpoint t.deletePathParams = extractPathParams(targetResourceRequest.Delete.Path) - t.updatePathParams = extractPathParams(targetResourceRequest.Update[0].Path) t.readPathParams = extractReadPathParams(targetResourceRequest.Read.Path) t.createPathParams = extractPathParams(targetResourceRequest.Create.Path) + t.configParams = MakeTestTFConfig(targetResourceRequest.Create.RequestBody.Required, targetResourceRequest.Create.Parameters) t.deleteMethod = targetResourceRequest.Delete.Method - t.updateMethod = targetResourceRequest.Update[0].Method t.readMethod = targetResourceRequest.Read.Method t.createMethod = targetResourceRequest.Create.Method t.createReqBody = createReqBody - t.updateReqBody = updateReqBody t.readReqBody = readReqBody t.deleteReqBody = deleteReqBody + t.readReqBodyForCheckExist = readReqBodyForCheckExist + t.readReqBodyForCheckDestroy = readReqBodyForCheckDestroy + t.createOpOptionalParams = createOpOptionalParams + t.readOpOptionalParams = readOpOptionalParams t.createMethodName = strings.ToUpper(targetResourceRequest.Create.Method) + getMethodName(targetResourceRequest.Create.Path) t.readMethodName = strings.ToUpper(targetResourceRequest.Read.Method) + getMethodName(targetResourceRequest.Read.Path) - t.updateMethodName = strings.ToUpper(targetResourceRequest.Update[0].Method) + getMethodName(targetResourceRequest.Update[0].Path) t.deleteMethodName = strings.ToUpper(targetResourceRequest.Delete.Method) + getMethodName(targetResourceRequest.Delete.Path) t.idGetter = makeIdGetter(id) - return t + b = t + + return b } func getMethodName(s string) string { @@ -539,7 +971,7 @@ func makeIdGetter(target string) string { for idx, val := range parts { if idx == len(parts)-1 { - s = s + fmt.Sprintf(`["%s"].(string)`, util.ToCamelCase(val)) + s = s + fmt.Sprintf(`["%s"].(string)`, util.ToPascalCase(util.ToCamelCase(val))) continue } @@ -549,7 +981,7 @@ func makeIdGetter(target string) string { return s } -func MakeImportStateLogic(target string) string { +func makeImportStateLogic(target string) string { parts := strings.Split(target, ".") if len(parts) < 2 { @@ -583,6 +1015,16 @@ func MakeRefreshFromResponse(attr resource.Attributes, resourceName string) stri } postPlan.%[3]s = types.BoolValue(tempVal) }`, val.Name, util.ToPascalCase(resourceName), util.ToPascalCase(val.Name)) + "\n") + } else if val.Int32 != nil { + s.WriteString(fmt.Sprintf(` + if !response.%[2]s.Attributes()["%[1]s"].IsNull() || !response.%[2]s.Attributes()["%[1]s"].IsUnknown() { + tempVal, err := strconv.Atoi(response.%[2]s.Attributes()["%[1]s"].String()) + if err != nil { + diagnostics.AddError("CONVERSION ERROR", fmt.Sprintf("Failed to convert %[1]s to int: \%v", err)) + return + } + postPlan.%[3]s = types.Int32Value(int32(tempVal)) + }`, val.Name, util.ToPascalCase(resourceName), util.ToPascalCase(val.Name)) + "\n") } else if val.Int64 != nil { s.WriteString(fmt.Sprintf(` if !response.%[2]s.Attributes()["%[1]s"].IsNull() || !response.%[2]s.Attributes()["%[1]s"].IsUnknown() { @@ -593,6 +1035,26 @@ func MakeRefreshFromResponse(attr resource.Attributes, resourceName string) stri } postPlan.%[3]s = types.Int64Value(int64(tempVal)) }`, val.Name, util.ToPascalCase(resourceName), util.ToPascalCase(val.Name)) + "\n") + } else if val.Float32 != nil { + s.WriteString(fmt.Sprintf(` + if !response.%[2]s.Attributes()["%[1]s"].IsNull() || !response.%[2]s.Attributes()["%[1]s"].IsUnknown() { + tempVal, err := strconv.ParseFloat(response.%[2]s.Attributes()["%[1]s"].String(), 32) + if err != nil { + diagnostics.AddError("CONVERSION ERROR", fmt.Sprintf("Failed to convert %[1]s to float64: %v", err)) + return + } + postPlan.%[3]s = types.Float32Value(tempVal) + }`, val.Name, util.ToPascalCase(resourceName), util.ToPascalCase(val.Name)) + "\n") + } else if val.Float64 != nil { + s.WriteString(fmt.Sprintf(` + if !response.%[2]s.Attributes()["%[1]s"].IsNull() || !response.%[2]s.Attributes()["%[1]s"].IsUnknown() { + tempVal, err := strconv.ParseFloat(response.%[2]s.Attributes()["%[1]s"].String(), 64) + if err != nil { + diagnostics.AddError("CONVERSION ERROR", fmt.Sprintf("Failed to convert %[1]s to float64: %v", err)) + return + } + postPlan.%[3]s = types.Float64Value(tempVal) + }`, val.Name, util.ToPascalCase(resourceName), util.ToPascalCase(val.Name)) + "\n") } else if val.List != nil { s.WriteString(fmt.Sprintf(` if !response.%[2]s.Attributes()["%[1]s"].IsNull() || !response.%[2]s.Attributes()["%[1]s"].IsUnknown() { @@ -628,3 +1090,19 @@ func MakeRefreshFromResponse(attr resource.Attributes, resourceName string) stri return s.String() } + +func MakeTestTFConfig(requiredCreateParams []*util.ParamsWithTypeInfo, createPathParams *util.ParameterWithOptional) string { + var t strings.Builder + + for _, val := range requiredCreateParams { + t.WriteString(fmt.Sprintf(` %[1]s = "%[2]s"`, PascalToSnakeCase(val.Name), "tf-"+acctest.RandString(5)) + "\n") + } + + if createPathParams != nil { + for _, val := range createPathParams.Required { + t.WriteString(fmt.Sprintf(` %[1]s = "%[2]s"`, util.FirstAlphabetToLowerCase(util.PathToPascal(val.Name)), "tf-"+acctest.RandString(5)) + "\n") + } + } + + return t.String() +} diff --git a/internal/util/helper.go b/internal/util/helper.go index 985e7ee0..7b649ebb 100644 --- a/internal/util/helper.go +++ b/internal/util/helper.go @@ -10,9 +10,9 @@ import ( ) func RemovingWhiteSpace(input string) string { - input = strings.ReplaceAll(input, "\t", "") // 탭 제거 - input = strings.ReplaceAll(input, "\n", "") // 개행 제거 - input = strings.ReplaceAll(input, " ", "") // 공백 제거 + input = strings.ReplaceAll(input, "\t", "") // remove tab + input = strings.ReplaceAll(input, "\n", "") // remove newline + input = strings.ReplaceAll(input, " ", "") // remove space return input }