diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..f774ad9 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,23 @@ +name: Go +on: [push, pull_request] +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.13 + uses: actions/setup-go@v1 + with: + go-version: 1.13 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v1 + + - name: Test + run: make test + + - name: Build + run: make build \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..001de55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +terraform-artifactory.tf +terraform-provider-artifactory +*.dll +*.exe +.DS_Store +example.tf +terraform.tfplan +terraform.tfstate +bin/ +modules-dev/ +vendor/*/ +website/.vagrant +website/build +website/node_modules +.vagrant/ +*.backup +./*.tfstate +.terraform/ +*.log +*.bak +*~ +.*.swp +.idea +resources +resources2 +src/ +.vscode +.vscode/ +dist/ +examples/terraform.d +*.iml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fcb86a3 --- /dev/null +++ b/Makefile @@ -0,0 +1,54 @@ +.DEFAULT_GOAL := build +OS := $(shell go env GOOS) +ARCH := $(shell go env GOARCH) +PLUGIN_PATH ?= ${HOME}/.terraform.d/plugins/${OS}_${ARCH} +PLUGIN_NAME := terraform-provider-helmfile +DIST_PATH := dist/${OS}_${ARCH} +GO_PACKAGES := $(shell go list ./... | grep -v /vendor/) +GO_FILES := $(shell find . -type f -name '*.go') + + +.PHONY: all +all: test build + +.PHONY: test +test: test-all + +.PHONY: test-all +test-all: + @TF_ACC=1 go test -v -race $(GO_PACKAGES) + +${DIST_PATH}/${PLUGIN_NAME}: ${GO_FILES} + mkdir -p $(DIST_PATH); \ + go build -o $(DIST_PATH)/${PLUGIN_NAME} + +.PHONY: build +build: ${DIST_PATH}/${PLUGIN_NAME} + +.PHONY: install +install: build + mkdir -p $(PLUGIN_PATH); \ + rm -rf $(PLUGIN_PATH)/${PLUGIN_NAME}; \ + install -m 0755 $(DIST_PATH)/${PLUGIN_NAME} $(PLUGIN_PATH)/${PLUGIN_NAME} + +.PHONY: example/plan +example/plan: + mkdir -p examples/terraform.d/plugins + env PLUGIN_PATH=examples/terraform.d/plugins/$(OS)_$(ARCH) make install + cd examples; terraform init; terraform plan + +.PHONY: example/apply +example/apply: + mkdir -p examples/terraform.d/plugins + env PLUGIN_PATH=examples/terraform.d/plugins/$(OS)_$(ARCH) make install + cd examples; terraform init; terraform apply + +.PHONY: example/destroy +example/destroy: + mkdir -p examples/terraform.d/plugins + env PLUGIN_PATH=examples/terraform.d/plugins/$(OS)_$(ARCH) make install + cd examples; terraform init; terraform destroy + +.PHONY: clean +clean: + rm -rf ${DIST_PATH}/* diff --git a/README.md b/README.md new file mode 100644 index 0000000..a302d03 --- /dev/null +++ b/README.md @@ -0,0 +1,172 @@ +# terraform-provider-helmfile + +Deploy [Helmfile](https://github.com/roboll/helmfile/) releases from within Terraform. + +Benefits: + +- Entry-point to your infrastructure and app deployments as a whole +- Input terraform variables and outputs into Helmfile +- Blue-green deployment of your whole stack with tf's `create_before_destroy` + +## Prerequisites + +Install the `terraform-provider-helmfile` binary under `terraform.d/plugins/${OS}_${ARCH}`. + +## Examples + +There is nothing to configure for the provider, declare it like so + +``` +provider "helmfile" {} + +resource "helmfile_release_set" "mystack" { + path = "./helmfile.yaml" + + # Install and choose from one of installed versions of helm + # By changing this, you can upgrade helm per release_set + # Default: helm + helm_binary = "helm-3.0.0" + + # Install and choose from one of installed versions of helmfile + # By changing this, you can upgrade helmfile per release_set + # Default: helmfile + binary = "helmfile-v0.93.0" + + working_directory = path.module + + # Helmfile environment name to deploy + # Default: default + environment = "prod" + + # Environment variables available to helmfile's requireEnv + environment_variables = { + FOO = "foo" + } + + # State values to be passed to Helmfile + values = { + # Corresponds to --state-values-set name=myapp + name = "myapp" + } + + # State values files to be passed to Helmfile + values_files = [ + "overrides.yaml", + ] + + # Label key-value pairs to filter releases + selector = { + # Corresponds to -l labelkey1=value1 + labelkey1 = "value1" + } +} + + +output "mystack_diff" { + value = helmfile_release_set.mystack.diff_output +} + +output "mystack_apply" { + value = helmfile_release_set.mystack.apply_output +} +``` + +In the example above I am changing my working_directory, setting some environment variables that will be utilized by all my helmfiles. + +Stdout and stderr from Helmfile runs are available in the debug log files. + +Running `terraform plan` runs `helmfile diff`. + +It shows no changes if `helmfile diff` did not detect any changes: + +```console +helmfile_release_set.mystack: Refreshing state... [id=bnd30hkllhcvvgsrplo0] + +------------------------------------------------------------------------ + +No changes. Infrastructure is up-to-date. + +This means that Terraform did not detect any differences between your +configuration and real physical resources that exist. As a result, no +actions need to be performed. +``` + +`terraform plan` surfaces changes in the `diff_output` field if `helmfile diff` detected any changes: + +``` +helmfile_release_set.mystack: Refreshing state... [id=bnd30hkllhcvvgsrplo0] + +------------------------------------------------------------------------ + +An execution plan has been generated and is shown below. +Resource actions are indicated with the following symbols: + ~ update in-place + +Terraform will perform the following actions: + + # helmfile_release_set.mystack will be updated in-place + ~ resource "helmfile_release_set" "mystack" { + binary = "helmfile" + - diff_output = "Comparing release=myapp-foo, chart=sp/podinfo\n\x1b[33mdefault, myapp-foo-podinfo, Deployment (apps) has changed:\x1b[0m\n # Source: podinfo/templates/deployment.yaml\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: myapp-foo-podinfo\n labels:\n app: podinfo\n chart: podinfo-3.1.4\n release: myapp-foo\n heritage: Helm\n spec:\n replicas: 1\n strategy:\n type: RollingUpdate\n rollingUpdate:\n maxUnavailable: 1\n selector:\n matchLabels:\n app: podinfo\n release: myapp-foo\n template:\n metadata:\n labels:\n app: podinfo\n release: myapp-foo\n annotations:\n prometheus.io/scrape: \"true\"\n prometheus.io/port: \"9898\"\n spec:\n terminationGracePeriodSeconds: 30\n containers:\n - name: podinfo\n\x1b[31m- image: \"stefanprodan/podinfo:foobar2aa\"\x1b[0m\n\x1b[32m+ image: \"stefanprodan/podinfo:foobar2a\"\x1b[0m\n imagePullPolicy: IfNotPresent\n command:\n - ./podinfo\n - --port=9898\n - --port-metrics=9797\n - --grpc-port=9999\n - --grpc-service-name=podinfo\n - --level=info\n - --random-delay=false\n - --random-error=false\n env:\n - name: PODINFO_UI_COLOR\n value: cyan\n ports:\n - name: http\n containerPort: 9898\n protocol: TCP\n - name: http-metrics\n containerPort: 9797\n protocol: TCP\n - name: grpc\n containerPort: 9999\n protocol: TCP\n livenessProbe:\n exec:\n command:\n - podcli\n - check\n - http\n - localhost:9898/healthz\n initialDelaySeconds: 1\n timeoutSeconds: 5\n readinessProbe:\n exec:\n command:\n - podcli\n - check\n - http\n - localhost:9898/readyz\n initialDelaySeconds: 1\n timeoutSeconds: 5\n volumeMounts:\n - name: data\n mountPath: /data\n resources:\n limits: null\n requests:\n cpu: 1m\n memory: 16Mi\n volumes:\n - name: data\n emptyDir: {}\n\nin ./helmfile.yaml: failed processing release myapp-foo: helm3 exited with status 2:\n Error: identified at least one change, exiting with non-zero exit code (detailed-exitcode parameter enabled)\n Error: plugin \"diff\" exited with error\n" -> null + ~ dirty = true -> false + environment = "default" + environment_variables = { + "FOO" = "foo" + } + helm_binary = "helm3" + id = "bnd30hkllhcvvgsrplo0" + path = "./helmfile.yaml" + selector = { + "labelkey1" = "value1" + } + values = { + "name" = "myapp" + } + working_directory = "." + } + +Plan: 0 to add, 1 to change, 0 to destroy. +``` + +Running `terraform apply` runs `helmfile apply` to deploy your releases. + +The computed field `apply_output` is used to surface the output from Helmfile. You can use in the string interpolation to produce a useful Terraform output. + +In the example below, the output `mystack_apply` is generated from `apply_output` so that you can review what has actually changed on `helmfile apply`: + +```console +helmfile_release_set.mystack: Refreshing state... [id=bnd30hkllhcvvgsrplo0] + +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. + +Outputs: + +mystack_apply = Comparing release=myapp-foo, chart=sp/podinfo +******************** + + Release was not present in Helm. Diff will show entire contents as new. + +******************** +... + +mystack_diff = +``` + +`terraform apply` just succeeds without any effect when there's no change detected by `helmfile`: + +```console +helmfile_release_set.mystack: Refreshing state... [id=bnd30hkllhcvvgsrplo0] + +Apply complete! Resources: 0 added, 0 changed, 0 destroyed. + +Outputs: + +mystack_apply = +mystack_diff = +``` + +## Develop +If you wish to build this yourself, follow the instructions: + + cd terraform-provider-helmfile + go build diff --git a/examples/helmfile.yaml b/examples/helmfile.yaml new file mode 100644 index 0000000..4883ab1 --- /dev/null +++ b/examples/helmfile.yaml @@ -0,0 +1,5 @@ +releases: +- name: {{ .Values.name }}-{{ requiredEnv "FOO" }} + chart: sp/podinfo + labels: + labelkey1: value1 diff --git a/examples/temp.values.yaml b/examples/temp.values.yaml new file mode 100755 index 0000000..02806ec --- /dev/null +++ b/examples/temp.values.yaml @@ -0,0 +1 @@ +{"name":"myapp"} \ No newline at end of file diff --git a/examples/test.tf b/examples/test.tf new file mode 100644 index 0000000..47e2dc5 --- /dev/null +++ b/examples/test.tf @@ -0,0 +1,31 @@ +provider "helmfile" {} + +resource "helmfile_release_set" "mystack" { + path = "./helmfile.yaml" + + helm_binary = "helm3" + + working_directory = path.module + + environment = "default" + + environment_variables = { + FOO = "foo" + } + + values = { + name = "myapp" + } + + selector = { + labelkey1 = "value1" + } +} + +output "mystack_diff" { + value = helmfile_release_set.mystack.diff_output +} + +output "mystack_apply" { + value = helmfile_release_set.mystack.apply_output +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cb5e93b --- /dev/null +++ b/go.mod @@ -0,0 +1,13 @@ +module github.com/mumoshu/terraform-provider-helmfile + +go 1.12 + +require ( + github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 + github.com/hashicorp/terraform-plugin-sdk v1.0.0 + github.com/mitchellh/go-linereader v0.0.0-20190213213312-1b945b3263eb + github.com/posener/complete v1.2.1 + github.com/rs/xid v1.2.1 +) + +replace git.apache.org/thrift.git => github.com/apache/thrift v0.0.0-20180902110319-2566ecd5d999 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f3d2396 --- /dev/null +++ b/go.sum @@ -0,0 +1,315 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1 h1:lRi0CHyU+ytlvylOlFKKq0af6JncuyoRh1J+QJBqQx0= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8= +github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= +github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= +github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0= +github.com/apparentlymart/go-cidr v1.0.1 h1:NmIwLZ/KdsjIUlhf+/Np40atNXm/+lZ5txfTJ/SpF+U= +github.com/apparentlymart/go-cidr v1.0.1/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3 h1:ZSTrOEhiM5J5RFxEaFvMZVEAM1KvT1YzbEOwB2EAGjA= +github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM= +github.com/apparentlymart/go-textseg v1.0.0 h1:rRmlIsPEEhUTIKQb7T++Nz/A5Q6C9IuX2wFoYVvnCs0= +github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= +github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs= +github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +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.15.78/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM= +github.com/aws/aws-sdk-go v1.19.39 h1:pIez14zQWSd/TER2Scohm7aCEG2TgoyXSOX6srOKt6o= +github.com/aws/aws-sdk-go v1.19.39/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas= +github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4= +github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2mtRGSCPsat1kze3CUtvJN3/jTXlp29k= +github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= +github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5 h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/hashicorp/errwrap v0.0.0-20180715044906-d6c0cd880357/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-cleanhttp v0.5.0 h1:wvCrVc9TjDls6+YGAF2hAifE1E5U1+b4tH6KdvN3Gig= +github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM= +github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= +github.com/hashicorp/go-getter v1.4.0 h1:ENHNi8494porjD0ZhIrjlAHnveSFhY7hvOJrV/fsKkw= +github.com/hashicorp/go-getter v1.4.0/go.mod h1:7qxyCd8rBfcShwsvxgIguu4KbS3l8bUCwg2Umn7RjeY= +github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd/go.mod h1:9bjs9uLqI8l75knNv3lV1kA55veR+WUPSiKIWcQHudI= +github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI= +github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= +github.com/hashicorp/go-multierror v0.0.0-20180717150148-3d5d8f294aa0/go.mod h1:JMRHfdO9jKNzS/+BTlxCjKNQHg/jZAft8U7LloJvN7I= +github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE= +github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY= +github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo= +github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= +github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.1.0 h1:bPIoEKD27tNdebFGGxxYwcL4nepeY4j1QP23PFRGzg0= +github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.2.0 h1:3vNe/fWF5CBgRIguda1meWhsZHy3m8gCJ5wx+dIzX/E= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f h1:UdxlrJz4JOnY8W+DbLISwf2B8WXEolNRA8BGCwI9jws= +github.com/hashicorp/hcl v0.0.0-20170504190234-a4b07c25de5f/go.mod h1:oZtUIOe8dh44I2q6ScRibXws4Ajl+d+nod3AaR9vL5w= +github.com/hashicorp/hcl2 v0.0.0-20190821123243-0c888d1241f6 h1:JImQpEeUQ+0DPFMaWzLA0GdUNPaUlCXLpfiqkSZBUfc= +github.com/hashicorp/hcl2 v0.0.0-20190821123243-0c888d1241f6/go.mod h1:Cxv+IJLuBiEhQ7pBYGEuORa0nr4U994pE8mYLuFd7v0= +github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590 h1:2yzhWGdgQUWZUCNK+AoO35V+HTsgEmcM4J9IkArh7PI= +github.com/hashicorp/hil v0.0.0-20190212112733-ab17b08d6590/go.mod h1:n2TSygSNwsLJ76m8qFXTSc7beTb+auJxYdqrnoqwZWE= +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-config-inspect v0.0.0-20190821133035-82a99dc22ef4 h1:fTkL0YwjohGyN7AqsDhz6bwcGBpT+xBqi3Qhpw58Juw= +github.com/hashicorp/terraform-config-inspect v0.0.0-20190821133035-82a99dc22ef4/go.mod h1:JDmizlhaP5P0rYTTZB0reDMefAiJyfWPEtugV4in1oI= +github.com/hashicorp/terraform-plugin-sdk v1.0.0 h1:3AjuuV1LJKs1NlG+heUgqWN6/QCSx2kDhyS6K7F0fTw= +github.com/hashicorp/terraform-plugin-sdk v1.0.0/go.mod h1:NuwtLpEpPsFaKJPJNGtMcn9vlhe6Ofe+Y6NqXhJgV2M= +github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb h1:b5rjCoWHc7eqmAS4/qyk21ZsHyb6Mxv/jykxvNTkU4M= +github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ= +github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= +github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4= +github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= +github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs= +github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/mitchellh/cli v1.0.0 h1:iGBIsUe3+HZ/AD/Vd7DErOt5sU9fa8Uj7A2s1aggv1Y= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= +github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= +github.com/mitchellh/go-homedir v1.0.0 h1:vKb8ShqSby24Yrqr/yDYkuFz8d0WUjys40rvnGC8aR0= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-linereader v0.0.0-20190213213312-1b945b3263eb h1:GRiLv4rgyqjqzxbhJke65IYUf4NCOOvrPOJbV/sPxkM= +github.com/mitchellh/go-linereader v0.0.0-20190213213312-1b945b3263eb/go.mod h1:OaY7UOoTkkrX3wRwjpYRKafIkkyeD0UtweSHAWWiqQM= +github.com/mitchellh/go-testing-interface v0.0.0-20171004221916-a61a99592b77/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-testing-interface v1.0.0 h1:fzU/JVNcaqHQEcVFAKeR41fkiLdIPrefOvVG1VZ96U0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4= +github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/mitchellh/reflectwalk v1.0.1 h1:FVzMWA5RllMAKIdUSC8mdWo3XtwoecrH79BY70sEEpE= +github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= +github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI= +github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= +github.com/rs/xid v1.2.1 h1:mhH9Nq+C1fY2l1XIpgxIiUOfNpRBYH1kKcr+qfKgjRc= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= +github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= +github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc= +github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= +github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/ulikunitz/xz v0.5.5 h1:pFrO0lVpTBXLpYw+pnLj6TbvHuyjXMfjGeCwSqCVwok= +github.com/ulikunitz/xz v0.5.5/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= +github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= +github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/zclconf/go-cty v1.0.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= +github.com/zclconf/go-cty v1.1.0 h1:uJwc9HiBOCpoKIObTQaLR+tsEXx1HBHnOsOOpcdhZgw= +github.com/zclconf/go-cty v1.1.0/go.mod h1:xnAOWiHeOqg2nWS62VtQ7pbOu17FtxJNW8RLEih+O3s= +github.com/zclconf/go-cty-yaml v1.0.1 h1:up11wlgAaDvlAGENcFDnZgkn0qUJurso7k6EpURKNF8= +github.com/zclconf/go-cty-yaml v1.0.1/go.mod h1:IP3Ylp0wQpYm50IHK8OZWKMu6sPJIUgKa8XhiVHura0= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0 h1:C9hSCOW830chIVkdja34wa6Ky+IzWllkUinR+BtRZd4= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo= +golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180811021610-c39426892332/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-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190502183928-7f726cade0ab h1:9RfW3ktsOZxgo9YNbBAjq1FWzc/igwEcUzZz8IXgSbk= +golang.org/x/net v0.0.0-20190502183928-7f726cade0ab/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +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-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190129075346-302c3dd5f1cc/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-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82 h1:vsphBvatvfbhlb4PO1BYSr9dzugGxJ/SQHoNufZJq1w= +golang.org/x/sys v0.0.0-20190502175342-a43fa875dd82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0 h1:jbyannxz0XFD3zdjgrSUsaJbgpH4eTrkdhRChkHPfO8= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1 h1:j6XxA85m/6txkUCHvzlV5f+HBNl/1r5cZ2A/3IEFOO8= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/main.go b/main.go new file mode 100644 index 0000000..24e9016 --- /dev/null +++ b/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "github.com/hashicorp/terraform-plugin-sdk/plugin" + "github.com/mumoshu/terraform-provider-helmfile/pkg/tfhelmfile" +) + +func main() { + plugin.Serve(&plugin.ServeOpts{ + ProviderFunc: tfhelmfile.Provider}) +} diff --git a/pkg/tfhelmfile/config.go b/pkg/tfhelmfile/config.go new file mode 100644 index 0000000..08bad75 --- /dev/null +++ b/pkg/tfhelmfile/config.go @@ -0,0 +1,15 @@ +package tfhelmfile + +//Config is the config for the client. +type Config struct { +} + +//Client is the client itself. Since we already have access to the shell no real provisioning needs to be done +type Client struct { +} + +// Client configures and returns a fully initialized ShellClient +func (c *Config) Client() (interface{}, error) { + var client Client + return &client, nil +} diff --git a/pkg/tfhelmfile/provider.go b/pkg/tfhelmfile/provider.go new file mode 100644 index 0000000..8b31a08 --- /dev/null +++ b/pkg/tfhelmfile/provider.go @@ -0,0 +1,31 @@ +package tfhelmfile + +import ( + "github.com/hashicorp/terraform-plugin-sdk/helper/mutexkv" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +// Provider returns a terraform.ResourceProvider. +func Provider() terraform.ResourceProvider { + + // The actual provider + return &schema.Provider{ + Schema: map[string]*schema.Schema{}, + ResourcesMap: map[string]*schema.Resource{ + "helmfile_release_set": resourceShellHelmfileReleaseSet(), + }, + ConfigureFunc: providerConfigure, + } +} + +func providerConfigure(d *schema.ResourceData) (interface{}, error) { + config := Config{} + + return config.Client() +} + +// This is a global MutexKV for use within this plugin. +var helmfileMutexKV = mutexkv.NewMutexKV() + +const releaseSetMutexKey = "releaseSetMutexKey" diff --git a/pkg/tfhelmfile/provider_test.go b/pkg/tfhelmfile/provider_test.go new file mode 100644 index 0000000..aa81a56 --- /dev/null +++ b/pkg/tfhelmfile/provider_test.go @@ -0,0 +1,28 @@ +package tfhelmfile + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +var testAccProviders map[string]terraform.ResourceProvider +var testAccProvider *schema.Provider + +func init() { + testAccProvider = Provider().(*schema.Provider) + testAccProviders = map[string]terraform.ResourceProvider{ + "helmfile_release_set": testAccProvider, + } +} + +func TestProvider(t *testing.T) { + if err := Provider().(*schema.Provider).InternalValidate(); err != nil { + t.Fatalf("err: %s", err) + } +} + +func TestProvider_impl(t *testing.T) { + var _ terraform.ResourceProvider = Provider() +} diff --git a/pkg/tfhelmfile/resource_release_set.go b/pkg/tfhelmfile/resource_release_set.go new file mode 100644 index 0000000..7ef25a5 --- /dev/null +++ b/pkg/tfhelmfile/resource_release_set.go @@ -0,0 +1,325 @@ +package tfhelmfile + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "log" + "os" + "os/exec" + "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/rs/xid" +) + +const KeyValuesFiles = "values_files" +const KeyValues = "values" +const KeySelector = "selector" +const KeyEnvironmentVariables = "environment_variables" +const KeyWorkingDirectory = "working_directory" +const KeyPath = "path" +const KeyEnvironment = "environment" +const KeyBin = "binary" +const KeyHelmBin = "helm_binary" +const KeyDiffOutput = "diff_output" +const KeyApplyOutput = "apply_output" +const KeyDirty = "dirty" + +func resourceShellHelmfileReleaseSet() *schema.Resource { + return &schema.Resource{ + Create: resourceReleaseSetCreate, + Delete: resourceReleaseSetDelete, + Read: resourceReleaseSetRead, + Update: resourceReleaseSetUpdate, + Schema: map[string]*schema.Schema{ + KeyValuesFiles: { + Type: schema.TypeList, + Optional: true, + ForceNew: false, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + KeyValues: { + Type: schema.TypeMap, + Optional: true, + ForceNew: false, + }, + KeySelector: { + Type: schema.TypeMap, + Optional: true, + ForceNew: false, + }, + KeyEnvironmentVariables: { + Type: schema.TypeMap, + Optional: true, + Elem: schema.TypeString, + }, + KeyWorkingDirectory: { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Default: ".", + }, + KeyPath: { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Default: "helmfile.yaml", + }, + KeyBin: { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Default: "helmfile", + }, + KeyHelmBin: { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Default: "helm", + }, + KeyEnvironment: { + Type: schema.TypeString, + Optional: true, + ForceNew: false, + Default: "helm", + }, + KeyDiffOutput: { + Type: schema.TypeString, + Optional: true, + // So that we can set this in `read` to instruct `terraform plan` to show diff as being disappear on `terraform apply` + Computed: false, + }, + KeyApplyOutput: { + Type: schema.TypeString, + Computed: true, + }, + KeyDirty: { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + } +} + +//helpers to unwravel the recursive bits by adding a base condition +func resourceReleaseSetCreate(d *schema.ResourceData, meta interface{}) error { + return create(d, meta, []string{"create"}) +} + +func resourceReleaseSetRead(d *schema.ResourceData, meta interface{}) error { + return read(d, meta, []string{"read"}) +} + +func resourceReleaseSetUpdate(d *schema.ResourceData, meta interface{}) error { + return update(d, meta, []string{"update"}) +} + +func resourceReleaseSetDelete(d *schema.ResourceData, meta interface{}) error { + return delete(d, meta, []string{"delete"}) +} +type Fields struct { + Bin string + Values map[string]interface{} + ValuesFiles []interface{} + HelmBin string + Path string + DiffOutput string + ApplyOutput string + Environment string + Selector map[string]interface{} + EnvironmentVariables map[string]interface{} + WorkingDirectory string +} + +func MustRead(d *schema.ResourceData) *Fields { + f := Fields{} + f.Environment = d.Get(KeyEnvironment).(string) + f.Path = d.Get(KeyPath).(string) + f.DiffOutput = d.Get(KeyDiffOutput).(string) + f.ApplyOutput = d.Get(KeyApplyOutput).(string) + f.HelmBin = d.Get(KeyHelmBin).(string) + f.Selector = d.Get(KeySelector).(map[string]interface{}) + f.ValuesFiles = d.Get(KeyValuesFiles).([]interface{}) + f.Values = d.Get(KeyValues).(map[string]interface{}) + f.Bin = d.Get(KeyBin).(string) + f.WorkingDirectory = d.Get(KeyWorkingDirectory).(string) + f.EnvironmentVariables = d.Get(KeyEnvironmentVariables).(map[string]interface{}) + return &f +} + +func SetDiffOutput(d *schema.ResourceData, v string) { + d.Set(KeyDiffOutput, v) +} + +func SetApplyOutput(d *schema.ResourceData, v string) { + d.Set(KeyApplyOutput, v) +} + +func GenerateCommand(fs *Fields, additionals ...string) (*exec.Cmd, error) { + args := []string{ + "--environment", fs.Environment, + "--file", fs.Path, + "--helm-binary", fs.HelmBin, + } + for k, v := range fs.Selector { + args = append(args, "--selector", fmt.Sprintf("%s=%s", k, v)) + } + for _, f := range fs.ValuesFiles { + args = append(args, "--state-values-file", fmt.Sprintf("%v", f)) + } + if len(fs.Values) > 0 { + js, err := json.Marshal(fs.Values) + if err != nil { + return nil, err + } + tmpf := "temp.values.yaml" + if err := ioutil.WriteFile(tmpf, js, 0700); err != nil { + return nil, err + } + args = append(args, "--state-values-file", tmpf) + } + cmd := exec.Command(fs.Bin, append(args, additionals...)...) + cmd.Dir = fs.WorkingDirectory + cmd.Env = append(os.Environ(), readEnvironmentVariables(fs.EnvironmentVariables)...) + return cmd, nil +} + +func create(d *schema.ResourceData, meta interface{}, stack []string) error { + log.Printf("[DEBUG] Creating release set resource...") + printStackTrace(stack) + fs := MustRead(d) + cmd, err := GenerateCommand(fs, "apply") + if err != nil { + return err + } + d.MarkNewResource() + //obtain exclusive lock + helmfileMutexKV.Lock(releaseSetMutexKey) + + state := NewState() + st, err := runCommand(cmd, state, false) + if err != nil { + return err + } + helmfileMutexKV.Unlock(releaseSetMutexKey) + + //// Assume we won't have any diff after successful apply + //SetDiffOutput(d, "") + + //create random uuid for the id + id := xid.New().String() + d.SetId(id) + + SetApplyOutput(d, st.Output) + SetDiffOutput(d, "") + + return nil +} + +func read(d *schema.ResourceData, meta interface{}, stack []string) error { + log.Printf("[DEBUG] Reading release set resource...") + printStackTrace(stack) + + fs := MustRead(d) + + cmd, err := GenerateCommand(fs, "diff", "--detailed-exitcode") + if err != nil { + return err + } + + //obtain exclusive lock + helmfileMutexKV.Lock(releaseSetMutexKey) + + state := NewState() + newState, err := runCommand(cmd, state, true) + if err != nil { + return err + } + output := newState.Output + + helmfileMutexKV.Unlock(releaseSetMutexKey) + if newState == nil { + log.Printf("[DEBUG] State from read operation was nil. Marking resource for deletion.") + d.SetId("") + return nil + } + log.Printf("[DEBUG] output:|%v|", output) + log.Printf("[DEBUG] new output:|%v|", newState.Output) + + SetDiffOutput(d, output) + SetApplyOutput(d, "") + + isStateEqual := reflect.DeepEqual(fs.DiffOutput, newState.Output) + isNewResource := d.IsNewResource() + isUpdatedResource := stack[0] == "update" + if !isStateEqual && !isNewResource && !isUpdatedResource { + log.Printf("[DEBUG] Previous state not equal to new state. Marking resource as dirty to trigger update.") + d.Set(KeyDirty, true) + return nil + } + + return nil +} + +func update(d *schema.ResourceData, meta interface{}, stack []string) error { + log.Printf("[DEBUG] Updating release set resource...") + d.Set(KeyDirty, false) + printStackTrace(stack) + fs := MustRead(d) + cmd, err := GenerateCommand(fs, "apply") + if err != nil { + return err + } + + //obtain exclusive lock + helmfileMutexKV.Lock(releaseSetMutexKey) + + state := NewState() + st, err := runCommand(cmd, state, false) + if err != nil { + return err + } + + SetApplyOutput(d, st.Output) + + helmfileMutexKV.Unlock(releaseSetMutexKey) + + if err := read(d, meta, stack); err != nil { + return err + } + + SetDiffOutput(d, "") + SetApplyOutput(d, st.Output) + + return nil +} + +func delete(d *schema.ResourceData, meta interface{}, stack []string) error { + log.Printf("[DEBUG] Deleting release set resource...") + printStackTrace(stack) + fs := MustRead(d) + cmd, err := GenerateCommand(fs, "destroy") + if err != nil { + return err + } + + //obtain exclusive lock + helmfileMutexKV.Lock(releaseSetMutexKey) + defer helmfileMutexKV.Unlock(releaseSetMutexKey) + + state := NewState() + _, err = runCommand(cmd, state, false) + if err != nil { + return err + } + + SetDiffOutput(d, "") + + d.SetId("") + + return nil +} diff --git a/pkg/tfhelmfile/resource_release_set_test.go b/pkg/tfhelmfile/resource_release_set_test.go new file mode 100644 index 0000000..1eacc2b --- /dev/null +++ b/pkg/tfhelmfile/resource_release_set_test.go @@ -0,0 +1,195 @@ +package tfhelmfile + +import ( + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" +) + +func TestAccHelmfileReleaseSet_basic(t *testing.T) { + resourceName := "shell_script.basic" + rString := acctest.RandString(8) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckShellScriptDestroy, + Steps: []resource.TestStep{ + { + Config: testAccShellScriptConfig_basic(rString), + + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "output.%", "1"), + resource.TestCheckResourceAttr(resourceName, "output.out1", rString), + resource.TestCheckResourceAttrSet(resourceName, "id"), + ), + }, + }, + }) +} + +func TestAccHelmfileReleaseSet_create_read_delete(t *testing.T) { + resourceName := "shell_script.crd" + rString := acctest.RandString(8) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckShellScriptDestroy, + Steps: []resource.TestStep{ + { + Config: testAccShellScriptConfig_create_read_delete(rString), + + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "output.%", "1"), + resource.TestCheckResourceAttr(resourceName, "output.out1", rString), + resource.TestCheckResourceAttrSet(resourceName, "id"), + ), + }, + }, + }) +} + +func TestAccHelmfileReleaseSet_create_update_delete(t *testing.T) { + resourceName := "shell_script.cud" + rString := acctest.RandString(8) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckShellScriptDestroy, + Steps: []resource.TestStep{ + { + Config: testAccShellScriptConfig_create_update_delete(rString), + + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "output.%", "1"), + resource.TestCheckResourceAttr(resourceName, "output.out1", rString), + resource.TestCheckResourceAttrSet(resourceName, "id"), + ), + }, + }, + }) +} + +func TestAccHelmfileReleaseSet_complete(t *testing.T) { + resourceName := "shell_script.complete" + rString := acctest.RandString(8) + resource.Test(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckShellScriptDestroy, + Steps: []resource.TestStep{ + { + Config: testAccShellScriptConfig_complete(rString), + + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "output.%", "2"), + resource.TestCheckResourceAttr(resourceName, "output.out1", rString), + resource.TestCheckResourceAttrSet(resourceName, "id"), + ), + }, + }, + }) +} + +func testAccCheckShellScriptDestroy(s *terraform.State) error { + for _, rs := range s.RootModule().Resources { + if rs.Type != "shell_script" { + continue + } + fileName := rs.Primary.Attributes["shell_script.test.environment.filename"] + if _, err := os.Stat(fileName); os.IsExist(err) { + return fmt.Errorf("Shell Script file failed to cleanup") + } + } + return nil +} + +func testAccShellScriptConfig_basic(outValue string) string { + return fmt.Sprintf(` + resource "shell_script" "basic" { + lifecycle_commands { + create = <> create_delete.json + cat create_delete.json >&3 +EOF + delete = "rm -rf create_delete.json" + } + + environment = { + filename= "create_delete.json" + } + } +`, outValue) +} + +func testAccShellScriptConfig_create_read_delete(outValue string) string { + return fmt.Sprintf(` + resource "shell_script" "crd" { + lifecycle_commands { + create = <> create_read_delete.json + cat create_read_delete.json >&3 +EOF + read = "cat create_read_delete.json >&3" + delete = "rm -rf create_read_delete.json" + } + + environment = { + filename= "create_read_delete.json" + } + } +`, outValue) +} + +func testAccShellScriptConfig_create_update_delete(outValue string) string { + return fmt.Sprintf(` + resource "shell_script" "cud" { + lifecycle_commands { + create = <> create_update_delete.json + cat create_update_delete.json >&3 +EOF + update = <> create_update_delete.json + cat create_update_delete.json >&3 +EOF + delete = "rm -rf create_update_delete.json" + } + + environment = { + filename= "create_update_delete.json" + } + } +`, outValue, outValue) +} + +func testAccShellScriptConfig_complete(outValue string) string { + return fmt.Sprintf(` + resource "shell_script" "complete" { + lifecycle_commands { + create = file("test-fixtures/scripts/create.sh") + read = file("test-fixtures/scripts/read.sh") + update = file("test-fixtures//scripts/update.sh") + delete = file("test-fixtures/scripts/delete.sh") + } + + environment = { + filename= "create_complete.json" + testdatasize = "10240" + out1 = "%s" + } + + triggers = { + key = "value" + } + } +`, outValue) +} diff --git a/pkg/tfhelmfile/utility.go b/pkg/tfhelmfile/utility.go new file mode 100644 index 0000000..bf20dde --- /dev/null +++ b/pkg/tfhelmfile/utility.go @@ -0,0 +1,137 @@ +package tfhelmfile + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "log" + "os" + "os/exec" + "syscall" + + "github.com/armon/circbuf" + "github.com/mitchellh/go-linereader" +) + +// State is a wrapper around both the input and output attributes that are relavent for updates +type State struct { + Output string +} + +// NewState is the constructor for State +func NewState() *State { + return &State{} +} + +func readEnvironmentVariables(ev map[string]interface{}) []string { + var variables []string + if ev != nil { + for k, v := range ev { + variables = append(variables, k+"="+v.(string)) + } + } + return variables +} + +func printStackTrace(stack []string) { + log.Printf("-------------------------") + log.Printf("[DEBUG] Current stack:") + for _, v := range stack { + log.Printf("[DEBUG] -- %s", v) + } + log.Printf("-------------------------") +} + +func parseJSON(b []byte) (map[string]string, error) { + tb := bytes.Trim(b, "\x00") + s := string(tb) + var f map[string]interface{} + err := json.Unmarshal([]byte(s), &f) + output := make(map[string]string) + for k, v := range f { + output[k] = v.(string) + } + return output, err +} + +type outputter struct{} + +func (o outputter) Output(_ string) { + +} + +func runCommand(cmd *exec.Cmd, state *State, diffMode bool) (*State, error) { + const maxBufSize = 8 * 1024 + // Setup the command + input, _ := json.Marshal(state.Output) + stdin := bytes.NewReader(input) + cmd.Stdin = stdin + pr, pw, err := os.Pipe() + if err != nil { + return nil, err + } + cmd.Stderr = pw + cmd.Stdout = pw + + output, _ := circbuf.NewBuffer(maxBufSize) + + // Write everything we read from the pipe to the output buffer too + tee := io.TeeReader(pr, output) + + // copy the teed output to the UI output + copyDoneCh := make(chan struct{}) + //o := ctx.Value(schema.ProvOutputKey).(terraform.UIOutput) + go copyOutput(outputter{}, tee, copyDoneCh) + + // Run the command to completion + runErr := cmd.Run() + + if err := pw.Close(); err != nil { + return nil, err + } + + select { + case <-copyDoneCh: + //case <-ctx.Done(): + } + + out := output.String() + log.Printf("[DEBUG] helmfile command output: \"%s\"", out) + var exitStatus int + if runErr != nil { + switch ee := runErr.(type) { + case *exec.ExitError: + // Propagate any non-zero exit status from the external command, rather than throwing it away, + // so that helmfile could return its own exit code accordingly + waitStatus := ee.Sys().(syscall.WaitStatus) + exitStatus = waitStatus.ExitStatus() + if exitStatus != 2 { + return nil, fmt.Errorf("%s: %v\n%s", cmd.Path, runErr, out) + } + default: + return nil, fmt.Errorf("%s: %v\n%s", cmd.Path, runErr, out) + } + } + + newState := NewState() + if diffMode && exitStatus == 0 { + newState.Output = "" + } else { + newState.Output = out + } + log.Printf("[DEBUG] helmfile command new state: \"%v\"", newState) + return newState, nil +} + +type Outputter interface { + Output(string) +} + +func copyOutput(o Outputter, r io.Reader, doneCh chan<- struct{}) { + defer close(doneCh) + lr := linereader.New(r) + for line := range lr.Ch { + o.Output(line) + } +}