diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 651f554f34..3c4952fc90 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -59,7 +59,6 @@ deploy: extends: .base stage: deploy script: - - terraform version - make -C terraform check_schema - make package - make auto_deploy diff --git a/src/azul/terraform.py b/src/azul/terraform.py index 51da71b74e..792cb7bb0c 100644 --- a/src/azul/terraform.py +++ b/src/azul/terraform.py @@ -2,6 +2,7 @@ chain, ) import json +import logging from pathlib import ( Path, ) @@ -32,6 +33,8 @@ JSONs, ) +log = logging.getLogger(__name__) + @attr.s(auto_attribs=True, kw_only=True, frozen=True) class TerraformSchema: @@ -70,7 +73,9 @@ def taggable_resource_types(self) -> Sequence[str]: def run(self, *args: str) -> str: terraform_dir = Path(config.project_root) / 'terraform' - cmd = subprocess.run(['terraform', *args], + args = ['terraform', *args] + log.info('Running %r', args) + cmd = subprocess.run(args, cwd=terraform_dir, check=True, stdout=subprocess.PIPE, @@ -102,7 +107,9 @@ def versions(self) -> Sequence[str]: # `terraform -version` prints a warning if you are not running the latest # release of Terraform; we discard it, otherwise, we would need to update # the tracked schema every time a new version of Terraform is released - versions, footer = self.run('-version').split('\n\n') + output = self.run('-version') + log.info('Terraform output:\n%s', output) + versions, footer = output.split('\n\n') return sorted(versions.splitlines()) diff --git a/terraform/Makefile b/terraform/Makefile index f362dae1e1..f84a0f1274 100644 --- a/terraform/Makefile +++ b/terraform/Makefile @@ -3,11 +3,15 @@ all: apply include ../common.mk +.PHONY: providers +providers: check_terraform check_branch check_aws providers.tf.json backend.tf.json + terraform init + .PHONY: config config: $(patsubst %.template.py,%,$(wildcard *.tf.json.template.py)) .PHONY: init -init: check_terraform check_branch check_aws config +init: providers config terraform init .PHONY: rename_resources @@ -70,7 +74,9 @@ update_schema: init python $(project_root)/scripts/terraform_schema.py update .PHONY: check_schema -check_schema: check_terraform +# Depend on init to ensure provider plugins are installed. Without it +# we wouldn't be able to check their versions against those in the schema. +check_schema: providers @if ! python $(project_root)/scripts/terraform_schema.py check; then \ echo -e "\nRun '$(MAKE) update_schema'.\n"; \ false; \