diff --git a/.github/linters/.hadolint.yml b/.github/linters/.hadolint.yml new file mode 100644 index 00000000..b58d33fd --- /dev/null +++ b/.github/linters/.hadolint.yml @@ -0,0 +1,6 @@ +--- +########################## +## Hadolint config file ## +########################## +ignored: + - DL3018 \ No newline at end of file diff --git a/.github/workflows/chatops.yml b/.github/workflows/chatops.yml index 71293dd1..44b35b88 100644 --- a/.github/workflows/chatops.yml +++ b/.github/workflows/chatops.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: "Handle common commands" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.22.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }} @@ -24,7 +24,7 @@ jobs: - name: "Checkout commit" uses: actions/checkout@v2 - name: "Run tests" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.22.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/validate-codeowners.yml b/.github/workflows/validate-codeowners.yml new file mode 100644 index 00000000..0bc01d7e --- /dev/null +++ b/.github/workflows/validate-codeowners.yml @@ -0,0 +1,18 @@ +name: Validate Codeowners +on: + pull_request: + paths: + - '**/CODEOWNERS' + - '.github/workflows/validate-codeowners.yml' + +jobs: + validate-codeowners: + runs-on: ubuntu-latest + steps: + - name: "Checkout source code at current commit" + uses: actions/checkout@v2 + - uses: mszostok/codeowners-validator@v0.5.0 + with: + checks: "files,syntax,owners,duppatterns" + # GitHub access token is required only if the `owners` check is enabled + github_access_token: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}" diff --git a/Dockerfile b/Dockerfile index 35e900b9..e63898f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.14.4-alpine3.11 +FROM golang:1.15.6-alpine3.12 LABEL maintainer="Cloud Posse " LABEL "com.github.actions.name"="Build Harness" @@ -6,14 +6,14 @@ LABEL "com.github.actions.description"="Run any build-harness make target" LABEL "com.github.actions.icon"="tool" LABEL "com.github.actions.color"="blue" -RUN apk update && \ - apk --update add \ +RUN apk --update --no-cache add \ bash \ ca-certificates \ coreutils \ curl \ git \ gettext \ + go \ grep \ jq \ libc6-compat \ @@ -21,7 +21,8 @@ RUN apk update && \ py-pip && \ git config --global advice.detachedHead false -RUN curl -sSL https://apk.cloudposse.com/install.sh | bash +SHELL ["/bin/bash", "-o", "pipefail", "-c"] +RUN curl -fsSL --retry 3 https://apk.cloudposse.com/install.sh | bash ## Install as packages @@ -29,18 +30,30 @@ RUN curl -sSL https://apk.cloudposse.com/install.sh | bash ## So can not be curl binary RUN apk --update --no-cache add \ chamber@cloudposse \ + gomplate@cloudposse \ helm@cloudposse \ helmfile@cloudposse \ codefresh@cloudposse \ + terraform-0.11@cloudposse terraform-0.12@cloudposse terraform-0.13@cloudposse terraform-0.14@cloudposse \ + terraform-config-inspect@cloudposse \ + terraform-docs@cloudposse \ + vert@cloudposse \ yq@cloudposse && \ sed -i /PATH=/d /etc/profile -ADD ./ /build-harness/ +# Use Terraform 0.13 by default +ARG DEFAULT_TERRAFORM_VERSION=0.13 +RUN update-alternatives --set terraform /usr/share/terraform/$DEFAULT_TERRAFORM_VERSION/bin/terraform && \ + mkdir -p /build-harness/vendor && \ + cp -p /usr/share/terraform/$DEFAULT_TERRAFORM_VERSION/bin/terraform /build-harness/vendor/terraform + +COPY ./ /build-harness/ ENV INSTALL_PATH /usr/local/bin WORKDIR /build-harness +ARG PACKAGES_PREFER_HOST=true RUN make -s bash/lint make/lint RUN make -s template/deps aws/install terraform/install readme/deps RUN make -s go/deps-build go/deps-dev diff --git a/README.md b/README.md index 9eb24690..1b40e0dd 100644 --- a/README.md +++ b/README.md @@ -237,13 +237,14 @@ Available targets: slack/notify/deploy Send notification to slack using "deploy" template template/build Create $OUT file by building it from $IN template file template/deps Install dependencies + terraform/bump-tf-12-min-version Rewrite versions.tf to bump modules with minimum core version of '0.12.x' to '>= 0.12.26' terraform/get-modules Ensure all modules can be fetched terraform/get-plugins Ensure all plugins can be fetched terraform/install Install terraform terraform/lint Lint check Terraform - terraform/remove-upper-bound Rewrite versions.tf to remove upper bound for terraform core version constraint (like this ">= 0.12.0, < 0.14.0") - terraform/rewrite-module-source Rewrite the *.tf files to use registry notation for modules sources - terraform/upgrade-modules Upgrade all terraform module sources + terraform/loosen-constraints and convert "~>" constraints to ">=". + terraform/rewrite-required-providers Rewrite versions.tf to update existing configuration to add an explicit source attribute for each provider + terraform/upgrade-modules This target has not been upgraded to handle registry format terraform/validate Basic terraform sanity check travis/docker-login Login into docker hub travis/docker-tag-and-push Tag & Push according Travis environment variables diff --git a/docs/targets.md b/docs/targets.md index 8d368fbb..ffa0b810 100644 --- a/docs/targets.md +++ b/docs/targets.md @@ -114,13 +114,14 @@ Available targets: slack/notify/deploy Send notification to slack using "deploy" template template/build Create $OUT file by building it from $IN template file template/deps Install dependencies + terraform/bump-tf-12-min-version Rewrite versions.tf to bump modules with minimum core version of '0.12.x' to '>= 0.12.26' terraform/get-modules Ensure all modules can be fetched terraform/get-plugins Ensure all plugins can be fetched terraform/install Install terraform terraform/lint Lint check Terraform - terraform/remove-upper-bound Rewrite versions.tf to remove upper bound for terraform core version constraint (like this ">= 0.12.0, < 0.14.0") - terraform/rewrite-module-source Rewrite the *.tf files to use registry notation for modules sources - terraform/upgrade-modules Upgrade all terraform module sources + terraform/loosen-constraints and convert "~>" constraints to ">=". + terraform/rewrite-required-providers Rewrite versions.tf to update existing configuration to add an explicit source attribute for each provider + terraform/upgrade-modules This target has not been upgraded to handle registry format terraform/validate Basic terraform sanity check travis/docker-login Login into docker hub travis/docker-tag-and-push Tag & Push according Travis environment variables diff --git a/modules/github/Makefile.init b/modules/github/Makefile.init index 835f0e42..8a3db340 100644 --- a/modules/github/Makefile.init +++ b/modules/github/Makefile.init @@ -6,16 +6,33 @@ GITHUB_TEMPLATES = \ .github/ISSUE_TEMPLATE/bug_report.md \ .github/ISSUE_TEMPLATE/question.md \ .github/auto-release.yml \ - .github/workflows/auto-release.yml + .github/workflows/auto-release.yml \ + .github/workflows/validate-codeowners.yml + +# Install extra configuration for terraform projects +GITHUB_TERRAFORM_TEMPLATES = .github/workflows/chatops.yml \ + .github/workflows/auto-context.yml \ + .github/workflows/auto-readme.yml \ + .github/mergify.yml -ifneq ($(wildcard *.tf),) -# Install test workflow for terraform projects -GITHUB_TEMPLATES += .github/workflows/chatops.yml -endif $(GITHUB_TEMPLATES): $(addprefix $(BUILD_HARNESS_PATH)/templates/, $(GITHUB_TEMPLATES)) mkdir -p $(dir $@) cp $(BUILD_HARNESS_PATH)/templates/$@ $@ git ls-files --error-unmatch $@ 2>/dev/null || git add $@ -github/init: $(GITHUB_TEMPLATES) +$(GITHUB_TERRAFORM_TEMPLATES): $(addprefix $(BUILD_HARNESS_PATH)/templates/terraform/, $(GITHUB_TERRAFORM_TEMPLATES)) + mkdir -p $(dir $@) + cp $(BUILD_HARNESS_PATH)/templates/terraform/$@ $@ + git ls-files --error-unmatch $@ 2>/dev/null || git add $@ + +github/init/context.tf: + curl -o context.tf -fsSL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf + git ls-files --error-unmatch context.tf 2>/dev/null || git add context.tf + @if [[ -d examples/complete ]]; then \ + cp -p context.tf examples/complete/context.tf ; \ + fi + +.PHONY: $(GITHUB_TEMPLATES) $(GITHUB_TERRAFORM_TEMPLATES) github/init/context.tf + +github/init: $(GITHUB_TEMPLATES) $(if $(wildcard *.tf),$(GITHUB_TERRAFORM_TEMPLATES) github/init/context.tf) diff --git a/modules/packages/Makefile b/modules/packages/Makefile index fb8a2ce5..4cae84b6 100644 --- a/modules/packages/Makefile +++ b/modules/packages/Makefile @@ -1,6 +1,7 @@ export INSTALL_PATH ?= $(BUILD_HARNESS_PATH)/vendor export PACKAGES_VERSION ?= 0.133.0 export PACKAGES_PATH ?= $(BUILD_HARNESS_PATH)/vendor/packages +export PACKAGES_PREFER_HOST ?= false ## Delete packages packages/delete: @@ -13,18 +14,23 @@ packages/reinstall: packages/delete packages/install ## Install packages packages/install: @if [ ! -d $(PACKAGES_PATH) ]; then \ - echo "Installing packages $(PACKAGES_VERSION)..."; \ - rm -rf $(PACKAGES_PATH); \ - $(GIT) clone -c advice.detachedHead=false --depth=1 -b $(PACKAGES_VERSION) https://github.com/cloudposse/packages.git $(PACKAGES_PATH); \ - rm -rf $(PACKAGES_PATH)/.git; \ + echo "* Installing packages $(PACKAGES_VERSION)..."; \ + rm -rf $(PACKAGES_PATH); \ + $(GIT) clone -c advice.detachedHead=false --depth=1 -b $(PACKAGES_VERSION) https://github.com/cloudposse/packages.git $(PACKAGES_PATH); \ + rm -rf $(PACKAGES_PATH)/.git; \ fi ## Install package (e.g. helm, helmfile, kubectl) -packages/install/%: packages/install - @if [ ! -x $(INSTALL_PATH)/$(subst packages/install/,,$@) ]; then \ - $(MAKE) -C $(PACKAGES_PATH)/install $(subst packages/install/,,$@); \ +packages/install/%: + @binary="$*"; \ + if [[ -x "$(INSTALL_PATH)/$$binary" ]]; then \ + echo "* Package $$binary already installed"; \ + elif [[ "$(PACKAGES_PREFER_HOST)" == "true" ]] && installed=$$(command -v $* 2>/dev/null); then \ + echo Using "$*" from "$$installed" ; \ else \ - echo "Package $(subst packages/install/,,$@) already installed"; \ + $(MAKE) packages/install && \ + echo "* Installing $* to $(INSTALL_PATH)" && \ + $(MAKE) -C $(PACKAGES_PATH)/install "$*"; \ fi; ## Reinstall package (e.g. helm, helmfile, kubectl) diff --git a/modules/terraform/Makefile b/modules/terraform/Makefile index 1d34bc58..5c560b7f 100644 --- a/modules/terraform/Makefile +++ b/modules/terraform/Makefile @@ -41,17 +41,59 @@ else endif ## Upgrade all terraform module sources +## This target has not been upgraded to handle registry format terraform/upgrade-modules: - @$(BUILD_HARNESS_PATH)/bin/upgrade_terraform_modules.sh all + @echo "* $@ has been disabled because it has not been updated to handle Terraform registry syntax" + # @$(BUILD_HARNESS_PATH)/bin/upgrade_terraform_modules.sh all -## Rewrite the *.tf files to use registry notation for modules sources +# Rewrite the *.tf files to use registry notation for modules sources +terraform/rewrite-module-source: TERRAFORM = terraform-0.13 terraform/rewrite-module-source: - @sed -i -E 's,"git::https://github.com/(.*?)/terraform-([^-]*?)-(.*?).git\?ref=tags/(.*?)","\1/\3/\2"\n version = "\4",g' $$(find . -type f -name '*.tf') + @sed -i -E 's,\s*source\s+=\s+"git::https://github.com/([^/]+)/terraform-([^-]+)-(.+).git\?ref=(tags/)?([0-9.]+)", source = "\1/\3/\2"\n version = "\5",g' $$(find . -type f -not -name context.tf -name '*.tf') @$(TERRAFORM) fmt . @$(TERRAFORM) fmt examples/complete +terraform/rewrite-readme-source: TERRAFORM = terraform-0.13 +terraform/rewrite-readme-source: + @sed -i -E 's,^(\s*)source\s+=\s+"git::https://github.com/([^/]+)/terraform-([^-]+)-(.+).git\?ref=(tags/)?master",\1source = "\2/\4/\3"\n\1# Cloud Posse recommends pinning every module to a specific version\n\1# version = "x.x.x",g' README.yaml + ## Rewrite versions.tf to remove upper bound for terraform core version constraint (like this ">= 0.12.0, < 0.14.0") -terraform/remove-upper-bound: - @sed -i -E 's,required_version\s*\=\s*\"(.*?)(\,\s*<.*)",required_version = "\1",g' $$(find . -type f -name 'versions.tf') - @$(TERRAFORM) fmt . - @$(TERRAFORM) fmt examples/complete +## and convert "~>" constraints to ">=". +terraform/loosen-constraints: TERRAFORM = terraform-0.13 +terraform/loosen-constraints: + @for v in $$(find . -type f -name 'versions.tf'); do \ + DIR="$$(dirname $$v)"; \ + sed -i -E 's,\s\=\s*\"(.*[0-9.]+)(\,\s*<.*)", = "\1",g' "$$v" ; \ + sed -i -E 's,=\s*"\s*~>,= ">=,g' "$$v" ; \ + $(TERRAFORM) fmt "$$DIR" ; \ + done + +## Rewrite versions.tf to bump modules with minimum core version of '0.12.x' to '>= 0.12.26' +terraform/bump-tf-12-min-version: TERRAFORM = terraform-0.13 +terraform/bump-tf-12-min-version: terraform/loosen-constraints + @for v in $$(find . -type f -name 'versions.tf'); do \ + DIR="$$(dirname $$v)"; \ + PIN="$$(terraform-config-inspect --json "$$DIR" | jq -r '.required_core[]')" ; \ + if vert "$$PIN" 0.12.25 >/dev/null; then \ + echo updating "$$v" ; \ + sed -i -E 's,required_version\s*\=\s*\"(\~>|>\=)\s?(0\.12(\.\d+)?)\",required_version = ">= 0.12.26",g' "$$v" ; \ + $(TERRAFORM) fmt $$DIR ; \ + else \ + echo "$$v" already pinned to "$$PIN" ; \ + fi; \ + done + +## Rewrite versions.tf to update existing configuration to add an explicit source attribute for each provider +terraform/rewrite-required-providers: TERRAFORM = terraform-0.13 +terraform/rewrite-required-providers: terraform/loosen-constraints + @for v in $$(find . -type f -name 'versions.tf'); do \ + DIR="$$(dirname $$v)" ; \ + KEEP_VERSION=$$(grep -Eo 'required_version\s*=\s*"(.*)"' "$$v" | cut -d '"' -f2) ; \ + echo upgrading $$v ; \ + terraform-0.13 0.13upgrade -yes "$$DIR" >/dev/null ; \ + sed -i -E 's,(required_version\s*\=\s*\")(.*)(\"),\1'"$$KEEP_VERSION"'\3,g' "$$v" ; \ + done + +terraform/v14-rewrite: TERRAFORM = terraform-0.13 +terraform/v14-rewrite: terraform/loosen-constraints terraform/bump-tf-12-min-version terraform/rewrite-required-providers terraform/rewrite-module-source terraform/rewrite-readme-source + @git diff --no-patch --exit-code README.yaml || $(MAKE) readme diff --git a/templates/.github/CODEOWNERS b/templates/.github/CODEOWNERS index 07b38d2c..ceb46444 100644 --- a/templates/.github/CODEOWNERS +++ b/templates/.github/CODEOWNERS @@ -1,7 +1,7 @@ # Use this file to define individuals or teams that are responsible for code in a repository. # Read more: # -# Order is important: the last matching pattern takes the most precedence +# Order is important: the last matching pattern has the highest precedence # These owners will be the default owners for everything * @cloudposse/engineering @cloudposse/contributors @@ -13,5 +13,12 @@ # Cloud Posse must review any changes to GitHub actions .github/* @cloudposse/engineering -# Cloud Posse must review any changes to standard context definition -**/context.tf @cloudposse/engineering +# Cloud Posse must review any changes to standard context definition, +# but some changes can be rubber-stamped. +**/context.tf @cloudposse/engineering @cloudposse/approvers +README.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers +docs/*.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers + +# Cloud Posse Admins must review all changes to CODEOWNERS or the mergify configuration +.github/mergify.yml @cloudposse/admins +.github/CODEOWNERS @cloudposse/admins diff --git a/templates/.github/auto-release.yml b/templates/.github/auto-release.yml index 2836185f..18a1ca62 100644 --- a/templates/.github/auto-release.yml +++ b/templates/.github/auto-release.yml @@ -4,30 +4,35 @@ version-template: '$MAJOR.$MINOR.$PATCH' version-resolver: major: labels: - - 'major' + - 'major' minor: labels: - - 'minor' - - 'enhancement' + - 'minor' + - 'enhancement' patch: labels: - - 'patch' - - 'fix' - - 'bugfix' - - 'bug' - - 'hotfix' + - 'auto-update' + - 'patch' + - 'fix' + - 'bugfix' + - 'bug' + - 'hotfix' default: 'minor' categories: - - title: '🚀 Enhancements' - labels: - - 'enhancement' - - title: '🐛 Bug Fixes' - labels: - - 'fix' - - 'bugfix' - - 'bug' - - 'hotfix' +- title: '🚀 Enhancements' + labels: + - 'enhancement' + - 'patch' +- title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - 'hotfix' +- title: '🤖 Automatic Updates' + labels: + - 'auto-update' change-template: |
diff --git a/templates/.github/workflows/validate-codeowners.yml b/templates/.github/workflows/validate-codeowners.yml new file mode 100644 index 00000000..80442891 --- /dev/null +++ b/templates/.github/workflows/validate-codeowners.yml @@ -0,0 +1,18 @@ +name: Validate Codeowners +on: + pull_request: + +jobs: + validate-codeowners: + runs-on: ubuntu-latest + steps: + - name: "Checkout source code at current commit" + uses: actions/checkout@v2 + - uses: mszostok/codeowners-validator@v0.5.0 + with: + # For now, remove "files" check to allow CODEOWNERS to specify non-existent + # files so we can use the same CODEOWNERS file for Terraform and non-Terraform repos + # checks: "files,syntax,owners,duppatterns" + checks: "syntax,owners,duppatterns" + # GitHub access token is required only if the `owners` check is enabled + github_access_token: "${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}" diff --git a/templates/Makefile.build-harness b/templates/Makefile.build-harness index 5834360f..a38afd72 100644 --- a/templates/Makefile.build-harness +++ b/templates/Makefile.build-harness @@ -1,7 +1,14 @@ +# +# This is a shim installed automatically by the build-harness +# https://github.com/cloudposse/build-harness +# + export SHELL = /bin/bash export BUILD_HARNESS_ORG ?= cloudposse export BUILD_HARNESS_PROJECT ?= build-harness +export BUILD_HARNESS_DOCKER_IMAGE ?= $(BUILD_HARNESS_ORG)/$(BUILD_HARNESS_PROJECT) export BUILD_HARNESS_BRANCH ?= master +export BUILD_HARNESS_DOCKER_TAG ?= latest export BUILD_HARNESS_PATH ?= $(shell until [ -d "$(BUILD_HARNESS_PROJECT)" ] || [ "`pwd`" == '/' ]; do cd ..; done; pwd)/$(BUILD_HARNESS_PROJECT) -include $(BUILD_HARNESS_PATH)/Makefile @@ -15,5 +22,34 @@ init:: ## Clean build-harness clean:: @[ "$(BUILD_HARNESS_PATH)" == '/' ] || \ - [ "$(BUILD_HARNESS_PATH)" == '.' ] || \ - echo rm -rf $(BUILD_HARNESS_PATH) + [ "$(BUILD_HARNESS_PATH)" == '.' ] || \ + [ "$(BUILD_HARNESS_PATH)" == '/$(BUILD_HARNESS_PROJECT)' ] || \ + echo rm -rf $(BUILD_HARNESS_PATH) + +.PHONY: shell builder shell/pull builder/pull +shell/pull builder/pull: + @docker pull $(BUILD_HARNESS_DOCKER_IMAGE):$(BUILD_HARNESS_DOCKER_TAG) + @exit 0 + +DEFAULT_DOCKER_ENVS := AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN TERM AWS_PROFILE AWS_REGION \ + AWS_DEFAULT_PROFILE AWS_DEFAULT_REGION +EXTRA_DOCKER_ENVS ?= AWS_CONFIG_FILE AWS_SHARED_CREDENTIALS_FILE +MOUNT_HOME ?= $(shell [ -d "$$HOME" ] && printf -- "-e HOME -v \"%s\":\"%s\"" "$$HOME" "$$HOME") +DOCKER_ENVS ?= $(DEFAULT_DOCKER_ENVS) $(EXTRA_DOCKER_ENVS) + +## Start a shell inside of the `build-harness` docker container with `make shell` or `make builder` +## Run `make` targets inside the shell by setting `TARGETS`, e.g. +## make builder TARGETS="github/init readme" +ARGS := $(if $(TARGETS),$(TARGETS),-l) +ENTRYPOINT := $(if $(TARGETS),/usr/bin/make,/bin/bash) +shell builder: + $(info Starting $(BUILD_HARNESS_DOCKER_IMAGE):$(BUILD_HARNESS_DOCKER_TAG)) + docker run --name build-harness \ + --rm -it \ + -e PACKAGES_PREFER_HOST=true \ + $(addprefix -e ,$(DOCKER_ENVS)) \ + $(MOUNT_HOME) \ + -v $(CURDIR):/opt \ + --workdir /opt \ + --entrypoint $(ENTRYPOINT) \ + $(BUILD_HARNESS_DOCKER_IMAGE):$(BUILD_HARNESS_DOCKER_TAG) $(ARGS) diff --git a/templates/README.md.gotmpl b/templates/README.md.gotmpl index dd7a78cd..439fbeb2 100644 --- a/templates/README.md.gotmpl +++ b/templates/README.md.gotmpl @@ -89,8 +89,15 @@ We literally have [*hundreds of terraform modules*][terraform_modules] that are ## Usage {{ if (file.Exists "main.tf") }} -**IMPORTANT:** The `master` branch is used in `source` just as an example. In your code, do not pin to `master` because there may be breaking changes between releases. -Instead pin to the release tag (e.g. `?ref=tags/x.y.z`) of one of our [latest releases]({{ printf "https://github.com/%s/releases" (ds "config").github_repo}}). +**IMPORTANT:** We do not pin modules to versions in our examples because of the +difficulty of keeping the versions in the documentation in sync with the latest released versions. +We highly recommend that in your code you pin the version to the exact version you are +using so that your infrastructure remains stable, and update versions in a +systematic way so that they do not catch you by surprise. + +Also, because of a bug in the Terraform registry ([hashicorp/terraform#21417](https://github.com/hashicorp/terraform/issues/21417)), +the registry shows many of our inputs as required when in fact they are optional. +The table below correctly indicates which inputs are required. {{end}} {{ (ds "config").usage -}} diff --git a/templates/terraform/.github/mergify.yml b/templates/terraform/.github/mergify.yml new file mode 100644 index 00000000..485982ff --- /dev/null +++ b/templates/terraform/.github/mergify.yml @@ -0,0 +1,52 @@ +pull_request_rules: +- name: "approve automated PRs that have passed checks" + conditions: + - "check-success~=test/bats" + - "check-success~=test/readme" + - "check-success~=test/terratest" + - "base=master" + - "author=cloudpossebot" + - "head~=auto-update/.*" + actions: + review: + type: "APPROVE" + bot_account: "cloudposse-mergebot" + message: "We've automatically approved this PR because the checks from the automated Pull Request have passed." + +- name: "merge automated PRs when approved and tests pass" + conditions: + - "check-success~=test/bats" + - "check-success~=test/readme" + - "check-success~=test/terratest" + - "base=master" + - "head~=auto-update/.*" + - "#approved-reviews-by>=1" + - "#changes-requested-reviews-by=0" + - "#commented-reviews-by=0" + - "base=master" + - "author=cloudpossebot" + actions: + merge: + method: "squash" + +- name: "delete the head branch after merge" + conditions: + - "merged" + actions: + delete_head_branch: {} + +- name: "ask to resolve conflict" + conditions: + - "conflict" + actions: + comment: + message: "This pull request is now in conflict. Could you fix it @{{author}}? 🙏" + +- name: "remove outdated reviews" + conditions: + - "base=master" + actions: + dismiss_reviews: + changes_requested: true + approved: true + message: "This Pull Request has been updated, so we're dismissing all reviews." diff --git a/templates/terraform/.github/workflows/auto-context.yml b/templates/terraform/.github/workflows/auto-context.yml new file mode 100644 index 00000000..739a3c9e --- /dev/null +++ b/templates/terraform/.github/workflows/auto-context.yml @@ -0,0 +1,55 @@ +name: "auto-context" +on: + schedule: + # Update context.tf nightly + - cron: '0 3 * * *' + +jobs: + update: + if: github.event_name == 'schedule' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Update context.tf + shell: bash + id: update + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + run: | + if [[ -f context.tf ]]; then + echo "Discovered existing context.tf! Fetching most recent version to see if there is an update." + curl -o context.tf -fsSL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf + if git diff --no-patch --exit-code context.tf; then + echo "No changes detected! Exiting the job..." + else + echo "context.tf file has changed. Update examples and rebuild README.md." + make init + make github/init/context.tf + make readme/build + echo "::set-output name=create_pull_request=true" + fi + else + echo "This module has not yet been updated to support the context.tf pattern! Please update in order to support automatic updates." + fi + + - name: Create Pull Request + if: {{ steps.update.outputs.create_pull_request == 'true' }} + uses: cloudposse/actions/github/create-pull-request@0.22.0 + with: + token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} + commit-message: Update context.tf from origin source + title: Update context.tf + body: |- + ## what + This is an auto-generated PR that updates the `context.tf` file to the latest version from `cloudposse/terraform-null-label` + + ## why + To support all the features of the `context` interface. + + branch: auto-update/context.tf + base: master + delete-branch: true + labels: | + auto-update + context diff --git a/templates/terraform/.github/workflows/auto-readme.yml b/templates/terraform/.github/workflows/auto-readme.yml new file mode 100644 index 00000000..6229e606 --- /dev/null +++ b/templates/terraform/.github/workflows/auto-readme.yml @@ -0,0 +1,41 @@ +name: "auto-readme" +on: + schedule: + # Update README.md nightly + - cron: '0 4 * * *' + +jobs: + update: + if: github.event_name == 'schedule' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Update readme + shell: bash + id: update + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + run: | + make init + make readme/build + + - name: Create Pull Request + uses: cloudposse/actions/github/create-pull-request@0.20.0 + with: + token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} + commit-message: Update README.md and docs + title: Update README.md and docs + body: |- + ## what + This is an auto-generated PR that updates the README.md and docs + + ## why + To have most recent changes of README.md and doc from origin templates + + branch: auto-update/readme + base: master + delete-branch: true + labels: | + auto-update + readme diff --git a/templates/.github/workflows/chatops.yml b/templates/terraform/.github/workflows/chatops.yml similarity index 98% rename from templates/.github/workflows/chatops.yml rename to templates/terraform/.github/workflows/chatops.yml index 0d943109..4ddc0674 100644 --- a/templates/.github/workflows/chatops.yml +++ b/templates/terraform/.github/workflows/chatops.yml @@ -9,7 +9,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: "Handle common commands" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.22.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }} @@ -24,7 +24,7 @@ jobs: - name: "Checkout commit" uses: actions/checkout@v2 - name: "Run tests" - uses: cloudposse/actions/github/slash-command-dispatch@0.16.0 + uses: cloudposse/actions/github/slash-command-dispatch@0.22.0 with: token: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} reaction-token: ${{ secrets.GITHUB_TOKEN }}