From 8e34805480bd7ee86d9390bbf09f424a9479b45e Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 9 Feb 2024 16:59:15 -0500 Subject: [PATCH] grpc: add base protos for HCLSpec This commit introduces a grpc subpackage to the SDK that implements a serialisable type for hcldec.Spec types. This is made so we'll be able to use another format to serialise what we need, as gob isn't supported anymore for cty.Type. The HCL2Spec function, implemented by all the plugins, are the ones responsible for transmitting the schema of their configurations to Packer, which as of v0.5.1 of the SDK, is using gob for serialisation, which has been removed from the cty library. This commit serves as a base to introduce an alternative as gRPC communication, and protobuf-serialised structures to communicate between Packer and the plugins. --- Makefile | 2 +- go.mod | 4 +- go.sum | 22 + grpc/proto_tester/main.go | 192 ++++++ grpc/structs/hclspec/convert.go | 263 ++++++++ grpc/structs/hclspec/hcl_spec.pb.go | 951 ++++++++++++++++++++++++++++ grpc/structs/hclspec/hcl_spec.proto | 94 +++ 7 files changed, 1526 insertions(+), 2 deletions(-) create mode 100644 grpc/proto_tester/main.go create mode 100644 grpc/structs/hclspec/convert.go create mode 100644 grpc/structs/hclspec/hcl_spec.pb.go create mode 100644 grpc/structs/hclspec/hcl_spec.proto diff --git a/Makefile b/Makefile index 2e86ca800..df2b6dadd 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ generate: install-gen-deps ## Generate dynamically generated code @find ./ -type f | xargs grep -l '^// Code generated' | xargs rm -f PROJECT_ROOT="$(CURDIR)" go generate ./... go fmt bootcommand/boot_command.go -# go run ./cmd/generate-fixer-deprecations + protoc grpc/structs/hclspec/hcl_spec.proto --go_out=. generate-check: generate ## Check go code generation is on par @echo "==> Checking that auto-generated code is not changed..." diff --git a/go.mod b/go.mod index 70f3f37be..3097bca60 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/agext/levenshtein v1.2.3 github.com/antchfx/xpath v1.1.11 // indirect github.com/armon/go-metrics v0.4.1 // indirect - github.com/aws/aws-sdk-go v1.44.114 + github.com/aws/aws-sdk-go v1.45.6 github.com/cenkalti/backoff/v3 v3.2.2 // indirect github.com/dylanmei/iso8601 v0.1.0 // indirect github.com/dylanmei/winrmtest v0.0.0-20210303004826-fbc9ae56efb6 @@ -91,12 +91,14 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect github.com/googleapis/gax-go/v2 v2.6.0 // indirect + github.com/hashicorp/aws-sdk-go-base v0.7.1 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-safetemp v1.0.0 // indirect github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect github.com/hashicorp/hcl v1.0.0 // indirect + github.com/hashicorp/packer-plugin-amazon v1.3.0 // indirect github.com/hashicorp/serf v0.10.1 // indirect github.com/huandu/xstrings v1.3.2 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect diff --git a/go.sum b/go.sum index 366761cea..025b83c22 100644 --- a/go.sum +++ b/go.sum @@ -48,8 +48,11 @@ github.com/armon/go-metrics v0.4.1/go.mod h1:E6amYzXo6aW1tqzoZGT755KkbgrJsSdpwZ+ 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/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0= github.com/aws/aws-sdk-go v1.44.114 h1:plIkWc/RsHr3DXBj4MEw9sEW4CcL/e2ryokc+CKyq1I= github.com/aws/aws-sdk-go v1.44.114/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= +github.com/aws/aws-sdk-go v1.45.6 h1:Y2isQQBZsnO15dzUQo9YQRThtHgrV200XCH05BRHVJI= +github.com/aws/aws-sdk-go v1.45.6/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= @@ -92,6 +95,7 @@ github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2 github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= @@ -141,6 +145,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.2.0 h1:y8Yozv7SZtlU//QXbez github.com/googleapis/enterprise-certificate-proxy v0.2.0/go.mod h1:8C0jb7/mgJe/9KK8Lm7X9ctZC2t60YyIpYEI16jx0Qg= github.com/googleapis/gax-go/v2 v2.6.0 h1:SXk3ABtQYDT/OH8jAyvEOQ58mgawq5C4o/4/89qN2ZU= github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMdcIDwU/6+DDoY= +github.com/hashicorp/aws-sdk-go-base v0.7.1 h1:7s/aR3hFn74tYPVihzDyZe7y/+BorN70rr9ZvpV3j3o= +github.com/hashicorp/aws-sdk-go-base v0.7.1/go.mod h1:2fRjWDv3jJBeN6mVWFHV6hFTNeFBx2gpDLQaZNxUVAY= github.com/hashicorp/consul/api v1.25.1 h1:CqrdhYzc8XZuPnhIYZWH45toM0LB9ZeYr/gvpLVI3PE= github.com/hashicorp/consul/api v1.25.1/go.mod h1:iiLVwR/htV7mas/sy0O+XSuEnrdBUUydemjxcUrAt4g= github.com/hashicorp/consul/sdk v0.14.1 h1:ZiwE2bKb+zro68sWzZ1SgHF3kRMBZ94TwOCFRF4ylPs= @@ -201,6 +207,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR/prTM= github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= +github.com/hashicorp/packer-plugin-amazon v1.3.0 h1:saMHhl2J8IGAROX7g2VGoiImcackAQRcDm/TVujiIzM= +github.com/hashicorp/packer-plugin-amazon v1.3.0/go.mod h1:QPNzP6bHzvIRBdpbcMrt46zGe7Ryg+f4Y9/MpOm1Lqo= github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= github.com/hashicorp/vault/api v1.10.0 h1:/US7sIjWN6Imp4o/Rj1Ce2Nr5bki/AXi9vAW3p2tOJQ= @@ -215,6 +223,7 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= +github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -350,6 +359,7 @@ github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxW github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zclconf/go-cty v1.13.3 h1:m+b9q3YDbg6Bec5rr+KGy1MzEVzY/jC2X+YX4yqKtHI= github.com/zclconf/go-cty v1.13.3/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI= @@ -366,6 +376,7 @@ golang.org/x/crypto v0.0.0-20200414173820-0848c9571904/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -382,6 +393,7 @@ golang.org/x/mobile v0.0.0-20210901025245-1fde1d6c3ca1 h1:t3ZHqovedSY8DEAUmZA99f golang.org/x/mobile v0.0.0-20210901025245-1fde1d6c3ca1/go.mod h1:jFTmtFYCV0MFtXBU+J5V/+5AUeVS0ON/0WkE/KSrl6E= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.4.2/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.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -394,12 +406,15 @@ golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco= golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -411,6 +426,7 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -439,12 +455,16 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/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-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.15.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.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -452,6 +472,7 @@ 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.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= @@ -465,6 +486,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.14.0 h1:jvNa2pY0M4r62jkRQ6RwEZZyPcymeL9XZMLBbV7U2nc= golang.org/x/tools v0.14.0/go.mod h1:uYBEerGOWcJyEORxN+Ek8+TT266gXkNlHdJBwexUsBg= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/grpc/proto_tester/main.go b/grpc/proto_tester/main.go new file mode 100644 index 000000000..7b92a658b --- /dev/null +++ b/grpc/proto_tester/main.go @@ -0,0 +1,192 @@ +package main + +import ( + "fmt" + "os" + "path/filepath" + + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/hashicorp/packer-plugin-amazon/builder/common" + "github.com/hashicorp/packer-plugin-amazon/builder/ebs" + "github.com/hashicorp/packer-plugin-sdk/grpc/structs/hclspec" + "github.com/hashicorp/packer-plugin-sdk/template/config" + "github.com/zclconf/go-cty/cty" +) + +func Usage() string { + baseName := filepath.Base(os.Args[0]) + return fmt.Sprintf(`%[1]s: simple serialiser/deserialiser for objectSpecs`, baseName) +} + +var spec = hcldec.ObjectSpec{ + "packer_build_name": &hcldec.AttrSpec{Name: "packer_build_name", Type: cty.String, Required: false}, + "packer_builder_type": &hcldec.AttrSpec{Name: "packer_builder_type", Type: cty.String, Required: false}, + "packer_core_version": &hcldec.AttrSpec{Name: "packer_core_version", Type: cty.String, Required: false}, + "packer_debug": &hcldec.AttrSpec{Name: "packer_debug", Type: cty.Bool, Required: false}, + "packer_force": &hcldec.AttrSpec{Name: "packer_force", Type: cty.Bool, Required: false}, + "packer_on_error": &hcldec.AttrSpec{Name: "packer_on_error", Type: cty.String, Required: false}, + "packer_user_variables": &hcldec.AttrSpec{Name: "packer_user_variables", Type: cty.Map(cty.String), Required: false}, + "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, + "access_key": &hcldec.AttrSpec{Name: "access_key", Type: cty.String, Required: false}, + "assume_role": &hcldec.BlockSpec{TypeName: "assume_role", Nested: hcldec.ObjectSpec((*common.FlatAssumeRoleConfig)(nil).HCL2Spec())}, + "custom_endpoint_ec2": &hcldec.AttrSpec{Name: "custom_endpoint_ec2", Type: cty.String, Required: false}, + "shared_credentials_file": &hcldec.AttrSpec{Name: "shared_credentials_file", Type: cty.String, Required: false}, + "decode_authorization_messages": &hcldec.AttrSpec{Name: "decode_authorization_messages", Type: cty.Bool, Required: false}, + "insecure_skip_tls_verify": &hcldec.AttrSpec{Name: "insecure_skip_tls_verify", Type: cty.Bool, Required: false}, + "max_retries": &hcldec.AttrSpec{Name: "max_retries", Type: cty.Number, Required: false}, + "mfa_code": &hcldec.AttrSpec{Name: "mfa_code", Type: cty.String, Required: false}, + "profile": &hcldec.AttrSpec{Name: "profile", Type: cty.String, Required: false}, + "region": &hcldec.AttrSpec{Name: "region", Type: cty.String, Required: false}, + "secret_key": &hcldec.AttrSpec{Name: "secret_key", Type: cty.String, Required: false}, + "skip_metadata_api_check": &hcldec.AttrSpec{Name: "skip_metadata_api_check", Type: cty.Bool, Required: false}, + "skip_credential_validation": &hcldec.AttrSpec{Name: "skip_credential_validation", Type: cty.Bool, Required: false}, + "token": &hcldec.AttrSpec{Name: "token", Type: cty.String, Required: false}, + "vault_aws_engine": &hcldec.BlockSpec{TypeName: "vault_aws_engine", Nested: hcldec.ObjectSpec((*common.FlatVaultAWSEngineOptions)(nil).HCL2Spec())}, + "aws_polling": &hcldec.BlockSpec{TypeName: "aws_polling", Nested: hcldec.ObjectSpec((*common.FlatAWSPollingConfig)(nil).HCL2Spec())}, + "ami_name": &hcldec.AttrSpec{Name: "ami_name", Type: cty.String, Required: false}, + "ami_description": &hcldec.AttrSpec{Name: "ami_description", Type: cty.String, Required: false}, + "ami_virtualization_type": &hcldec.AttrSpec{Name: "ami_virtualization_type", Type: cty.String, Required: false}, + "ami_users": &hcldec.AttrSpec{Name: "ami_users", Type: cty.List(cty.String), Required: false}, + "ami_groups": &hcldec.AttrSpec{Name: "ami_groups", Type: cty.List(cty.String), Required: false}, + "ami_org_arns": &hcldec.AttrSpec{Name: "ami_org_arns", Type: cty.List(cty.String), Required: false}, + "ami_ou_arns": &hcldec.AttrSpec{Name: "ami_ou_arns", Type: cty.List(cty.String), Required: false}, + "ami_product_codes": &hcldec.AttrSpec{Name: "ami_product_codes", Type: cty.List(cty.String), Required: false}, + "ami_regions": &hcldec.AttrSpec{Name: "ami_regions", Type: cty.List(cty.String), Required: false}, + "skip_region_validation": &hcldec.AttrSpec{Name: "skip_region_validation", Type: cty.Bool, Required: false}, + "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.Map(cty.String), Required: false}, + "tag": &hcldec.BlockListSpec{TypeName: "tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, + "ena_support": &hcldec.AttrSpec{Name: "ena_support", Type: cty.Bool, Required: false}, + "sriov_support": &hcldec.AttrSpec{Name: "sriov_support", Type: cty.Bool, Required: false}, + "force_deregister": &hcldec.AttrSpec{Name: "force_deregister", Type: cty.Bool, Required: false}, + "force_delete_snapshot": &hcldec.AttrSpec{Name: "force_delete_snapshot", Type: cty.Bool, Required: false}, + "encrypt_boot": &hcldec.AttrSpec{Name: "encrypt_boot", Type: cty.Bool, Required: false}, + "kms_key_id": &hcldec.AttrSpec{Name: "kms_key_id", Type: cty.String, Required: false}, + "region_kms_key_ids": &hcldec.AttrSpec{Name: "region_kms_key_ids", Type: cty.Map(cty.String), Required: false}, + "skip_save_build_region": &hcldec.AttrSpec{Name: "skip_save_build_region", Type: cty.Bool, Required: false}, + "imds_support": &hcldec.AttrSpec{Name: "imds_support", Type: cty.String, Required: false}, + "snapshot_tags": &hcldec.AttrSpec{Name: "snapshot_tags", Type: cty.Map(cty.String), Required: false}, + "snapshot_tag": &hcldec.BlockListSpec{TypeName: "snapshot_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, + "snapshot_users": &hcldec.AttrSpec{Name: "snapshot_users", Type: cty.List(cty.String), Required: false}, + "snapshot_groups": &hcldec.AttrSpec{Name: "snapshot_groups", Type: cty.List(cty.String), Required: false}, + "associate_public_ip_address": &hcldec.AttrSpec{Name: "associate_public_ip_address", Type: cty.Bool, Required: false}, + "availability_zone": &hcldec.AttrSpec{Name: "availability_zone", Type: cty.String, Required: false}, + "block_duration_minutes": &hcldec.AttrSpec{Name: "block_duration_minutes", Type: cty.Number, Required: false}, + "capacity_reservation_preference": &hcldec.AttrSpec{Name: "capacity_reservation_preference", Type: cty.String, Required: false}, + "capacity_reservation_id": &hcldec.AttrSpec{Name: "capacity_reservation_id", Type: cty.String, Required: false}, + "capacity_reservation_group_arn": &hcldec.AttrSpec{Name: "capacity_reservation_group_arn", Type: cty.String, Required: false}, + "disable_stop_instance": &hcldec.AttrSpec{Name: "disable_stop_instance", Type: cty.Bool, Required: false}, + "ebs_optimized": &hcldec.AttrSpec{Name: "ebs_optimized", Type: cty.Bool, Required: false}, + "enable_nitro_enclave": &hcldec.AttrSpec{Name: "enable_nitro_enclave", Type: cty.Bool, Required: false}, + "enable_t2_unlimited": &hcldec.AttrSpec{Name: "enable_t2_unlimited", Type: cty.Bool, Required: false}, + "enable_unlimited_credits": &hcldec.AttrSpec{Name: "enable_unlimited_credits", Type: cty.Bool, Required: false}, + "iam_instance_profile": &hcldec.AttrSpec{Name: "iam_instance_profile", Type: cty.String, Required: false}, + "fleet_tags": &hcldec.AttrSpec{Name: "fleet_tags", Type: cty.Map(cty.String), Required: false}, + "fleet_tag": &hcldec.BlockListSpec{TypeName: "fleet_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, + "skip_profile_validation": &hcldec.AttrSpec{Name: "skip_profile_validation", Type: cty.Bool, Required: false}, + "temporary_iam_instance_profile_policy_document": &hcldec.BlockSpec{TypeName: "temporary_iam_instance_profile_policy_document", Nested: hcldec.ObjectSpec((*common.FlatPolicyDocument)(nil).HCL2Spec())}, + "shutdown_behavior": &hcldec.AttrSpec{Name: "shutdown_behavior", Type: cty.String, Required: false}, + "instance_type": &hcldec.AttrSpec{Name: "instance_type", Type: cty.String, Required: false}, + "security_group_filter": &hcldec.BlockSpec{TypeName: "security_group_filter", Nested: hcldec.ObjectSpec((*common.FlatSecurityGroupFilterOptions)(nil).HCL2Spec())}, + "run_tags": &hcldec.AttrSpec{Name: "run_tags", Type: cty.Map(cty.String), Required: false}, + "run_tag": &hcldec.BlockListSpec{TypeName: "run_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, + "security_group_id": &hcldec.AttrSpec{Name: "security_group_id", Type: cty.String, Required: false}, + "security_group_ids": &hcldec.AttrSpec{Name: "security_group_ids", Type: cty.List(cty.String), Required: false}, + "source_ami": &hcldec.AttrSpec{Name: "source_ami", Type: cty.String, Required: false}, + "source_ami_filter": &hcldec.BlockSpec{TypeName: "source_ami_filter", Nested: hcldec.ObjectSpec((*common.FlatAmiFilterOptions)(nil).HCL2Spec())}, + "spot_instance_types": &hcldec.AttrSpec{Name: "spot_instance_types", Type: cty.List(cty.String), Required: false}, + "spot_price": &hcldec.AttrSpec{Name: "spot_price", Type: cty.String, Required: false}, + "spot_price_auto_product": &hcldec.AttrSpec{Name: "spot_price_auto_product", Type: cty.String, Required: false}, + "spot_tags": &hcldec.AttrSpec{Name: "spot_tags", Type: cty.Map(cty.String), Required: false}, + "spot_tag": &hcldec.BlockListSpec{TypeName: "spot_tag", Nested: hcldec.ObjectSpec((*config.FlatKeyValue)(nil).HCL2Spec())}, + "subnet_filter": &hcldec.BlockSpec{TypeName: "subnet_filter", Nested: hcldec.ObjectSpec((*common.FlatSubnetFilterOptions)(nil).HCL2Spec())}, + "subnet_id": &hcldec.AttrSpec{Name: "subnet_id", Type: cty.String, Required: false}, + "license_specifications": &hcldec.BlockListSpec{TypeName: "license_specifications", Nested: hcldec.ObjectSpec((*common.FlatLicenseSpecification)(nil).HCL2Spec())}, + "placement": &hcldec.BlockSpec{TypeName: "placement", Nested: hcldec.ObjectSpec((*common.FlatPlacement)(nil).HCL2Spec())}, + "tenancy": &hcldec.AttrSpec{Name: "tenancy", Type: cty.String, Required: false}, + "temporary_security_group_source_cidrs": &hcldec.AttrSpec{Name: "temporary_security_group_source_cidrs", Type: cty.List(cty.String), Required: false}, + "temporary_security_group_source_public_ip": &hcldec.AttrSpec{Name: "temporary_security_group_source_public_ip", Type: cty.Bool, Required: false}, + "user_data": &hcldec.AttrSpec{Name: "user_data", Type: cty.String, Required: false}, + "user_data_file": &hcldec.AttrSpec{Name: "user_data_file", Type: cty.String, Required: false}, + "vpc_filter": &hcldec.BlockSpec{TypeName: "vpc_filter", Nested: hcldec.ObjectSpec((*common.FlatVpcFilterOptions)(nil).HCL2Spec())}, + "vpc_id": &hcldec.AttrSpec{Name: "vpc_id", Type: cty.String, Required: false}, + "windows_password_timeout": &hcldec.AttrSpec{Name: "windows_password_timeout", Type: cty.String, Required: false}, + "metadata_options": &hcldec.BlockSpec{TypeName: "metadata_options", Nested: hcldec.ObjectSpec((*common.FlatMetadataOptions)(nil).HCL2Spec())}, + "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, + "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, + "ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false}, + "ssh_port": &hcldec.AttrSpec{Name: "ssh_port", Type: cty.Number, Required: false}, + "ssh_username": &hcldec.AttrSpec{Name: "ssh_username", Type: cty.String, Required: false}, + "ssh_password": &hcldec.AttrSpec{Name: "ssh_password", Type: cty.String, Required: false}, + "ssh_keypair_name": &hcldec.AttrSpec{Name: "ssh_keypair_name", Type: cty.String, Required: false}, + "temporary_key_pair_name": &hcldec.AttrSpec{Name: "temporary_key_pair_name", Type: cty.String, Required: false}, + "temporary_key_pair_type": &hcldec.AttrSpec{Name: "temporary_key_pair_type", Type: cty.String, Required: false}, + "temporary_key_pair_bits": &hcldec.AttrSpec{Name: "temporary_key_pair_bits", Type: cty.Number, Required: false}, + "ssh_ciphers": &hcldec.AttrSpec{Name: "ssh_ciphers", Type: cty.List(cty.String), Required: false}, + "ssh_clear_authorized_keys": &hcldec.AttrSpec{Name: "ssh_clear_authorized_keys", Type: cty.Bool, Required: false}, + "ssh_key_exchange_algorithms": &hcldec.AttrSpec{Name: "ssh_key_exchange_algorithms", Type: cty.List(cty.String), Required: false}, + "ssh_private_key_file": &hcldec.AttrSpec{Name: "ssh_private_key_file", Type: cty.String, Required: false}, + "ssh_certificate_file": &hcldec.AttrSpec{Name: "ssh_certificate_file", Type: cty.String, Required: false}, + "ssh_pty": &hcldec.AttrSpec{Name: "ssh_pty", Type: cty.Bool, Required: false}, + "ssh_timeout": &hcldec.AttrSpec{Name: "ssh_timeout", Type: cty.String, Required: false}, + "ssh_wait_timeout": &hcldec.AttrSpec{Name: "ssh_wait_timeout", Type: cty.String, Required: false}, + "ssh_agent_auth": &hcldec.AttrSpec{Name: "ssh_agent_auth", Type: cty.Bool, Required: false}, + "ssh_disable_agent_forwarding": &hcldec.AttrSpec{Name: "ssh_disable_agent_forwarding", Type: cty.Bool, Required: false}, + "ssh_handshake_attempts": &hcldec.AttrSpec{Name: "ssh_handshake_attempts", Type: cty.Number, Required: false}, + "ssh_bastion_host": &hcldec.AttrSpec{Name: "ssh_bastion_host", Type: cty.String, Required: false}, + "ssh_bastion_port": &hcldec.AttrSpec{Name: "ssh_bastion_port", Type: cty.Number, Required: false}, + "ssh_bastion_agent_auth": &hcldec.AttrSpec{Name: "ssh_bastion_agent_auth", Type: cty.Bool, Required: false}, + "ssh_bastion_username": &hcldec.AttrSpec{Name: "ssh_bastion_username", Type: cty.String, Required: false}, + "ssh_bastion_password": &hcldec.AttrSpec{Name: "ssh_bastion_password", Type: cty.String, Required: false}, + "ssh_bastion_interactive": &hcldec.AttrSpec{Name: "ssh_bastion_interactive", Type: cty.Bool, Required: false}, + "ssh_bastion_private_key_file": &hcldec.AttrSpec{Name: "ssh_bastion_private_key_file", Type: cty.String, Required: false}, + "ssh_bastion_certificate_file": &hcldec.AttrSpec{Name: "ssh_bastion_certificate_file", Type: cty.String, Required: false}, + "ssh_file_transfer_method": &hcldec.AttrSpec{Name: "ssh_file_transfer_method", Type: cty.String, Required: false}, + "ssh_proxy_host": &hcldec.AttrSpec{Name: "ssh_proxy_host", Type: cty.String, Required: false}, + "ssh_proxy_port": &hcldec.AttrSpec{Name: "ssh_proxy_port", Type: cty.Number, Required: false}, + "ssh_proxy_username": &hcldec.AttrSpec{Name: "ssh_proxy_username", Type: cty.String, Required: false}, + "ssh_proxy_password": &hcldec.AttrSpec{Name: "ssh_proxy_password", Type: cty.String, Required: false}, + "ssh_keep_alive_interval": &hcldec.AttrSpec{Name: "ssh_keep_alive_interval", Type: cty.String, Required: false}, + "ssh_read_write_timeout": &hcldec.AttrSpec{Name: "ssh_read_write_timeout", Type: cty.String, Required: false}, + "ssh_remote_tunnels": &hcldec.AttrSpec{Name: "ssh_remote_tunnels", Type: cty.List(cty.String), Required: false}, + "ssh_local_tunnels": &hcldec.AttrSpec{Name: "ssh_local_tunnels", Type: cty.List(cty.String), Required: false}, + "ssh_public_key": &hcldec.AttrSpec{Name: "ssh_public_key", Type: cty.List(cty.Number), Required: false}, + "ssh_private_key": &hcldec.AttrSpec{Name: "ssh_private_key", Type: cty.List(cty.Number), Required: false}, + "winrm_username": &hcldec.AttrSpec{Name: "winrm_username", Type: cty.String, Required: false}, + "winrm_password": &hcldec.AttrSpec{Name: "winrm_password", Type: cty.String, Required: false}, + "winrm_host": &hcldec.AttrSpec{Name: "winrm_host", Type: cty.String, Required: false}, + "winrm_no_proxy": &hcldec.AttrSpec{Name: "winrm_no_proxy", Type: cty.Bool, Required: false}, + "winrm_port": &hcldec.AttrSpec{Name: "winrm_port", Type: cty.Number, Required: false}, + "winrm_timeout": &hcldec.AttrSpec{Name: "winrm_timeout", Type: cty.String, Required: false}, + "winrm_use_ssl": &hcldec.AttrSpec{Name: "winrm_use_ssl", Type: cty.Bool, Required: false}, + "winrm_insecure": &hcldec.AttrSpec{Name: "winrm_insecure", Type: cty.Bool, Required: false}, + "winrm_use_ntlm": &hcldec.AttrSpec{Name: "winrm_use_ntlm", Type: cty.Bool, Required: false}, + "ssh_interface": &hcldec.AttrSpec{Name: "ssh_interface", Type: cty.String, Required: false}, + "pause_before_ssm": &hcldec.AttrSpec{Name: "pause_before_ssm", Type: cty.String, Required: false}, + "session_manager_port": &hcldec.AttrSpec{Name: "session_manager_port", Type: cty.Number, Required: false}, + "skip_create_ami": &hcldec.AttrSpec{Name: "skip_create_ami", Type: cty.Bool, Required: false}, + "ami_block_device_mappings": &hcldec.BlockListSpec{TypeName: "ami_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, + "launch_block_device_mappings": &hcldec.BlockListSpec{TypeName: "launch_block_device_mappings", Nested: hcldec.ObjectSpec((*common.FlatBlockDevice)(nil).HCL2Spec())}, + "run_volume_tags": &hcldec.AttrSpec{Name: "run_volume_tags", Type: cty.Map(cty.String), Required: false}, + "run_volume_tag": &hcldec.BlockListSpec{TypeName: "run_volume_tag", Nested: hcldec.ObjectSpec((*config.FlatNameValue)(nil).HCL2Spec())}, + "no_ephemeral": &hcldec.AttrSpec{Name: "no_ephemeral", Type: cty.Bool, Required: false}, + "deprecate_at": &hcldec.AttrSpec{Name: "deprecate_at", Type: cty.String, Required: false}, + "fast_launch": &hcldec.BlockSpec{TypeName: "fast_launch", Nested: hcldec.ObjectSpec((*ebs.FlatFastLaunchConfig)(nil).HCL2Spec())}, +} + +func main() { + ret, err := hclspec.ToProto(spec) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to convert hclspec to proto: %s\n", err) + os.Exit(1) + } + + fmt.Printf("successfully converted hclspec to proto: %+v\n\n", ret.String()) + + back, err := ret.FromProto() + if err != nil { + fmt.Fprintf(os.Stderr, "failed to convert proto to hclspec: %s\n", err) + os.Exit(1) + } + + fmt.Printf("successfully converted proto to hclspec: %#v\n\n", back) +} diff --git a/grpc/structs/hclspec/convert.go b/grpc/structs/hclspec/convert.go new file mode 100644 index 000000000..9ff78abf4 --- /dev/null +++ b/grpc/structs/hclspec/convert.go @@ -0,0 +1,263 @@ +package hclspec + +import ( + "fmt" + "reflect" + + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// ToProto converts a hcldec.Spec to a protobuf-serialisable equivalent. +// +// This can then be used for gRPC communication over-the-wire for Packer plugins. +func ToProto(spec hcldec.Spec) (*Spec, error) { + switch concreteSpec := spec.(type) { + case *hcldec.AttrSpec: + attr, err := attrSpecToProto(concreteSpec) + if err != nil { + return nil, fmt.Errorf("failed to decode attribute spec: %s", err) + } + return &Spec{ + Block: &Spec_Attr{ + Attr: attr, + }, + }, nil + case *hcldec.BlockListSpec: + blspec, err := blockListSpecToProto(concreteSpec) + if err != nil { + return nil, fmt.Errorf("failed to decode block list spec: %s", err) + } + return &Spec{ + Block: &Spec_BlockList{ + BlockList: blspec, + }, + }, nil + case hcldec.ObjectSpec: + objSpec, err := objectSpecToProto(&concreteSpec) + if err != nil { + return nil, fmt.Errorf("failed to decode object spec: %s", err) + } + return &Spec{ + Block: &Spec_Object{ + Object: objSpec, + }, + }, nil + case *hcldec.BlockSpec: + blockSpec, err := blockSpecToProto(concreteSpec) + if err != nil { + return nil, fmt.Errorf("failed to decode object spec: %s", err) + } + return &Spec{ + Block: &Spec_BlockValue{ + BlockValue: blockSpec, + }, + }, nil + } + + return nil, fmt.Errorf("unsupported hcldec.Spec type: %#v", reflect.TypeOf(spec).String()) +} + +func blockSpecToProto(bsp *hcldec.BlockSpec) (*Block, error) { + nst, err := ToProto(bsp.Nested) + if err != nil { + return nil, fmt.Errorf("failed to decode block nested spec: %s", err) + } + + return &Block{ + Name: bsp.TypeName, + Required: bsp.Required, + Nested: nst, + }, nil +} + +func objectSpecToProto(hsp *hcldec.ObjectSpec) (*Object, error) { + outSpec := &Object{ + Attributes: map[string]*Spec{}, + } + + for name, spec := range *hsp { + pSpec, err := ToProto(spec) + if err != nil { + return nil, fmt.Errorf("failed to convert object attribute %q to hcldec.Spec: %s", name, err) + } + outSpec.Attributes[name] = pSpec + } + + return outSpec, nil +} + +func blockListSpecToProto(blspec *hcldec.BlockListSpec) (*BlockList, error) { + nested, err := ToProto(blspec.Nested) + if err != nil { + return nil, fmt.Errorf("failed to decode block list nested type: %s", err) + } + + return &BlockList{ + Name: blspec.TypeName, + Nested: nested, + }, nil +} + +func attrSpecToProto(attrSpec *hcldec.AttrSpec) (*Attr, error) { + convertedType, err := ctyTypeToProto(attrSpec.Type) + if err != nil { + return nil, fmt.Errorf("failed to convert ctyType for attribute %q: %s", attrSpec.Name, err) + } + + return &Attr{ + Name: attrSpec.Name, + Required: attrSpec.Required, + Type: convertedType, + }, nil +} + +func ctyTypeToProto(cType cty.Type) (*CtyType, error) { + if cType.IsPrimitiveType() { + switch cType { + case cty.Bool, + cty.String, + cty.Number: + return &CtyType{ + TypeDef: &CtyType_Primitive{ + Primitive: &CtyPrimitive{ + TypeString: cType.GoString(), + }, + }, + }, nil + default: + return nil, fmt.Errorf("Unknown primitive type: %s", cType.FriendlyName()) + } + } + + if cType.IsListType() { + el := cType.ElementType() + elType, err := ctyTypeToProto(el) + if err != nil { + return nil, fmt.Errorf("failed to extract valid cty.Type from list element: %s", err) + } + return &CtyType{ + TypeDef: &CtyType_List{ + List: &CtyList{ + ElementType: elType, + }, + }, + }, nil + } + + // As per the specification, cty.Map are always a map from string to a cty type + // + // Therefore, we don't need to worry about other types than the element's + if cType.IsMapType() { + el := cType.MapElementType() + elType, err := ctyTypeToProto(*el) + if err != nil { + return nil, fmt.Errorf("failed to extract valid cty.Type from map: %s", err) + } + return &CtyType{ + TypeDef: &CtyType_Map{ + Map: &CtyMap{ + ElementType: elType, + }, + }, + }, nil + } + + return nil, fmt.Errorf("unsupported cty.Type conversion to protobuf-compatible structure: %+v", cType) +} + +func (spec *Spec) FromProto() (hcldec.Spec, error) { + switch realSpec := spec.Block.(type) { + case *Spec_Attr: + return protoArgToHCLDecSpec(realSpec.Attr) + case *Spec_BlockList: + return protoBlockListToHCLDecSpec(realSpec.BlockList) + case *Spec_BlockValue: + return protoBlockToHCLDecSpec(realSpec.BlockValue) + case *Spec_Object: + return protoObjectSpecToHCLDecSpec(realSpec.Object) + } + + return nil, fmt.Errorf("unsupported spec type: %s", spec.String()) +} + +func protoObjectSpecToHCLDecSpec(protoSpec *Object) (*hcldec.ObjectSpec, error) { + outSpec := hcldec.ObjectSpec{} + + for name, spec := range protoSpec.Attributes { + attrSpec, err := spec.FromProto() + if err != nil { + return nil, fmt.Errorf("failed to decode object attribute %q: %s", name, err) + } + outSpec[name] = attrSpec + } + + return &outSpec, nil +} + +func protoBlockToHCLDecSpec(bl *Block) (*hcldec.BlockSpec, error) { + nested, err := bl.Nested.FromProto() + if err != nil { + return nil, fmt.Errorf("failed to decode block nested type from proto: %s", err) + } + + return &hcldec.BlockSpec{ + TypeName: bl.Name, + Required: bl.Required, + Nested: nested, + }, nil +} + +func protoBlockListToHCLDecSpec(bll *BlockList) (*hcldec.BlockListSpec, error) { + blSpec := bll.Nested + nested, err := blSpec.FromProto() + if err != nil { + return nil, fmt.Errorf("failed to decode block list nested type from proto: %s", err) + } + + return &hcldec.BlockListSpec{ + TypeName: bll.Name, + Nested: nested, + }, nil +} + +func protoArgToHCLDecSpec(attr *Attr) (*hcldec.AttrSpec, error) { + relType, err := protoTypeToCtyType(attr.Type) + if err != nil { + return nil, fmt.Errorf("failed to convert type of attribute %q: %s", attr.Name, err) + } + + return &hcldec.AttrSpec{ + Name: attr.Name, + Required: attr.Required, + Type: relType, + }, nil +} + +func protoTypeToCtyType(protoType *CtyType) (cty.Type, error) { + switch concrete := protoType.TypeDef.(type) { + case *CtyType_Primitive: + switch concrete.Primitive.TypeString { + case "cty.String": + return cty.String, nil + case "cty.Bool": + return cty.Bool, nil + case "cty.Number": + return cty.Number, nil + } + case *CtyType_List: + elType, err := protoTypeToCtyType(concrete.List.ElementType) + if err != nil { + return cty.NilType, fmt.Errorf("failed to convert list element type: %s", err) + } + return cty.List(elType), nil + case *CtyType_Map: + elType, err := protoTypeToCtyType(concrete.Map.ElementType) + if err != nil { + return cty.NilType, fmt.Errorf("failed to convert map element type: %s", err) + } + return cty.Map(elType), nil + } + + return cty.NilType, fmt.Errorf("unsupported cty.Type: %+v", protoType) +} diff --git a/grpc/structs/hclspec/hcl_spec.pb.go b/grpc/structs/hclspec/hcl_spec.pb.go new file mode 100644 index 000000000..02947120f --- /dev/null +++ b/grpc/structs/hclspec/hcl_spec.pb.go @@ -0,0 +1,951 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.12.4 +// source: grpc/structs/hclspec/hcl_spec.proto + +package hclspec + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// CtyType is any of the cty types that can be used for a Attribute. +// +// Bodies aren't an issue since they're encompassing a bunch of different +// attributes, which end-up referencing a type from this structure. +type CtyType struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Types that are assignable to TypeDef: + // + // *CtyType_Primitive + // *CtyType_List + // *CtyType_Map + TypeDef isCtyType_TypeDef `protobuf_oneof:"typeDef"` +} + +func (x *CtyType) Reset() { + *x = CtyType{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CtyType) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CtyType) ProtoMessage() {} + +func (x *CtyType) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CtyType.ProtoReflect.Descriptor instead. +func (*CtyType) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{0} +} + +func (m *CtyType) GetTypeDef() isCtyType_TypeDef { + if m != nil { + return m.TypeDef + } + return nil +} + +func (x *CtyType) GetPrimitive() *CtyPrimitive { + if x, ok := x.GetTypeDef().(*CtyType_Primitive); ok { + return x.Primitive + } + return nil +} + +func (x *CtyType) GetList() *CtyList { + if x, ok := x.GetTypeDef().(*CtyType_List); ok { + return x.List + } + return nil +} + +func (x *CtyType) GetMap() *CtyMap { + if x, ok := x.GetTypeDef().(*CtyType_Map); ok { + return x.Map + } + return nil +} + +type isCtyType_TypeDef interface { + isCtyType_TypeDef() +} + +type CtyType_Primitive struct { + Primitive *CtyPrimitive `protobuf:"bytes,1,opt,name=primitive,proto3,oneof"` +} + +type CtyType_List struct { + List *CtyList `protobuf:"bytes,2,opt,name=list,proto3,oneof"` +} + +type CtyType_Map struct { + Map *CtyMap `protobuf:"bytes,3,opt,name=map,proto3,oneof"` +} + +func (*CtyType_Primitive) isCtyType_TypeDef() {} + +func (*CtyType_List) isCtyType_TypeDef() {} + +func (*CtyType_Map) isCtyType_TypeDef() {} + +// CtyPrimitive is any of the cty.Type that match the `IsPrimitiveType` function +// i.e. either Number, Bool or String. +type CtyPrimitive struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TypeString string `protobuf:"bytes,1,opt,name=typeString,proto3" json:"typeString,omitempty"` +} + +func (x *CtyPrimitive) Reset() { + *x = CtyPrimitive{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CtyPrimitive) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CtyPrimitive) ProtoMessage() {} + +func (x *CtyPrimitive) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CtyPrimitive.ProtoReflect.Descriptor instead. +func (*CtyPrimitive) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{1} +} + +func (x *CtyPrimitive) GetTypeString() string { + if x != nil { + return x.TypeString + } + return "" +} + +// CtyList is a list of a cty.Type +type CtyList struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ElementType *CtyType `protobuf:"bytes,1,opt,name=elementType,proto3" json:"elementType,omitempty"` +} + +func (x *CtyList) Reset() { + *x = CtyList{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CtyList) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CtyList) ProtoMessage() {} + +func (x *CtyList) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CtyList.ProtoReflect.Descriptor instead. +func (*CtyList) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{2} +} + +func (x *CtyList) GetElementType() *CtyType { + if x != nil { + return x.ElementType + } + return nil +} + +// CtyMap is a map from one type to another +type CtyMap struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ElementType *CtyType `protobuf:"bytes,1,opt,name=elementType,proto3" json:"elementType,omitempty"` +} + +func (x *CtyMap) Reset() { + *x = CtyMap{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CtyMap) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CtyMap) ProtoMessage() {} + +func (x *CtyMap) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CtyMap.ProtoReflect.Descriptor instead. +func (*CtyMap) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{3} +} + +func (x *CtyMap) GetElementType() *CtyType { + if x != nil { + return x.ElementType + } + return nil +} + +// HCL2Spec matches what Packer already consumes from plugins in order to describe +// their contents' schema, and lets Packer decode the configuration provided by +// the user to cty values, and detect problems with the contents before executing them. +// +// These are sent over-the-wire over gRPC, much like the old system did using gob +// encoding and standard go RPC servers. +type HCL2Spec struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TypeSpec map[string]*Spec `protobuf:"bytes,1,rep,name=TypeSpec,proto3" json:"TypeSpec,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *HCL2Spec) Reset() { + *x = HCL2Spec{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HCL2Spec) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HCL2Spec) ProtoMessage() {} + +func (x *HCL2Spec) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HCL2Spec.ProtoReflect.Descriptor instead. +func (*HCL2Spec) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{4} +} + +func (x *HCL2Spec) GetTypeSpec() map[string]*Spec { + if x != nil { + return x.TypeSpec + } + return nil +} + +// A Spec is any kind of object that can convert losslessly to any of the hcldec.Spec types. +type Spec struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Types that are assignable to Block: + // + // *Spec_Object + // *Spec_Attr + // *Spec_BlockValue + // *Spec_BlockList + Block isSpec_Block `protobuf_oneof:"block"` +} + +func (x *Spec) Reset() { + *x = Spec{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Spec) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Spec) ProtoMessage() {} + +func (x *Spec) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Spec.ProtoReflect.Descriptor instead. +func (*Spec) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{5} +} + +func (m *Spec) GetBlock() isSpec_Block { + if m != nil { + return m.Block + } + return nil +} + +func (x *Spec) GetObject() *Object { + if x, ok := x.GetBlock().(*Spec_Object); ok { + return x.Object + } + return nil +} + +func (x *Spec) GetAttr() *Attr { + if x, ok := x.GetBlock().(*Spec_Attr); ok { + return x.Attr + } + return nil +} + +func (x *Spec) GetBlockValue() *Block { + if x, ok := x.GetBlock().(*Spec_BlockValue); ok { + return x.BlockValue + } + return nil +} + +func (x *Spec) GetBlockList() *BlockList { + if x, ok := x.GetBlock().(*Spec_BlockList); ok { + return x.BlockList + } + return nil +} + +type isSpec_Block interface { + isSpec_Block() +} + +type Spec_Object struct { + Object *Object `protobuf:"bytes,1,opt,name=object,proto3,oneof"` +} + +type Spec_Attr struct { + // buf:lint:ignore FIELD_LOWER_SNAKE_CASE + Attr *Attr `protobuf:"bytes,2,opt,name=Attr,proto3,oneof"` +} + +type Spec_BlockValue struct { + BlockValue *Block `protobuf:"bytes,3,opt,name=block_value,json=blockValue,proto3,oneof"` +} + +type Spec_BlockList struct { + BlockList *BlockList `protobuf:"bytes,4,opt,name=block_list,json=blockList,proto3,oneof"` +} + +func (*Spec_Object) isSpec_Block() {} + +func (*Spec_Attr) isSpec_Block() {} + +func (*Spec_BlockValue) isSpec_Block() {} + +func (*Spec_BlockList) isSpec_Block() {} + +// Attr spec type reads the value of an attribute in the current body +// and returns that value as its result. It also creates validation constraints +// for the given attribute name and its value. +type Attr struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Type *CtyType `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + Required bool `protobuf:"varint,3,opt,name=required,proto3" json:"required,omitempty"` +} + +func (x *Attr) Reset() { + *x = Attr{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Attr) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Attr) ProtoMessage() {} + +func (x *Attr) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Attr.ProtoReflect.Descriptor instead. +func (*Attr) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{6} +} + +func (x *Attr) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Attr) GetType() *CtyType { + if x != nil { + return x.Type + } + return nil +} + +func (x *Attr) GetRequired() bool { + if x != nil { + return x.Required + } + return false +} + +// Block spec type applies one nested spec block to the contents of a +// block within the current body and returns the result of that spec. It also +// creates validation constraints for the given block type name. +type Block struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Required bool `protobuf:"varint,2,opt,name=required,proto3" json:"required,omitempty"` + Nested *Spec `protobuf:"bytes,3,opt,name=nested,proto3" json:"nested,omitempty"` +} + +func (x *Block) Reset() { + *x = Block{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Block) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Block) ProtoMessage() {} + +func (x *Block) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[7] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Block.ProtoReflect.Descriptor instead. +func (*Block) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{7} +} + +func (x *Block) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Block) GetRequired() bool { + if x != nil { + return x.Required + } + return false +} + +func (x *Block) GetNested() *Spec { + if x != nil { + return x.Nested + } + return nil +} + +// BlockList spec type is similar to `Block`, but it accepts zero or +// more blocks of a specified type rather than requiring zero or one. The +// result is a JSON array with one entry per block of the given type. +type BlockList struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Nested *Spec `protobuf:"bytes,2,opt,name=nested,proto3" json:"nested,omitempty"` +} + +func (x *BlockList) Reset() { + *x = BlockList{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BlockList) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BlockList) ProtoMessage() {} + +func (x *BlockList) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BlockList.ProtoReflect.Descriptor instead. +func (*BlockList) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{8} +} + +func (x *BlockList) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *BlockList) GetNested() *Spec { + if x != nil { + return x.Nested + } + return nil +} + +// Object spec type is the most commonly used at the root of a spec file. +// Its result is a JSON object whose properties are set based on any nested +// spec blocks: +type Object struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Attributes map[string]*Spec `protobuf:"bytes,1,rep,name=attributes,proto3" json:"attributes,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *Object) Reset() { + *x = Object{} + if protoimpl.UnsafeEnabled { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Object) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Object) ProtoMessage() {} + +func (x *Object) ProtoReflect() protoreflect.Message { + mi := &file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Object.ProtoReflect.Descriptor instead. +func (*Object) Descriptor() ([]byte, []int) { + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP(), []int{9} +} + +func (x *Object) GetAttributes() map[string]*Spec { + if x != nil { + return x.Attributes + } + return nil +} + +var File_grpc_structs_hclspec_hcl_spec_proto protoreflect.FileDescriptor + +var file_grpc_structs_hclspec_hcl_spec_proto_rawDesc = []byte{ + 0x0a, 0x23, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x68, + 0x63, 0x6c, 0x73, 0x70, 0x65, 0x63, 0x2f, 0x68, 0x63, 0x6c, 0x5f, 0x73, 0x70, 0x65, 0x63, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x80, 0x01, 0x0a, 0x07, 0x43, 0x74, 0x79, 0x54, 0x79, 0x70, + 0x65, 0x12, 0x2d, 0x0a, 0x09, 0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x43, 0x74, 0x79, 0x50, 0x72, 0x69, 0x6d, 0x69, 0x74, + 0x69, 0x76, 0x65, 0x48, 0x00, 0x52, 0x09, 0x70, 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, + 0x12, 0x1e, 0x0a, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, + 0x2e, 0x43, 0x74, 0x79, 0x4c, 0x69, 0x73, 0x74, 0x48, 0x00, 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, + 0x12, 0x1b, 0x0a, 0x03, 0x6d, 0x61, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, + 0x43, 0x74, 0x79, 0x4d, 0x61, 0x70, 0x48, 0x00, 0x52, 0x03, 0x6d, 0x61, 0x70, 0x42, 0x09, 0x0a, + 0x07, 0x74, 0x79, 0x70, 0x65, 0x44, 0x65, 0x66, 0x22, 0x2e, 0x0a, 0x0c, 0x43, 0x74, 0x79, 0x50, + 0x72, 0x69, 0x6d, 0x69, 0x74, 0x69, 0x76, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x79, 0x70, 0x65, + 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x74, 0x79, + 0x70, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x22, 0x35, 0x0a, 0x07, 0x43, 0x74, 0x79, 0x4c, + 0x69, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x0b, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, + 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x43, 0x74, 0x79, 0x54, 0x79, + 0x70, 0x65, 0x52, 0x0b, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, + 0x34, 0x0a, 0x06, 0x43, 0x74, 0x79, 0x4d, 0x61, 0x70, 0x12, 0x2a, 0x0a, 0x0b, 0x65, 0x6c, 0x65, + 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, + 0x2e, 0x43, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, 0x65, 0x6c, 0x65, 0x6d, 0x65, 0x6e, + 0x74, 0x54, 0x79, 0x70, 0x65, 0x22, 0x83, 0x01, 0x0a, 0x08, 0x48, 0x43, 0x4c, 0x32, 0x53, 0x70, + 0x65, 0x63, 0x12, 0x33, 0x0a, 0x08, 0x54, 0x79, 0x70, 0x65, 0x53, 0x70, 0x65, 0x63, 0x18, 0x01, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x48, 0x43, 0x4c, 0x32, 0x53, 0x70, 0x65, 0x63, 0x2e, + 0x54, 0x79, 0x70, 0x65, 0x53, 0x70, 0x65, 0x63, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x54, + 0x79, 0x70, 0x65, 0x53, 0x70, 0x65, 0x63, 0x1a, 0x42, 0x0a, 0x0d, 0x54, 0x79, 0x70, 0x65, 0x53, + 0x70, 0x65, 0x63, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x53, 0x70, 0x65, 0x63, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa7, 0x01, 0x0a, 0x04, + 0x53, 0x70, 0x65, 0x63, 0x12, 0x21, 0x0a, 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x48, 0x00, 0x52, + 0x06, 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x1b, 0x0a, 0x04, 0x41, 0x74, 0x74, 0x72, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x41, 0x74, 0x74, 0x72, 0x48, 0x00, 0x52, 0x04, + 0x41, 0x74, 0x74, 0x72, 0x12, 0x29, 0x0a, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x06, 0x2e, 0x42, 0x6c, 0x6f, 0x63, + 0x6b, 0x48, 0x00, 0x52, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, + 0x2b, 0x0a, 0x0a, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6c, 0x69, 0x73, 0x74, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x48, + 0x00, 0x52, 0x09, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x42, 0x07, 0x0a, 0x05, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x22, 0x54, 0x0a, 0x04, 0x41, 0x74, 0x74, 0x72, 0x12, 0x12, 0x0a, + 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x12, 0x1c, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x08, 0x2e, 0x43, 0x74, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, + 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x56, 0x0a, 0x05, 0x42, + 0x6c, 0x6f, 0x63, 0x6b, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x72, 0x65, 0x71, 0x75, + 0x69, 0x72, 0x65, 0x64, 0x12, 0x1d, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x53, 0x70, 0x65, 0x63, 0x52, 0x06, 0x6e, 0x65, 0x73, + 0x74, 0x65, 0x64, 0x22, 0x3e, 0x0a, 0x09, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4c, 0x69, 0x73, 0x74, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x06, 0x6e, 0x65, 0x73, 0x74, 0x65, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x53, 0x70, 0x65, 0x63, 0x52, 0x06, 0x6e, 0x65, 0x73, + 0x74, 0x65, 0x64, 0x22, 0x87, 0x01, 0x0a, 0x06, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x12, 0x37, + 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x2e, 0x41, 0x74, 0x74, 0x72, + 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0a, 0x61, 0x74, 0x74, + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x1a, 0x44, 0x0a, 0x0f, 0x41, 0x74, 0x74, 0x72, 0x69, + 0x62, 0x75, 0x74, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x1b, 0x0a, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x05, 0x2e, 0x53, 0x70, + 0x65, 0x63, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x16, 0x5a, + 0x14, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x73, 0x2f, 0x68, 0x63, + 0x6c, 0x73, 0x70, 0x65, 0x63, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_grpc_structs_hclspec_hcl_spec_proto_rawDescOnce sync.Once + file_grpc_structs_hclspec_hcl_spec_proto_rawDescData = file_grpc_structs_hclspec_hcl_spec_proto_rawDesc +) + +func file_grpc_structs_hclspec_hcl_spec_proto_rawDescGZIP() []byte { + file_grpc_structs_hclspec_hcl_spec_proto_rawDescOnce.Do(func() { + file_grpc_structs_hclspec_hcl_spec_proto_rawDescData = protoimpl.X.CompressGZIP(file_grpc_structs_hclspec_hcl_spec_proto_rawDescData) + }) + return file_grpc_structs_hclspec_hcl_spec_proto_rawDescData +} + +var file_grpc_structs_hclspec_hcl_spec_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_grpc_structs_hclspec_hcl_spec_proto_goTypes = []interface{}{ + (*CtyType)(nil), // 0: CtyType + (*CtyPrimitive)(nil), // 1: CtyPrimitive + (*CtyList)(nil), // 2: CtyList + (*CtyMap)(nil), // 3: CtyMap + (*HCL2Spec)(nil), // 4: HCL2Spec + (*Spec)(nil), // 5: Spec + (*Attr)(nil), // 6: Attr + (*Block)(nil), // 7: Block + (*BlockList)(nil), // 8: BlockList + (*Object)(nil), // 9: Object + nil, // 10: HCL2Spec.TypeSpecEntry + nil, // 11: Object.AttributesEntry +} +var file_grpc_structs_hclspec_hcl_spec_proto_depIdxs = []int32{ + 1, // 0: CtyType.primitive:type_name -> CtyPrimitive + 2, // 1: CtyType.list:type_name -> CtyList + 3, // 2: CtyType.map:type_name -> CtyMap + 0, // 3: CtyList.elementType:type_name -> CtyType + 0, // 4: CtyMap.elementType:type_name -> CtyType + 10, // 5: HCL2Spec.TypeSpec:type_name -> HCL2Spec.TypeSpecEntry + 9, // 6: Spec.object:type_name -> Object + 6, // 7: Spec.Attr:type_name -> Attr + 7, // 8: Spec.block_value:type_name -> Block + 8, // 9: Spec.block_list:type_name -> BlockList + 0, // 10: Attr.type:type_name -> CtyType + 5, // 11: Block.nested:type_name -> Spec + 5, // 12: BlockList.nested:type_name -> Spec + 11, // 13: Object.attributes:type_name -> Object.AttributesEntry + 5, // 14: HCL2Spec.TypeSpecEntry.value:type_name -> Spec + 5, // 15: Object.AttributesEntry.value:type_name -> Spec + 16, // [16:16] is the sub-list for method output_type + 16, // [16:16] is the sub-list for method input_type + 16, // [16:16] is the sub-list for extension type_name + 16, // [16:16] is the sub-list for extension extendee + 0, // [0:16] is the sub-list for field type_name +} + +func init() { file_grpc_structs_hclspec_hcl_spec_proto_init() } +func file_grpc_structs_hclspec_hcl_spec_proto_init() { + if File_grpc_structs_hclspec_hcl_spec_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CtyType); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CtyPrimitive); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CtyList); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CtyMap); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HCL2Spec); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Spec); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Attr); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Block); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BlockList); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Object); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[0].OneofWrappers = []interface{}{ + (*CtyType_Primitive)(nil), + (*CtyType_List)(nil), + (*CtyType_Map)(nil), + } + file_grpc_structs_hclspec_hcl_spec_proto_msgTypes[5].OneofWrappers = []interface{}{ + (*Spec_Object)(nil), + (*Spec_Attr)(nil), + (*Spec_BlockValue)(nil), + (*Spec_BlockList)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_grpc_structs_hclspec_hcl_spec_proto_rawDesc, + NumEnums: 0, + NumMessages: 12, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_grpc_structs_hclspec_hcl_spec_proto_goTypes, + DependencyIndexes: file_grpc_structs_hclspec_hcl_spec_proto_depIdxs, + MessageInfos: file_grpc_structs_hclspec_hcl_spec_proto_msgTypes, + }.Build() + File_grpc_structs_hclspec_hcl_spec_proto = out.File + file_grpc_structs_hclspec_hcl_spec_proto_rawDesc = nil + file_grpc_structs_hclspec_hcl_spec_proto_goTypes = nil + file_grpc_structs_hclspec_hcl_spec_proto_depIdxs = nil +} diff --git a/grpc/structs/hclspec/hcl_spec.proto b/grpc/structs/hclspec/hcl_spec.proto new file mode 100644 index 000000000..ec5fe265d --- /dev/null +++ b/grpc/structs/hclspec/hcl_spec.proto @@ -0,0 +1,94 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +syntax = "proto3"; + +option go_package = "grpc/structs/hclspec"; + +// CtyType is any of the cty types that can be used for a Attribute. +// +// Bodies aren't an issue since they're encompassing a bunch of different +// attributes, which end-up referencing a type from this structure. +message CtyType { + oneof typeDef { + CtyPrimitive primitive = 1; + CtyList list = 2; + CtyMap map = 3; + } +} + +// CtyPrimitive is any of the cty.Type that match the `IsPrimitiveType` function +// i.e. either Number, Bool or String. +message CtyPrimitive { + string typeString = 1; +} + +// CtyList is a list of a cty.Type +message CtyList { + CtyType elementType = 1; +} + +// CtyMap is a map from one type to another +message CtyMap { + CtyType elementType = 1; +} + +/* +HCL2Spec matches what Packer already consumes from plugins in order to describe +their contents' schema, and lets Packer decode the configuration provided by +the user to cty values, and detect problems with the contents before executing them. + +These are sent over-the-wire over gRPC, much like the old system did using gob +encoding and standard go RPC servers. +*/ +message HCL2Spec { + map TypeSpec = 1; +} + +// A Spec is any kind of object that can convert losslessly to any of the hcldec.Spec types. +message Spec { + oneof block { + Object object = 1; + // buf:lint:ignore FIELD_LOWER_SNAKE_CASE + Attr Attr = 2; + Block block_value = 3; + BlockList block_list = 4; + } +} + +/* Attr spec type reads the value of an attribute in the current body +and returns that value as its result. It also creates validation constraints +for the given attribute name and its value. +*/ +message Attr { + string name = 1; + CtyType type = 2; + bool required = 3; +} + +/* Block spec type applies one nested spec block to the contents of a +block within the current body and returns the result of that spec. It also +creates validation constraints for the given block type name. +*/ +message Block { + string name = 1; + bool required = 2; + Spec nested = 3; +} + +/* BlockList spec type is similar to `Block`, but it accepts zero or +more blocks of a specified type rather than requiring zero or one. The +result is a JSON array with one entry per block of the given type. +*/ +message BlockList { + string name = 1; + Spec nested = 2; +} + +/* Object spec type is the most commonly used at the root of a spec file. +Its result is a JSON object whose properties are set based on any nested +spec blocks: +*/ +message Object { + map attributes = 1; +}