From 75fa00f477ee7983af44dc6c3a511bfcfac8aead Mon Sep 17 00:00:00 2001 From: John Houston Date: Fri, 5 Apr 2024 16:35:15 -0400 Subject: [PATCH] Add provider defined functions for encoding and decoding Kubernetes manifests (#2428) --- .changelog/2428.txt | 3 + .../workflows/provider_functions_unit.yaml | 33 +++ GNUmakefile | 9 +- go.mod | 60 ++--- go.sum | 139 ++++++----- .../framework/provider/functions/decode.go | 118 ++++++++++ .../framework/provider/functions/encode.go | 153 ++++++++++++ .../provider/functions/functions_test.go | 14 ++ .../provider/functions/manifest_decode.go | 63 +++++ .../functions/manifest_decode_multi.go | 55 +++++ .../functions/manifest_decode_multi_test.go | 219 ++++++++++++++++++ .../functions/manifest_decode_test.go | 53 +++++ .../provider/functions/manifest_encode.go | 56 +++++ .../functions/manifest_encode_test.go | 219 ++++++++++++++++++ .../testdata/decode_manifest_invalid.yaml | 7 + .../decode_manifest_invalid_syntax.yaml | 14 ++ .../functions/testdata/decode_multi.yaml | 119 ++++++++++ .../functions/testdata/decode_single.yaml | 14 ++ internal/framework/provider/provider.go | 15 +- website/docs/d/nodes.html.markdown | 2 +- .../functions/manifest_decode.html.markdown | 48 ++++ .../manifest_decode_multi.html.markdown | 48 ++++ .../functions/manifest_encode.html.markdown | 61 +++++ 23 files changed, 1416 insertions(+), 106 deletions(-) create mode 100644 .changelog/2428.txt create mode 100644 .github/workflows/provider_functions_unit.yaml create mode 100644 internal/framework/provider/functions/decode.go create mode 100644 internal/framework/provider/functions/encode.go create mode 100644 internal/framework/provider/functions/functions_test.go create mode 100644 internal/framework/provider/functions/manifest_decode.go create mode 100644 internal/framework/provider/functions/manifest_decode_multi.go create mode 100644 internal/framework/provider/functions/manifest_decode_multi_test.go create mode 100644 internal/framework/provider/functions/manifest_decode_test.go create mode 100644 internal/framework/provider/functions/manifest_encode.go create mode 100644 internal/framework/provider/functions/manifest_encode_test.go create mode 100644 internal/framework/provider/functions/testdata/decode_manifest_invalid.yaml create mode 100644 internal/framework/provider/functions/testdata/decode_manifest_invalid_syntax.yaml create mode 100644 internal/framework/provider/functions/testdata/decode_multi.yaml create mode 100644 internal/framework/provider/functions/testdata/decode_single.yaml create mode 100644 website/docs/functions/manifest_decode.html.markdown create mode 100644 website/docs/functions/manifest_decode_multi.html.markdown create mode 100644 website/docs/functions/manifest_encode.html.markdown diff --git a/.changelog/2428.txt b/.changelog/2428.txt new file mode 100644 index 0000000000..be5ab0e92c --- /dev/null +++ b/.changelog/2428.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Add provider defined functions: `manifest_encode`, `manifest_decode`, `manifest_decode_multi` +``` \ No newline at end of file diff --git a/.github/workflows/provider_functions_unit.yaml b/.github/workflows/provider_functions_unit.yaml new file mode 100644 index 0000000000..b0510d4a65 --- /dev/null +++ b/.github/workflows/provider_functions_unit.yaml @@ -0,0 +1,33 @@ +name: Provider Functions Unit Tests + +on: + push: + branches: + - main + paths: + - "internal/framework/provider/functions/**/*.go" + pull_request: + branches: + - main + paths: + - "internal/framework/provider/functions/**/*.go" + workflow_dispatch: + +jobs: + unit_tests: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - name: Set up Go + uses: actions/setup-go@fac708d6674e30b6ba41289acaab6d4b75aa0753 # v4.0.1 + with: + go-version-file: 'go.mod' + - name: Go mod verify + run: go mod verify + - name: Run unit tests + env: + # FIXME this needs to be changed once the 1.8 release goes out + TF_ACC_TERRAFORM_VERSION: 1.8.0-rc1 + run: | + make testfuncs diff --git a/GNUmakefile b/GNUmakefile index ad45824f9c..566cd3e110 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -8,6 +8,8 @@ PKG_NAME := kubernetes OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH) TF_PROV_DOCS := $(PWD)/kubernetes/test-infra/tfproviderdocs +PROVIDER_FUNCTIONS_DIR := "$(PROVIDER_DIR)/internal/framework/provider/functions" + ifneq ($(PWD),$(PROVIDER_DIR)) $(error "Makefile must be run from the provider directory") endif @@ -75,6 +77,9 @@ test: fmtcheck vet testacc: fmtcheck vet TF_ACC=1 go test $(TEST) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS) -timeout 3h +testfuncs: fmtcheck + go test $(PROVIDER_FUNCTIONS_DIR) -v -vet=off $(TESTARGS) -parallel $(PARALLEL_RUNS) + test-compile: @if [ "$(TEST)" = "./..." ]; then \ echo "ERROR: Set TEST to a specific package. For example,"; \ @@ -99,8 +104,8 @@ tests-lint-fix: tools tools: go install github.com/client9/misspell/cmd/misspell@v0.3.4 go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@v0.28.1 - go install github.com/bflad/tfproviderdocs@v0.9.1 - go install github.com/katbyte/terrafmt@v0.5.2 + go install github.com/bflad/tfproviderdocs@v0.12.0 + go install github.com/katbyte/terrafmt@v0.5.3 go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.55.2 go install github.com/hashicorp/go-changelog/cmd/changelog-build@latest go install github.com/hashicorp/go-changelog/cmd/changelog-entry@latest diff --git a/go.mod b/go.mod index 3270b5eabd..692dec6d6d 100644 --- a/go.mod +++ b/go.mod @@ -1,28 +1,31 @@ module github.com/hashicorp/terraform-provider-kubernetes +go 1.21 + require ( github.com/Masterminds/semver v1.5.0 github.com/getkin/kin-openapi v0.111.0 github.com/google/go-cmp v0.6.0 - github.com/hashicorp/go-hclog v1.5.0 + github.com/hashicorp/go-hclog v1.6.2 github.com/hashicorp/go-plugin v1.6.0 github.com/hashicorp/go-version v1.6.0 - github.com/hashicorp/hc-install v0.6.0 - github.com/hashicorp/hcl/v2 v2.18.0 - github.com/hashicorp/terraform-exec v0.19.0 - github.com/hashicorp/terraform-json v0.17.1 + github.com/hashicorp/hc-install v0.6.3 + github.com/hashicorp/hcl/v2 v2.20.0 + github.com/hashicorp/terraform-exec v0.20.0 + github.com/hashicorp/terraform-json v0.21.0 github.com/hashicorp/terraform-plugin-docs v0.16.0 - github.com/hashicorp/terraform-plugin-framework v1.5.0 - github.com/hashicorp/terraform-plugin-go v0.20.0 + github.com/hashicorp/terraform-plugin-framework v1.7.0 + github.com/hashicorp/terraform-plugin-go v0.22.1 github.com/hashicorp/terraform-plugin-log v0.9.0 - github.com/hashicorp/terraform-plugin-mux v0.12.0 - github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 + github.com/hashicorp/terraform-plugin-mux v0.15.0 + github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 + github.com/hashicorp/terraform-plugin-testing v1.7.0 github.com/jinzhu/copier v0.3.5 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/hashstructure v1.1.0 github.com/robfig/cron v1.2.0 github.com/stretchr/testify v1.8.2 - golang.org/x/mod v0.14.0 + golang.org/x/mod v0.15.0 k8s.io/api v0.28.6 k8s.io/apiextensions-apiserver v0.28.6 k8s.io/apimachinery v0.28.6 @@ -30,20 +33,21 @@ require ( k8s.io/kube-aggregator v0.28.6 k8s.io/kubectl v0.28.6 k8s.io/kubernetes v1.28.6 + sigs.k8s.io/yaml v1.4.0 ) require ( github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.1.1 // indirect - github.com/Masterminds/sprig/v3 v3.2.2 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/sprig/v3 v3.2.3 // indirect + github.com/ProtonMail/go-crypto v1.1.0-alpha.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/google/gnostic-models v0.6.8 // indirect - github.com/huandu/xstrings v1.3.2 // indirect + github.com/huandu/xstrings v1.3.3 // indirect github.com/invopop/yaml v0.2.0 // indirect github.com/mitchellh/cli v1.1.5 // indirect github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect @@ -55,8 +59,9 @@ require ( github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect - golang.org/x/sync v0.5.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect + golang.org/x/sync v0.6.0 // indirect + golang.org/x/tools v0.16.1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect ) require ( @@ -68,7 +73,7 @@ require ( github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect github.com/fatih/camelcase v1.0.0 // indirect - github.com/fatih/color v1.13.0 // indirect + github.com/fatih/color v1.16.0 // indirect github.com/go-errors/errors v1.4.2 // indirect github.com/go-logr/logr v1.2.4 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect @@ -79,7 +84,7 @@ require ( github.com/google/btree v1.1.2 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-checkpoint v0.5.0 // indirect @@ -98,7 +103,7 @@ require ( github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 github.com/mitchellh/go-wordwrap v1.0.1 // indirect @@ -118,17 +123,17 @@ require ( github.com/spf13/pflag v1.0.5 // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/xlab/treeprint v1.2.0 // indirect - github.com/zclconf/go-cty v1.14.0 + github.com/zclconf/go-cty v1.14.3 go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect - golang.org/x/crypto v0.17.0 // indirect - golang.org/x/net v0.19.0 // indirect - golang.org/x/oauth2 v0.13.0 // indirect - golang.org/x/sys v0.15.0 // indirect - golang.org/x/term v0.15.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/oauth2 v0.16.0 // indirect + golang.org/x/sys v0.18.0 // indirect + golang.org/x/term v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/grpc v1.60.0 + google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect @@ -142,7 +147,4 @@ require ( sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect - sigs.k8s.io/yaml v1.3.0 // indirect ) - -go 1.21 diff --git a/go.sum b/go.sum index 49781d4535..8f849ae2e1 100644 --- a/go.sum +++ b/go.sum @@ -10,17 +10,16 @@ github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJ github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= -github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.1/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= -github.com/Masterminds/sprig/v3 v3.2.2 h1:17jRggJu518dr3QaafizSXOjKYp94wKfABxUmyxvxX8= -github.com/Masterminds/sprig/v3 v3.2.2/go.mod h1:UoaO7Yp8KlPnJIYWTFkMaqPUYKTfGFPhxNuwnnxkKlk= +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/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= -github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= -github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= +github.com/ProtonMail/go-crypto v1.1.0-alpha.0 h1:nHGfwXmFvJrSR9xu8qL7BkO4DqTHXE9N5vPhgY2I+j0= +github.com/ProtonMail/go-crypto v1.1.0-alpha.0/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= @@ -35,7 +34,6 @@ github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= -github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNSjIRk= github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA= @@ -43,13 +41,14 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -66,8 +65,9 @@ github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f/go.mod h1:OSY github.com/fatih/camelcase v1.0.0 h1:hxNvNX/xYBp0ovncs8WyWZrOrpBNub/JfaMvbURyft8= github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwoZc+/fpc= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/getkin/kin-openapi v0.111.0 h1:zspOcFKBCQOY8d9Yockcbit8iVR2hco9qLaoQoj7kmw= @@ -76,10 +76,10 @@ github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxI github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= -github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= -github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= -github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= +github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -125,6 +125,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -136,8 +137,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA= @@ -152,8 +153,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= 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.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= -github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-hclog v1.6.2 h1:NOtoftovWkDheyUM/8JW3QMiXyxJK3uHRK7wV04nD2I= +github.com/hashicorp/go-hclog v1.6.2/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= @@ -164,28 +165,30 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hc-install v0.6.0 h1:fDHnU7JNFNSQebVKYhHZ0va1bC6SrPQ8fpebsvNr2w4= -github.com/hashicorp/hc-install v0.6.0/go.mod h1:10I912u3nntx9Umo1VAeYPUUuehk0aRQJYpMwbX5wQA= -github.com/hashicorp/hcl/v2 v2.18.0 h1:wYnG7Lt31t2zYkcquwgKo6MWXzRUDIeIVU5naZwHLl8= -github.com/hashicorp/hcl/v2 v2.18.0/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= +github.com/hashicorp/hc-install v0.6.3 h1:yE/r1yJvWbtrJ0STwScgEnCanb0U9v7zp0Gbkmcoxqs= +github.com/hashicorp/hc-install v0.6.3/go.mod h1:KamGdbodYzlufbWh4r9NRo8y6GLHWZP2GBtdnms1Ln0= +github.com/hashicorp/hcl/v2 v2.20.0 h1:l++cRs/5jQOiKVvqXZm/P1ZEfVXJmvLS9WSVxkaeTb4= +github.com/hashicorp/hcl/v2 v2.20.0/go.mod h1:WmcD/Ym72MDOOx5F62Ly+leloeu6H7m0pG7VBiU6pQk= 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-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81SpgVtZNNtFSM= -github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg= -github.com/hashicorp/terraform-json v0.17.1 h1:eMfvh/uWggKmY7Pmb3T85u86E2EQg6EQHgyRwf3RkyA= -github.com/hashicorp/terraform-json v0.17.1/go.mod h1:Huy6zt6euxaY9knPAFKjUITn8QxUFIe9VuSzb4zn/0o= +github.com/hashicorp/terraform-exec v0.20.0 h1:DIZnPsqzPGuUnq6cH8jWcPunBfY+C+M8JyYF3vpnuEo= +github.com/hashicorp/terraform-exec v0.20.0/go.mod h1:ckKGkJWbsNqFKV1itgMnE0hY9IYf1HoiekpuN0eWoDw= +github.com/hashicorp/terraform-json v0.21.0 h1:9NQxbLNqPbEMze+S6+YluEdXgJmhQykRyRNd+zTI05U= +github.com/hashicorp/terraform-json v0.21.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk= github.com/hashicorp/terraform-plugin-docs v0.16.0 h1:UmxFr3AScl6Wged84jndJIfFccGyBZn52KtMNsS12dI= github.com/hashicorp/terraform-plugin-docs v0.16.0/go.mod h1:M3ZrlKBJAbPMtNOPwHicGi1c+hZUh7/g0ifT/z7TVfA= -github.com/hashicorp/terraform-plugin-framework v1.5.0 h1:8kcvqJs/x6QyOFSdeAyEgsenVOUeC/IyKpi2ul4fjTg= -github.com/hashicorp/terraform-plugin-framework v1.5.0/go.mod h1:6waavirukIlFpVpthbGd2PUNYaFedB0RwW3MDzJ/rtc= -github.com/hashicorp/terraform-plugin-go v0.20.0 h1:oqvoUlL+2EUbKNsJbIt3zqqZ7wi6lzn4ufkn/UA51xQ= -github.com/hashicorp/terraform-plugin-go v0.20.0/go.mod h1:Rr8LBdMlY53a3Z/HpP+ZU3/xCDqtKNCkeI9qOyT10QE= +github.com/hashicorp/terraform-plugin-framework v1.7.0 h1:wOULbVmfONnJo9iq7/q+iBOBJul5vRovaYJIu2cY/Pw= +github.com/hashicorp/terraform-plugin-framework v1.7.0/go.mod h1:jY9Id+3KbZ17OMpulgnWLSfwxNVYSoYBQFTgsx044CI= +github.com/hashicorp/terraform-plugin-go v0.22.1 h1:iTS7WHNVrn7uhe3cojtvWWn83cm2Z6ryIUDTRO0EV7w= +github.com/hashicorp/terraform-plugin-go v0.22.1/go.mod h1:qrjnqRghvQ6KnDbB12XeZ4FluclYwptntoWCr9QaXTI= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= -github.com/hashicorp/terraform-plugin-mux v0.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY= -github.com/hashicorp/terraform-plugin-mux v0.12.0/go.mod h1:8MR0AgmV+Q03DIjyrAKxXyYlq2EUnYBQP8gxAAA0zeM= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0 h1:wcOKYwPI9IorAJEBLzgclh3xVolO7ZorYd6U1vnok14= -github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0/go.mod h1:qH/34G25Ugdj5FcM95cSoXzUgIbgfhVLXCcEcYaMwq8= +github.com/hashicorp/terraform-plugin-mux v0.15.0 h1:+/+lDx0WUsIOpkAmdwBIoFU8UP9o2eZASoOnLsWbKME= +github.com/hashicorp/terraform-plugin-mux v0.15.0/go.mod h1:9ezplb1Dyq394zQ+ldB0nvy/qbNAz3mMoHHseMTMaKo= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0 h1:qHprzXy/As0rxedphECBEQAh3R4yp6pKksKHcqZx5G8= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0/go.mod h1:H+8tjs9TjV2w57QFVSMBQacf8k/E1XwLXGCARgViC6A= +github.com/hashicorp/terraform-plugin-testing v1.7.0 h1:I6aeCyZ30z4NiI3tzyDoO6fS7YxP5xSL1ceOon3gTe8= +github.com/hashicorp/terraform-plugin-testing v1.7.0/go.mod h1:sbAreCleJNOCz+y5vVHV8EJkIWZKi/t4ndKiUjM9vao= github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= @@ -193,8 +196,9 @@ github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv2 github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE= github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= +github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM= github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= @@ -241,8 +245,9 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/cli v1.1.5 h1:OxRIeJXpAMztws/XHlN2vu6imG5Dpq+j61AzAX5fLng= github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4= github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= @@ -307,8 +312,8 @@ github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNX github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= -github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= +github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ= +github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= @@ -346,8 +351,8 @@ github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 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.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc= -github.com/zclconf/go-cty v1.14.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= +github.com/zclconf/go-cty v1.14.3 h1:1JXy1XroaGrzZuG6X9dt7HL6s9AwbY+l4UNL8o5B6ho= +github.com/zclconf/go-cty v1.14.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca h1:VdD38733bfYv5tUZwEIskMM93VanwNIi5bIKnDrJdEY= go.starlark.net v0.0.0-20230525235612-a134d8f9ddca/go.mod h1:jxU+3+j+71eXOW14274+SmmuW82qJzl6iZSeqEtTGds= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -356,10 +361,9 @@ 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-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -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/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 h1:EDuYyU/MkFXllv9QF9819VlI9a4tzGuCbhG0ExK9o1U= golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= @@ -369,9 +373,8 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 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.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= +golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -383,22 +386,19 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= -golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= -golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= +golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= +golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/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-20190911185100-cd5d95a43a6e/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.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= -golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/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= @@ -416,27 +416,21 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/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.3.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.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.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.0.0-20220526004731-065cf7ba2467/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.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -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/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= +golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= 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.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.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 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.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= @@ -450,7 +444,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/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.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -464,13 +457,13 @@ google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJ google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80/go.mod h1:PAREbraiVEVGVdTZsVWjSbbTtSyGbAgIIvni8a8CD5s= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k= -google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM= +google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= +google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= 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= @@ -534,5 +527,5 @@ sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 h1:W6cLQc5pnqM sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3/go.mod h1:JWP1Fj0VWGHyw3YUPjXSQnRnrwezrZSrApfX5S0nIag= sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE= sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ihdVs8cGKBraizNC69E= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= +sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/internal/framework/provider/functions/decode.go b/internal/framework/provider/functions/decode.go new file mode 100644 index 0000000000..79de2a61f1 --- /dev/null +++ b/internal/framework/provider/functions/decode.go @@ -0,0 +1,118 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions + +import ( + "context" + "fmt" + "math/big" + "regexp" + + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types" + "sigs.k8s.io/yaml" +) + +var documentSeparator = regexp.MustCompile(`(:?^|\s*\n)---\s*`) + +func decode(ctx context.Context, manifest string) (v types.Tuple, diags diag.Diagnostics) { + docs := documentSeparator.Split(manifest, -1) + dtypes := []attr.Type{} + dvalues := []attr.Value{} + diags = diag.Diagnostics{} + + for _, d := range docs { + var data map[string]any + err := yaml.Unmarshal([]byte(d), &data) + if err != nil { + diags.Append(diag.NewErrorDiagnostic("Invalid YAML document", err.Error())) + return + } + + if len(data) == 0 { + diags.Append(diag.NewWarningDiagnostic("Empty document", "encountered a YAML document with no values")) + continue + } + + if err := validateKubernetesManifest(data); err != nil { + diags.Append(diag.NewErrorDiagnostic("Invalid Kubernetes manifest", err.Error())) + return + } + + obj, d := decodeScalar(ctx, data) + diags.Append(d...) + if diags.HasError() { + return + } + dtypes = append(dtypes, obj.Type(ctx)) + dvalues = append(dvalues, obj) + } + + return types.TupleValue(dtypes, dvalues) +} + +func decodeMapping(ctx context.Context, m map[string]any) (attr.Value, diag.Diagnostics) { + vm := make(map[string]attr.Value, len(m)) + tm := make(map[string]attr.Type, len(m)) + + for k, v := range m { + vv, diags := decodeScalar(ctx, v) + if diags.HasError() { + return nil, diags + } + vm[k] = vv + tm[k] = vv.Type(ctx) + } + + return types.ObjectValue(tm, vm) +} + +func decodeSequence(ctx context.Context, s []any) (attr.Value, diag.Diagnostics) { + vl := make([]attr.Value, len(s)) + tl := make([]attr.Type, len(s)) + + for i, v := range s { + vv, diags := decodeScalar(ctx, v) + if diags.HasError() { + return nil, diags + } + vl[i] = vv + tl[i] = vv.Type(ctx) + } + + return types.TupleValue(tl, vl) +} + +func decodeScalar(ctx context.Context, m any) (value attr.Value, diags diag.Diagnostics) { + switch v := m.(type) { + case float64: + value = types.NumberValue(big.NewFloat(float64(v))) + case bool: + value = types.BoolValue(v) + case string: + value = types.StringValue(v) + case []any: + return decodeSequence(ctx, v) + case map[string]any: + return decodeMapping(ctx, v) + default: + diags.Append(diag.NewErrorDiagnostic("failed to decode", fmt.Sprintf("unexpected type: %T for value %#v", v, v))) + } + return +} + +func validateKubernetesManifest(m map[string]any) error { + // NOTE: a Kubernetes manifest should have: + // - an apiVersion + // - a kind + // - a metadata field + for _, k := range []string{"apiVersion", "kind", "metadata"} { + _, ok := m[k] + if !ok { + return fmt.Errorf("missing field %q", k) + } + } + return nil +} diff --git a/internal/framework/provider/functions/encode.go b/internal/framework/provider/functions/encode.go new file mode 100644 index 0000000000..b34fbb7a48 --- /dev/null +++ b/internal/framework/provider/functions/encode.go @@ -0,0 +1,153 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions + +import ( + "fmt" + "strings" + + "github.com/hashicorp/terraform-plugin-framework/attr" + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/types/basetypes" + + "sigs.k8s.io/yaml" +) + +func encodeValue(v attr.Value) (any, error) { + if v.IsNull() { + return nil, nil + } + + switch vv := v.(type) { + case basetypes.StringValue: + return vv.ValueString(), nil + case basetypes.NumberValue: + f, _ := vv.ValueBigFloat().Float64() + return f, nil + case basetypes.BoolValue: + return vv.ValueBool(), nil + case basetypes.ObjectValue: + return encodeObject(vv) + case basetypes.TupleValue: + return encodeTuple(vv) + case basetypes.MapValue: + return encodeMap(vv) + case basetypes.ListValue: + return encodeList(vv) + case basetypes.SetValue: + return encodeSet(vv) + default: + return nil, fmt.Errorf("tried to encode unsupported type: %T: %v", v, vv) + } +} + +func encodeSet(sv basetypes.SetValue) ([]any, error) { + elems := sv.Elements() + size := len(elems) + l := make([]any, size) + for i := 0; i < size; i++ { + var err error + l[i], err = encodeValue(elems[i]) + if err != nil { + return nil, err + } + } + return l, nil +} + +func encodeList(lv basetypes.ListValue) ([]any, error) { + elems := lv.Elements() + size := len(elems) + l := make([]any, size) + for i := 0; i < size; i++ { + var err error + l[i], err = encodeValue(elems[i]) + if err != nil { + return nil, err + } + } + return l, nil +} + +func encodeTuple(tv basetypes.TupleValue) ([]any, error) { + elems := tv.Elements() + size := len(elems) + l := make([]any, size) + for i := 0; i < size; i++ { + var err error + l[i], err = encodeValue(elems[i]) + if err != nil { + return nil, err + } + } + return l, nil +} + +func encodeObject(ov basetypes.ObjectValue) (map[string]any, error) { + attrs := ov.Attributes() + m := make(map[string]any, len(attrs)) + for k, v := range attrs { + var err error + m[k], err = encodeValue(v) + if err != nil { + return nil, err + } + } + return m, nil +} + +func encodeMap(mv basetypes.MapValue) (map[string]any, error) { + elems := mv.Elements() + m := make(map[string]any, len(elems)) + for k, v := range elems { + var err error + m[k], err = encodeValue(v) + if err != nil { + return nil, err + } + } + return m, nil +} + +func marshal(m map[string]any) (encoded string, diags diag.Diagnostics) { + if err := validateKubernetesManifest(m); err != nil { + diags.Append(diag.NewErrorDiagnostic("Invalid Kubernetes manifest", err.Error())) + return + } + b, err := yaml.Marshal(m) + if err != nil { + diags.Append(diag.NewErrorDiagnostic("Error marshalling yaml", err.Error())) + return + } + return string(b), nil +} + +func encode(v attr.Value) (encoded string, diags diag.Diagnostics) { + val, err := encodeValue(v) + if err != nil { + return "", diag.Diagnostics{diag.NewErrorDiagnostic("Error decoding manifest", err.Error())} + } + + if m, ok := val.(map[string]any); ok { + return marshal(m) + } else if l, ok := val.([]any); ok { + for _, vv := range l { + m, ok := vv.(map[string]any) + if !ok { + diags.Append(diag.NewErrorDiagnostic( + "List of manifests contained an invalid resource", fmt.Sprintf("value doesn't seem to be a manifest: %#v", vv))) + } + s, diags := marshal(m) + if diags.HasError() { + return "", diags + } + encoded = strings.Join([]string{encoded, s}, "---\n") + } + return string(encoded), nil + } + + diags.Append(diag.NewErrorDiagnostic( + "Invalid manifest", fmt.Sprintf("value doesn't seem to be a manifest: %#v", val))) + return +} diff --git a/internal/framework/provider/functions/functions_test.go b/internal/framework/provider/functions/functions_test.go new file mode 100644 index 0000000000..5877d4432d --- /dev/null +++ b/internal/framework/provider/functions/functions_test.go @@ -0,0 +1,14 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions_test + +import ( + "github.com/hashicorp/terraform-plugin-framework/providerserver" + "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-provider-kubernetes/internal/framework/provider" +) + +var testAccProtoV5ProviderFactories = map[string]func() (tfprotov5.ProviderServer, error){ + "kubernetes": providerserver.NewProtocol5WithError(provider.New("test")), +} diff --git a/internal/framework/provider/functions/manifest_decode.go b/internal/framework/provider/functions/manifest_decode.go new file mode 100644 index 0000000000..d126755cb0 --- /dev/null +++ b/internal/framework/provider/functions/manifest_decode.go @@ -0,0 +1,63 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/function" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var _ function.Function = ManifestDecodeFunction{} + +func NewManifestDecodeFunction() function.Function { + return &ManifestDecodeFunction{} +} + +type ManifestDecodeFunction struct{} + +func (f ManifestDecodeFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { + resp.Name = "manifest_decode" +} + +func (f ManifestDecodeFunction) Definition(_ context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { + resp.Definition = function.Definition{ + Summary: "Decode a Kubernetes YAML manifest", + MarkdownDescription: "Given a YAML text containing a Kubernetes manifest, will decode and return an object representation of that resource.", + Parameters: []function.Parameter{ + function.StringParameter{ + Name: "manifest", + MarkdownDescription: "The YAML text for a Kubernetes manifest", + }, + }, + Return: function.DynamicReturn{}, + } +} + +func (f ManifestDecodeFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + var manifest string + + resp.Error = req.Arguments.Get(ctx, &manifest) + if resp.Error != nil { + return + } + + tv, diags := decode(ctx, manifest) + if diags.HasError() { + resp.Error = function.FuncErrorFromDiags(ctx, diags) + return + } + + elems := tv.Elements() + if len(elems) == 0 { + resp.Error = function.NewFuncError("Invalid manifest: YAML document is empty") + return + } else if len(elems) > 1 { + resp.Error = function.NewFuncError("YAML manifest contains multiple resources: use decode_manifest_multi to decode manifests containing more than one resource") + } + + dynamResp := types.DynamicValue(elems[0]) + resp.Error = resp.Result.Set(ctx, &dynamResp) +} diff --git a/internal/framework/provider/functions/manifest_decode_multi.go b/internal/framework/provider/functions/manifest_decode_multi.go new file mode 100644 index 0000000000..b3f3fec7f1 --- /dev/null +++ b/internal/framework/provider/functions/manifest_decode_multi.go @@ -0,0 +1,55 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/function" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var _ function.Function = ManifestDecodeMultiFunction{} + +func NewManifestDecodeMultiFunction() function.Function { + return &ManifestDecodeMultiFunction{} +} + +type ManifestDecodeMultiFunction struct{} + +func (f ManifestDecodeMultiFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { + resp.Name = "manifest_decode_multi" +} + +func (f ManifestDecodeMultiFunction) Definition(_ context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { + resp.Definition = function.Definition{ + Summary: "Decode a Kubernetes YAML manifest containing multiple resources", + MarkdownDescription: "Given a YAML text containing a Kubernetes manifest with multiple resources, will decode the manifest and return a tuple of object representations for each resource.", + Parameters: []function.Parameter{ + function.StringParameter{ + Name: "manifest", + MarkdownDescription: "The YAML plaintext for a Kubernetes manifest", + }, + }, + Return: function.DynamicReturn{}, + } +} + +func (f ManifestDecodeMultiFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + var manifest string + + resp.Error = req.Arguments.Get(ctx, &manifest) + if resp.Error != nil { + return + } + + tv, diags := decode(ctx, manifest) + if diags.HasError() { + resp.Error = function.FuncErrorFromDiags(ctx, diags) + return + } + + dynamResp := types.DynamicValue(tv) + resp.Error = resp.Result.Set(ctx, &dynamResp) +} diff --git a/internal/framework/provider/functions/manifest_decode_multi_test.go b/internal/framework/provider/functions/manifest_decode_multi_test.go new file mode 100644 index 0000000000..666365236e --- /dev/null +++ b/internal/framework/provider/functions/manifest_decode_multi_test.go @@ -0,0 +1,219 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions_test + +import ( + "fmt" + "math/big" + "os" + "path" + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" +) + +func TestManifestDecodeMulti(t *testing.T) { + t.Parallel() + + outputName := "test" + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testManifestDecodeMultiConfig("testdata/decode_single.yaml"), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownOutputValue(outputName, knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "apiVersion": knownvalue.StringExact("v1"), + "data": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "configfile": knownvalue.StringExact("---\ntest: document\n"), + }), + "kind": knownvalue.StringExact("ConfigMap"), + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "test": knownvalue.StringExact("test---label"), + }), + "name": knownvalue.StringExact("test-configmap"), + }), + }), + })), + }, + }, + { + Config: testManifestDecodeMultiConfig("testdata/decode_multi.yaml"), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownOutputValue(outputName, knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "apiVersion": knownvalue.StringExact("apps/v1"), + "kind": knownvalue.StringExact("DaemonSet"), + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "k8s-app": knownvalue.StringExact("fluentd-logging"), + }), + "name": knownvalue.StringExact("fluentd-elasticsearch"), + "namespace": knownvalue.StringExact("kube-system"), + }), + "spec": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "selector": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "matchLabels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("fluentd-elasticsearch"), + }), + }), + "template": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("fluentd-elasticsearch"), + }), + }), + "spec": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "containers": knownvalue.ListExact([]knownvalue.Check{knownvalue.ObjectExact(map[string]knownvalue.Check{ + "image": knownvalue.StringExact("quay.io/fluentd_elasticsearch/fluentd:v2.5.2"), + "name": knownvalue.StringExact("fluentd-elasticsearch"), + "resources": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "limits": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "cpu": knownvalue.NumberExact(big.NewFloat(1.5)), + "memory": knownvalue.StringExact("200Mi"), + }), + "requests": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "cpu": knownvalue.Int64Exact(1), + "memory": knownvalue.StringExact("200Mi"), + }), + }), + "volumeMounts": knownvalue.ListExact([]knownvalue.Check{knownvalue.ObjectExact(map[string]knownvalue.Check{ + "mountPath": knownvalue.StringExact("/var/log"), + "name": knownvalue.StringExact("varlog"), + })}), + })}), + "terminationGracePeriodSeconds": knownvalue.Int64Exact(30), + "tolerations": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "effect": knownvalue.StringExact("NoSchedule"), + "key": knownvalue.StringExact("node-role.kubernetes.io/control-plane"), + "operator": knownvalue.StringExact("Exists"), + }), + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "effect": knownvalue.StringExact("NoSchedule"), + "key": knownvalue.StringExact("node-role.kubernetes.io/master"), + "operator": knownvalue.StringExact("Exists"), + }), + }), + "volumes": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "hostPath": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "path": knownvalue.StringExact("/var/log"), + }), + "name": knownvalue.StringExact("varlog"), + }), + }), + }), + }), + }), + }), + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "apiVersion": knownvalue.StringExact("v1"), + "data": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "configfile": knownvalue.StringExact("---\ntest: document"), + "immutable": knownvalue.Bool(false), + }), + "kind": knownvalue.StringExact("ConfigMap"), + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "test": knownvalue.StringExact("test---label"), + }), + "name": knownvalue.StringExact("test-configmap"), + "namespace": knownvalue.StringExact("kube-system"), + }), + }), + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "apiVersion": knownvalue.StringExact("apps/v1"), + "kind": knownvalue.StringExact("DaemonSet"), + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "k8s-app": knownvalue.StringExact("fluentd-logging"), + }), + "name": knownvalue.StringExact("fluentd-elasticsearch2"), + "namespace": knownvalue.StringExact("kube-system"), + }), + "spec": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "selector": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "matchLabels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("fluentd-elasticsearch"), + }), + }), + "template": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "name": knownvalue.StringExact("fluentd-elasticsearch"), + "something": knownvalue.StringExact("helloworld"), + }), + }), + "spec": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "containers": knownvalue.ListExact([]knownvalue.Check{knownvalue.ObjectExact(map[string]knownvalue.Check{ + "image": knownvalue.StringExact("quay.io/fluentd_elasticsearch/fluentd:v2.5.2"), + "name": knownvalue.StringExact("fluentd-elasticsearch"), + "resources": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "limits": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "memory": knownvalue.StringExact("200Mi"), + }), + "requests": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "cpu": knownvalue.StringExact("100m"), + "memory": knownvalue.StringExact("200Mi"), + }), + }), + "volumeMounts": knownvalue.ListExact([]knownvalue.Check{knownvalue.ObjectExact(map[string]knownvalue.Check{ + "mountPath": knownvalue.StringExact("/var/log"), + "name": knownvalue.StringExact("varlog"), + })}), + })}), + "terminationGracePeriodSeconds": knownvalue.Int64Exact(30), + "tolerations": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "effect": knownvalue.StringExact("NoSchedule"), + "key": knownvalue.StringExact("node-role.kubernetes.io/control-plane"), + "operator": knownvalue.StringExact("Exists"), + }), + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "effect": knownvalue.StringExact("NoSchedule"), + "key": knownvalue.StringExact("node-role.kubernetes.io/master"), + "operator": knownvalue.StringExact("Exists"), + }), + }), + "volumes": knownvalue.ListExact([]knownvalue.Check{ + knownvalue.ObjectExact(map[string]knownvalue.Check{ + "hostPath": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "path": knownvalue.StringExact("/var/log"), + }), + "name": knownvalue.StringExact("varlog"), + }), + }), + }), + }), + }), + }), + })), + }, + }, + { + Config: testManifestDecodeMultiConfig("testdata/decode_manifest_invalid.yaml"), + ExpectError: regexp.MustCompile(`Invalid\s+Kubernetes\s+manifest`), + }, + { + Config: testManifestDecodeMultiConfig("testdata/decode_manifest_invalid_syntax.yaml"), + ExpectError: regexp.MustCompile(`Invalid\s+YAML\s+document`), + }, + }, + }) +} + +func testManifestDecodeMultiConfig(filename string) string { + cwd, _ := os.Getwd() + return fmt.Sprintf(` +output "test" { + value = provider::kubernetes::manifest_decode_multi(file(%q)) +}`, path.Join(cwd, filename)) +} diff --git a/internal/framework/provider/functions/manifest_decode_test.go b/internal/framework/provider/functions/manifest_decode_test.go new file mode 100644 index 0000000000..7902660a41 --- /dev/null +++ b/internal/framework/provider/functions/manifest_decode_test.go @@ -0,0 +1,53 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions_test + +import ( + "fmt" + "os" + "path" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/knownvalue" + "github.com/hashicorp/terraform-plugin-testing/statecheck" +) + +func TestManifestDecode(t *testing.T) { + t.Parallel() + + outputName := "test" + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testManifestDecodeConfig("testdata/decode_single.yaml"), + ConfigStateChecks: []statecheck.StateCheck{ + statecheck.ExpectKnownOutputValue(outputName, knownvalue.ObjectExact(map[string]knownvalue.Check{ + "apiVersion": knownvalue.StringExact("v1"), + "data": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "configfile": knownvalue.StringExact("---\ntest: document\n"), + }), + "kind": knownvalue.StringExact("ConfigMap"), + "metadata": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "labels": knownvalue.ObjectExact(map[string]knownvalue.Check{ + "test": knownvalue.StringExact("test---label"), + }), + "name": knownvalue.StringExact("test-configmap"), + }), + })), + }, + }, + }, + }) +} + +func testManifestDecodeConfig(filename string) string { + cwd, _ := os.Getwd() + return fmt.Sprintf(` +output "test" { + value = provider::kubernetes::manifest_decode(file(%q)) +}`, path.Join(cwd, filename)) +} diff --git a/internal/framework/provider/functions/manifest_encode.go b/internal/framework/provider/functions/manifest_encode.go new file mode 100644 index 0000000000..7c474d1fdf --- /dev/null +++ b/internal/framework/provider/functions/manifest_encode.go @@ -0,0 +1,56 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions + +import ( + "context" + + "github.com/hashicorp/terraform-plugin-framework/function" + "github.com/hashicorp/terraform-plugin-framework/types" +) + +var _ function.Function = ManifestEncodeFunction{} + +func NewManifestEncodeFunction() function.Function { + return &ManifestEncodeFunction{} +} + +type ManifestEncodeFunction struct{} + +func (f ManifestEncodeFunction) Metadata(_ context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { + resp.Name = "manifest_encode" +} + +func (f ManifestEncodeFunction) Definition(_ context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { + resp.Definition = function.Definition{ + Summary: "Encode an object to Kubernetes YAML", + MarkdownDescription: "Given an object representation of a Kubernetes manifest, will encode and return a YAML string for that resource.", + Parameters: []function.Parameter{ + function.DynamicParameter{ + Name: "manifest", + MarkdownDescription: "The object representation of a Kubernetes manifest", + }, + }, + Return: function.StringReturn{}, + } +} + +func (f ManifestEncodeFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { + var manifest types.Dynamic + + resp.Error = req.Arguments.Get(ctx, &manifest) + if resp.Error != nil { + return + } + + uv := manifest.UnderlyingValue() + s, diags := encode(uv) + if diags.HasError() { + resp.Error = function.FuncErrorFromDiags(ctx, diags) + return + } + + svalue := types.StringValue(s) + resp.Error = resp.Result.Set(ctx, &svalue) +} diff --git a/internal/framework/provider/functions/manifest_encode_test.go b/internal/framework/provider/functions/manifest_encode_test.go new file mode 100644 index 0000000000..9a4c131cef --- /dev/null +++ b/internal/framework/provider/functions/manifest_encode_test.go @@ -0,0 +1,219 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package functions_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestManifestEncode(t *testing.T) { + t.Parallel() + + outputName := "test" + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testManifestEncodeConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckOutput(outputName, `apiVersion: v1 +data: + test: test +kind: ConfigMap +metadata: + name: test + namespace: null +`), + ), + }, + }, + }) +} + +func TestManifestEncodeMulti(t *testing.T) { + t.Parallel() + + outputName := "test" + + resource.UnitTest(t, resource.TestCase{ + ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, + Steps: []resource.TestStep{ + { + Config: testManifestEncodeMultiConfig(), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckOutput(outputName, `--- +apiVersion: v1 +data: + test: test +immutable: false +kind: ConfigMap +metadata: + name: test +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + labels: + k8s-app: fluentd-logging + name: fluentd-elasticsearch2 + namespace: kube-system +spec: + selector: + matchLabels: + name: fluentd-elasticsearch + template: + metadata: + labels: + name: fluentd-elasticsearch + something: helloworld + spec: + containers: + - image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2 + name: fluentd-elasticsearch + resources: + limits: + cpu: 1.5 + memory: 200Mi + requests: + cpu: 100m + memory: 200Mi + volumeMounts: + - mountPath: /var/log + name: varlog + terminationGracePeriodSeconds: 30 + tolerations: + - effect: NoSchedule + key: node-role.kubernetes.io/control-plane + operator: Exists + - effect: NoSchedule + key: node-role.kubernetes.io/master + operator: Exists + volumes: + - hostPath: + path: /var/log + name: varlog +`), + ), + }, + }, + }) +} + +func testManifestEncodeConfig() string { + return ` +locals { + single_manifest = { + apiVersion = "v1" + kind = "ConfigMap" + metadata = { + name = "test" + namespace = null + } + data = { + "test" = "test" + } + } +} + +output "test" { + value = provider::kubernetes::manifest_encode(local.single_manifest) +}` +} + +func testManifestEncodeMultiConfig() string { + return ` +locals { + multi_manifest = [ + { + apiVersion = "v1" + kind = "ConfigMap" + metadata = { + name = "test" + } + data = { + "test" = "test" + } + immutable = false + }, + { + apiVersion = "apps/v1" + kind = "DaemonSet" + metadata = { + name = "fluentd-elasticsearch2" + namespace = "kube-system" + labels = { + "k8s-app" = "fluentd-logging" + } + } + spec = { + selector = { + matchLabels = { + name = "fluentd-elasticsearch" + } + } + template = { + metadata = { + labels = { + "something" = "helloworld" + "name" = "fluentd-elasticsearch" + } + } + spec = { + tolerations = [ + { + key = "node-role.kubernetes.io/control-plane" + operator = "Exists" + effect = "NoSchedule" + }, + { + key = "node-role.kubernetes.io/master" + operator = "Exists" + effect = "NoSchedule" + } + ] + containers = [ + { + name = "fluentd-elasticsearch" + image = "quay.io/fluentd_elasticsearch/fluentd:v2.5.2" + resources = { + limits = { + cpu = 1.5 + memory = "200Mi" + } + requests = { + cpu = "100m" + memory = "200Mi" + } + } + volumeMounts = [ + { + mountPath = "/var/log" + name = "varlog" + } + ] + } + ] + terminationGracePeriodSeconds = 30 + volumes = [ + { + name = "varlog" + hostPath = { + path = "/var/log" + } + } + ] + } + } + } + } + ] +} + +output "test" { + value = provider::kubernetes::manifest_encode(local.multi_manifest) +}` +} diff --git a/internal/framework/provider/functions/testdata/decode_manifest_invalid.yaml b/internal/framework/provider/functions/testdata/decode_manifest_invalid.yaml new file mode 100644 index 0000000000..c04e64f535 --- /dev/null +++ b/internal/framework/provider/functions/testdata/decode_manifest_invalid.yaml @@ -0,0 +1,7 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +--- +this: is +not: a +kubernetes: manifest diff --git a/internal/framework/provider/functions/testdata/decode_manifest_invalid_syntax.yaml b/internal/framework/provider/functions/testdata/decode_manifest_invalid_syntax.yaml new file mode 100644 index 0000000000..950820f5f8 --- /dev/null +++ b/internal/framework/provider/functions/testdata/decode_manifest_invalid_syntax.yaml @@ -0,0 +1,14 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +-- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-configmap + labels: + test: "test---label" + &data: + configfile: | + --- + test: document diff --git a/internal/framework/provider/functions/testdata/decode_multi.yaml b/internal/framework/provider/functions/testdata/decode_multi.yaml new file mode 100644 index 0000000000..b59897eacc --- /dev/null +++ b/internal/framework/provider/functions/testdata/decode_multi.yaml @@ -0,0 +1,119 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +# test comment +--- +# test comment +--- +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: fluentd-elasticsearch + namespace: kube-system + labels: + k8s-app: fluentd-logging +spec: + selector: + matchLabels: + name: fluentd-elasticsearch + template: + metadata: + labels: + name: fluentd-elasticsearch + spec: + tolerations: + # these tolerations are to have the daemonset runnable on control plane nodes + # remove them if your control plane nodes should not run pods + - key: node-role.kubernetes.io/control-plane + operator: Exists + effect: NoSchedule + - key: node-role.kubernetes.io/master + operator: Exists + effect: NoSchedule + containers: + - name: fluentd-elasticsearch + image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2 + resources: + limits: + cpu: 1.5 + memory: 200Mi + requests: + cpu: 1 + memory: 200Mi + volumeMounts: + - name: varlog + mountPath: /var/log + # it may be desirable to set a high priority class to ensure that a DaemonSet Pod + # preempts running Pods + # priorityClassName: important + terminationGracePeriodSeconds: 30 + volumes: + - name: varlog + hostPath: + path: /var/log +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-configmap + namespace: kube-system + labels: + test: "test---label" +data: + immutable: false + configfile: | + --- + test: document + +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: fluentd-elasticsearch2 + namespace: kube-system + labels: + k8s-app: fluentd-logging +spec: + selector: + matchLabels: + name: fluentd-elasticsearch + template: + metadata: + labels: + something: "helloworld" + name: fluentd-elasticsearch + spec: + tolerations: + # these tolerations are to have the daemonset runnable on control plane nodes + # remove them if your control plane nodes should not run pods + - key: node-role.kubernetes.io/control-plane + operator: Exists + effect: NoSchedule + - key: node-role.kubernetes.io/master + operator: Exists + effect: NoSchedule + containers: + - name: fluentd-elasticsearch + image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2 + resources: + limits: + memory: 200Mi + requests: + cpu: 100m + memory: 200Mi + volumeMounts: + - name: varlog + mountPath: /var/log + # it may be desirable to set a high priority class to ensure that a DaemonSet Pod + # preempts running Pods + # priorityClassName: important + terminationGracePeriodSeconds: 30 + volumes: + - name: varlog + hostPath: + path: /var/log +--- +--- +# test comment +--- diff --git a/internal/framework/provider/functions/testdata/decode_single.yaml b/internal/framework/provider/functions/testdata/decode_single.yaml new file mode 100644 index 0000000000..c8bf9405cf --- /dev/null +++ b/internal/framework/provider/functions/testdata/decode_single.yaml @@ -0,0 +1,14 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: test-configmap + labels: + test: "test---label" +data: + configfile: | + --- + test: document diff --git a/internal/framework/provider/provider.go b/internal/framework/provider/provider.go index bbfd63ed06..977760449a 100644 --- a/internal/framework/provider/provider.go +++ b/internal/framework/provider/provider.go @@ -7,14 +7,19 @@ import ( "context" "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/function" "github.com/hashicorp/terraform-plugin-framework/provider" "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" + pfunctions "github.com/hashicorp/terraform-provider-kubernetes/internal/framework/provider/functions" ) // Ensure KubernetesProvider satisfies various provider interfaces. -var _ provider.Provider = &KubernetesProvider{} +var ( + _ provider.Provider = &KubernetesProvider{} + _ provider.ProviderWithFunctions = &KubernetesProvider{} +) // KubernetesProvider defines the provider implementation. type KubernetesProvider struct { @@ -186,6 +191,14 @@ func (p *KubernetesProvider) DataSources(ctx context.Context) []func() datasourc return []func() datasource.DataSource{} } +func (p *KubernetesProvider) Functions(ctx context.Context) []func() function.Function { + return []func() function.Function{ + pfunctions.NewManifestDecodeFunction, + pfunctions.NewManifestDecodeMultiFunction, + pfunctions.NewManifestEncodeFunction, + } +} + func New(version string) provider.Provider { return &KubernetesProvider{ version: version, diff --git a/website/docs/d/nodes.html.markdown b/website/docs/d/nodes.html.markdown index e4a8a279ef..2e1e28d6d1 100644 --- a/website/docs/d/nodes.html.markdown +++ b/website/docs/d/nodes.html.markdown @@ -107,7 +107,7 @@ The following arguments are supported: * `machine_id` - Machine ID reported by the node see [main(5) machine-id](http://man7.org/linux/man-pages/man5/machine-id.5.html) for more info. * `system_uuid` - System UUID reported by the node. This field is - specific to [Red Hat hosts](https://access.redhat.com/documentation/en-us/red_hat_subscription_management/1/html/rhsm/uuid) + specific to Red Hat hosts. * `boot_id` - Boot ID reported by the node. * `kernel_version` - Kernel Version reported by the node from `uname -r` * `os_image` - OS Image reported by the node from `/etc/os-release` diff --git a/website/docs/functions/manifest_decode.html.markdown b/website/docs/functions/manifest_decode.html.markdown new file mode 100644 index 0000000000..b6651737b3 --- /dev/null +++ b/website/docs/functions/manifest_decode.html.markdown @@ -0,0 +1,48 @@ +--- +subcategory: "" +layout: "kubernetes" +page_title: "manifest_decode function" +description: |- + Decode a Kubernetes YAML manifest +--- + +# function: manifest_decode + +Given a YAML text containing a Kubernetes manifest, will decode and return an object representation of that resource. + +## Example Usage + +```hcl +# Configuration using provider functions must include required_providers configuration. +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + # Setting the provider version is a strongly recommended practice + # version = "..." + } + } + # Provider functions require Terraform 1.8 and later. + required_version = ">= 1.8.0" +} + +output "example_output" { + value = provider::kubernetes::manifest_decode(file("manifest.yaml")) +} +``` + +## Signature + +```text +manifest_decode(manifest string) object +``` + +## Arguments + + +1. `manifest` (String) The YAML text for a Kubernetes manifest + + +## Return Type + +The `object` returned from `manifest_decode` is dynamic and will mirror the structure of the YAML manifest supplied. diff --git a/website/docs/functions/manifest_decode_multi.html.markdown b/website/docs/functions/manifest_decode_multi.html.markdown new file mode 100644 index 0000000000..b7ad390e27 --- /dev/null +++ b/website/docs/functions/manifest_decode_multi.html.markdown @@ -0,0 +1,48 @@ +--- +subcategory: "" +layout: "kubernetes" +page_title: "manifest_decode_multi function" +description: |- + Decode a Kubernetes YAML manifest containing multiple resources +--- + +# function: manifest_decode_multi + +Given a YAML text containing a Kubernetes manifest with multiple resources, will decode the manifest and return a tuple of object representations for each resource. + +## Example Usage + +```hcl +# Configuration using provider functions must include required_providers configuration. +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + # Setting the provider version is a strongly recommended practice + # version = "..." + } + } + # Provider functions require Terraform 1.8 and later. + required_version = ">= 1.8.0" +} + +output "example_output" { + value = provider::kubernetes::manifest_decode_multi(file("manifest.yaml")) +} +``` + +## Signature + +```text +manifest_decode_multi(manifest string) tuple +``` + +## Arguments + + +1. `manifest` (String) The YAML text for a Kubernetes manifest containing multiple resources + + +## Return Type + +The `tuple` returned from `manifest_decode_multi` will contain dynamic objects that mirror the structure of the resources in YAML manifest supplied. diff --git a/website/docs/functions/manifest_encode.html.markdown b/website/docs/functions/manifest_encode.html.markdown new file mode 100644 index 0000000000..0237894ca5 --- /dev/null +++ b/website/docs/functions/manifest_encode.html.markdown @@ -0,0 +1,61 @@ +--- +subcategory: "" +layout: "kubernetes" +page_title: "manifest_encode function" +description: |- + Decode a Kubernetes YAML manifest containing multiple resources +--- + +# function: manifest_encode + +Given an object representation of a Kubernetes manifest, will encode and return a YAML string for that resource. + +## Example Usage + +```hcl +# Configuration using provider functions must include required_providers configuration. +terraform { + required_providers { + kubernetes = { + source = "hashicorp/kubernetes" + # Setting the provider version is a strongly recommended practice + # version = "..." + } + } + # Provider functions require Terraform 1.8 and later. + required_version = ">= 1.8.0" +} + +locals { + manifest = { + apiVersion = "v1" + kind = "ConfigMap" + metadata = { + name = "example" + } + data = { + EXAMPLE = "example" + } + } +} + +output "example_output" { + value = provider::kubernetes::manifest_encode(local.manifest) +} +``` + +## Signature + +```text +manifest_encode(manifest object) string +``` + +## Arguments + + +1. `manifest` (String) The object representation of a Kubernetes manifest + + +## Return Type + +The `string` returned from `manifest_encode` will contain the YAML encoded Kubernetes manifest.