Skip to content

Commit

Permalink
[fix] atlantis autoplan when modules change (#304)
Browse files Browse the repository at this point in the history
[fix] atlantis autoplan when modules changeThis configures auto-planning when anything in modules changes. In the future we may want to build a dependency graph between modules and components (including data dependencies), but for now the brute force approach will ensure that we don't miss changes.

### Test Plan
* CI
* ran on 1 internal repo

### References
* https://www.runatlantis.io/docs/repo-level-atlantis-yaml.html#configuring-autoplanning
  • Loading branch information
ryanking authored and czimergebot committed Jun 22, 2019
1 parent 801bb71 commit deb1e0e
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 72 deletions.
3 changes: 3 additions & 0 deletions templates/atlantis/atlantis.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ projects:
- name: {{ $project.Name }}
dir: {{ $project.Dir }}
workflow: fogg
autoplan:
when_modified: ["{{ .PathToRepoRoot }}terraform/modules/*/*.tf", "*.tf*"]
enabled: true
{{ end }}

workflows:
Expand Down
1 change: 1 addition & 0 deletions templates/repo/scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODE ?= local

ifeq ($(MODE),atlantis)
export AWS_CONFIG_FILE=$(REPO_ROOT)/config/atlantis-aws-config
TF_ARGS ?= -no-color
endif


Expand Down
18 changes: 9 additions & 9 deletions templates/repo/scripts/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check: lint check-plan

fmt: terraform
@printf "fmt: ";
@for f in $(TF); do printf .; $(terraform_command) fmt $$f; done
@for f in $(TF); do printf .; $(terraform_command) fmt $(TF_ARGS) $$f; done
@echo
.PHONY: fmt

Expand All @@ -34,24 +34,24 @@ endif
.PHONY: lint-tflint

terraform-validate: terraform init
@$(terraform_command) validate -check-variables=true
@$(terraform_command) validate $(TF_ARGS) -check-variables=true
.PHONY: terraform-validate

lint-terraform-fmt: terraform
@printf "fmt check: "
@for f in $(TF); do \
printf . \
$(terraform_command) fmt --check=true --diff=true $$f || exit $$? ; \
$(terraform_command) fmt $(TF_ARGS) --check=true --diff=true $$f || exit $$? ; \
done
@echo
.PHONY: lint-terraform-fmt

ifeq ($(MODE),local)
plan: init fmt
@$(terraform_command) plan
@$(terraform_command) plan $(TF_ARGS) -input=false
else ifeq ($(MODE),atlantis)
plan: init lint
@$(terraform_command) plan -input=false -no-color -out $(PLANFILE) | scenery
@$(terraform_command) plan $(TF_ARGS) -input=false -out $(PLANFILE) | scenery
else
@echo "Unknown MODE: $(MODE)"
@exit -1
Expand All @@ -66,10 +66,10 @@ ifneq ($(FORCE),1)
exit -1
endif
endif
@$(terraform_command) apply -auto-approve=$(AUTO_APPROVE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=$(AUTO_APPROVE)
else ifeq ($(MODE),atlantis)
apply:
@$(terraform_command) apply -auto-approve=true $(PLANFILE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=true $(PLANFILE)
else
echo "Unknown mode: $(MODE)"
exit -1
Expand All @@ -92,15 +92,15 @@ init: terraform
ifeq ($(MODE),local)
@$(terraform_command) init -input=false
else ifeq ($(MODE),atlantis)
@$(terraform_command) init -input=false -no-color
@$(terraform_command) init $(TF_ARGS) -input=false
else
@echo "Unknown MODE: $(MODE)"
@exit -1
endif
.PHONY: init

check-plan: init
@$(terraform_command) plan -detailed-exitcode; \
@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode; \
ERR=$$?; \
if [ $$ERR -eq 0 ] ; then \
echo "Success"; \
Expand Down
1 change: 1 addition & 0 deletions testdata/bless_provider/scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODE ?= local

ifeq ($(MODE),atlantis)
export AWS_CONFIG_FILE=$(REPO_ROOT)/config/atlantis-aws-config
TF_ARGS ?= -no-color
endif


Expand Down
18 changes: 9 additions & 9 deletions testdata/bless_provider/scripts/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check: lint check-plan

fmt: terraform
@printf "fmt: ";
@for f in $(TF); do printf .; $(terraform_command) fmt $$f; done
@for f in $(TF); do printf .; $(terraform_command) fmt $(TF_ARGS) $$f; done
@echo
.PHONY: fmt

Expand All @@ -34,24 +34,24 @@ endif
.PHONY: lint-tflint

terraform-validate: terraform init
@$(terraform_command) validate -check-variables=true
@$(terraform_command) validate $(TF_ARGS) -check-variables=true
.PHONY: terraform-validate

lint-terraform-fmt: terraform
@printf "fmt check: "
@for f in $(TF); do \
printf . \
$(terraform_command) fmt --check=true --diff=true $$f || exit $$? ; \
$(terraform_command) fmt $(TF_ARGS) --check=true --diff=true $$f || exit $$? ; \
done
@echo
.PHONY: lint-terraform-fmt

ifeq ($(MODE),local)
plan: init fmt
@$(terraform_command) plan
@$(terraform_command) plan $(TF_ARGS) -input=false
else ifeq ($(MODE),atlantis)
plan: init lint
@$(terraform_command) plan -input=false -no-color -out $(PLANFILE) | scenery
@$(terraform_command) plan $(TF_ARGS) -input=false -out $(PLANFILE) | scenery
else
@echo "Unknown MODE: $(MODE)"
@exit -1
Expand All @@ -66,10 +66,10 @@ ifneq ($(FORCE),1)
exit -1
endif
endif
@$(terraform_command) apply -auto-approve=$(AUTO_APPROVE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=$(AUTO_APPROVE)
else ifeq ($(MODE),atlantis)
apply:
@$(terraform_command) apply -auto-approve=true $(PLANFILE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=true $(PLANFILE)
else
echo "Unknown mode: $(MODE)"
exit -1
Expand All @@ -92,15 +92,15 @@ init: terraform
ifeq ($(MODE),local)
@$(terraform_command) init -input=false
else ifeq ($(MODE),atlantis)
@$(terraform_command) init -input=false -no-color
@$(terraform_command) init $(TF_ARGS) -input=false
else
@echo "Unknown MODE: $(MODE)"
@exit -1
endif
.PHONY: init

check-plan: init
@$(terraform_command) plan -detailed-exitcode; \
@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode; \
ERR=$$?; \
if [ $$ERR -eq 0 ] ; then \
echo "Success"; \
Expand Down
1 change: 1 addition & 0 deletions testdata/okta_provider/scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODE ?= local

ifeq ($(MODE),atlantis)
export AWS_CONFIG_FILE=$(REPO_ROOT)/config/atlantis-aws-config
TF_ARGS ?= -no-color
endif


Expand Down
18 changes: 9 additions & 9 deletions testdata/okta_provider/scripts/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check: lint check-plan

fmt: terraform
@printf "fmt: ";
@for f in $(TF); do printf .; $(terraform_command) fmt $$f; done
@for f in $(TF); do printf .; $(terraform_command) fmt $(TF_ARGS) $$f; done
@echo
.PHONY: fmt

Expand All @@ -34,24 +34,24 @@ endif
.PHONY: lint-tflint

terraform-validate: terraform init
@$(terraform_command) validate -check-variables=true
@$(terraform_command) validate $(TF_ARGS) -check-variables=true
.PHONY: terraform-validate

lint-terraform-fmt: terraform
@printf "fmt check: "
@for f in $(TF); do \
printf . \
$(terraform_command) fmt --check=true --diff=true $$f || exit $$? ; \
$(terraform_command) fmt $(TF_ARGS) --check=true --diff=true $$f || exit $$? ; \
done
@echo
.PHONY: lint-terraform-fmt

ifeq ($(MODE),local)
plan: init fmt
@$(terraform_command) plan
@$(terraform_command) plan $(TF_ARGS) -input=false
else ifeq ($(MODE),atlantis)
plan: init lint
@$(terraform_command) plan -input=false -no-color -out $(PLANFILE) | scenery
@$(terraform_command) plan $(TF_ARGS) -input=false -out $(PLANFILE) | scenery
else
@echo "Unknown MODE: $(MODE)"
@exit -1
Expand All @@ -66,10 +66,10 @@ ifneq ($(FORCE),1)
exit -1
endif
endif
@$(terraform_command) apply -auto-approve=$(AUTO_APPROVE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=$(AUTO_APPROVE)
else ifeq ($(MODE),atlantis)
apply:
@$(terraform_command) apply -auto-approve=true $(PLANFILE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=true $(PLANFILE)
else
echo "Unknown mode: $(MODE)"
exit -1
Expand All @@ -92,15 +92,15 @@ init: terraform
ifeq ($(MODE),local)
@$(terraform_command) init -input=false
else ifeq ($(MODE),atlantis)
@$(terraform_command) init -input=false -no-color
@$(terraform_command) init $(TF_ARGS) -input=false
else
@echo "Unknown MODE: $(MODE)"
@exit -1
endif
.PHONY: init

check-plan: init
@$(terraform_command) plan -detailed-exitcode; \
@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode; \
ERR=$$?; \
if [ $$ERR -eq 0 ] ; then \
echo "Success"; \
Expand Down
1 change: 1 addition & 0 deletions testdata/snowflake_provider/scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODE ?= local

ifeq ($(MODE),atlantis)
export AWS_CONFIG_FILE=$(REPO_ROOT)/config/atlantis-aws-config
TF_ARGS ?= -no-color
endif


Expand Down
18 changes: 9 additions & 9 deletions testdata/snowflake_provider/scripts/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check: lint check-plan

fmt: terraform
@printf "fmt: ";
@for f in $(TF); do printf .; $(terraform_command) fmt $$f; done
@for f in $(TF); do printf .; $(terraform_command) fmt $(TF_ARGS) $$f; done
@echo
.PHONY: fmt

Expand All @@ -34,24 +34,24 @@ endif
.PHONY: lint-tflint

terraform-validate: terraform init
@$(terraform_command) validate -check-variables=true
@$(terraform_command) validate $(TF_ARGS) -check-variables=true
.PHONY: terraform-validate

lint-terraform-fmt: terraform
@printf "fmt check: "
@for f in $(TF); do \
printf . \
$(terraform_command) fmt --check=true --diff=true $$f || exit $$? ; \
$(terraform_command) fmt $(TF_ARGS) --check=true --diff=true $$f || exit $$? ; \
done
@echo
.PHONY: lint-terraform-fmt

ifeq ($(MODE),local)
plan: init fmt
@$(terraform_command) plan
@$(terraform_command) plan $(TF_ARGS) -input=false
else ifeq ($(MODE),atlantis)
plan: init lint
@$(terraform_command) plan -input=false -no-color -out $(PLANFILE) | scenery
@$(terraform_command) plan $(TF_ARGS) -input=false -out $(PLANFILE) | scenery
else
@echo "Unknown MODE: $(MODE)"
@exit -1
Expand All @@ -66,10 +66,10 @@ ifneq ($(FORCE),1)
exit -1
endif
endif
@$(terraform_command) apply -auto-approve=$(AUTO_APPROVE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=$(AUTO_APPROVE)
else ifeq ($(MODE),atlantis)
apply:
@$(terraform_command) apply -auto-approve=true $(PLANFILE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=true $(PLANFILE)
else
echo "Unknown mode: $(MODE)"
exit -1
Expand All @@ -92,15 +92,15 @@ init: terraform
ifeq ($(MODE),local)
@$(terraform_command) init -input=false
else ifeq ($(MODE),atlantis)
@$(terraform_command) init -input=false -no-color
@$(terraform_command) init $(TF_ARGS) -input=false
else
@echo "Unknown MODE: $(MODE)"
@exit -1
endif
.PHONY: init

check-plan: init
@$(terraform_command) plan -detailed-exitcode; \
@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode; \
ERR=$$?; \
if [ $$ERR -eq 0 ] ; then \
echo "Success"; \
Expand Down
1 change: 1 addition & 0 deletions testdata/v1_full/scripts/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ MODE ?= local

ifeq ($(MODE),atlantis)
export AWS_CONFIG_FILE=$(REPO_ROOT)/config/atlantis-aws-config
TF_ARGS ?= -no-color
endif


Expand Down
18 changes: 9 additions & 9 deletions testdata/v1_full/scripts/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ check: lint check-plan

fmt: terraform
@printf "fmt: ";
@for f in $(TF); do printf .; $(terraform_command) fmt $$f; done
@for f in $(TF); do printf .; $(terraform_command) fmt $(TF_ARGS) $$f; done
@echo
.PHONY: fmt

Expand All @@ -34,24 +34,24 @@ endif
.PHONY: lint-tflint

terraform-validate: terraform init
@$(terraform_command) validate -check-variables=true
@$(terraform_command) validate $(TF_ARGS) -check-variables=true
.PHONY: terraform-validate

lint-terraform-fmt: terraform
@printf "fmt check: "
@for f in $(TF); do \
printf . \
$(terraform_command) fmt --check=true --diff=true $$f || exit $$? ; \
$(terraform_command) fmt $(TF_ARGS) --check=true --diff=true $$f || exit $$? ; \
done
@echo
.PHONY: lint-terraform-fmt

ifeq ($(MODE),local)
plan: init fmt
@$(terraform_command) plan
@$(terraform_command) plan $(TF_ARGS) -input=false
else ifeq ($(MODE),atlantis)
plan: init lint
@$(terraform_command) plan -input=false -no-color -out $(PLANFILE) | scenery
@$(terraform_command) plan $(TF_ARGS) -input=false -out $(PLANFILE) | scenery
else
@echo "Unknown MODE: $(MODE)"
@exit -1
Expand All @@ -66,10 +66,10 @@ ifneq ($(FORCE),1)
exit -1
endif
endif
@$(terraform_command) apply -auto-approve=$(AUTO_APPROVE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=$(AUTO_APPROVE)
else ifeq ($(MODE),atlantis)
apply:
@$(terraform_command) apply -auto-approve=true $(PLANFILE)
@$(terraform_command) apply $(TF_ARGS) -auto-approve=true $(PLANFILE)
else
echo "Unknown mode: $(MODE)"
exit -1
Expand All @@ -92,15 +92,15 @@ init: terraform
ifeq ($(MODE),local)
@$(terraform_command) init -input=false
else ifeq ($(MODE),atlantis)
@$(terraform_command) init -input=false -no-color
@$(terraform_command) init $(TF_ARGS) -input=false
else
@echo "Unknown MODE: $(MODE)"
@exit -1
endif
.PHONY: init

check-plan: init
@$(terraform_command) plan -detailed-exitcode; \
@$(terraform_command) plan $(TF_ARGS) -detailed-exitcode; \
ERR=$$?; \
if [ $$ERR -eq 0 ] ; then \
echo "Success"; \
Expand Down
Loading

0 comments on commit deb1e0e

Please sign in to comment.