Skip to content

Commit

Permalink
Fix: TF schema check fails on Gitlab
Browse files Browse the repository at this point in the history
… because no providers are installed.
  • Loading branch information
hannes-ucsc committed Dec 11, 2020
1 parent dcdb286 commit 60ed45f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 0 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ deploy:
extends: .base
stage: deploy
script:
- terraform version
- make -C terraform check_schema
- make package
- make auto_deploy
Expand Down
11 changes: 9 additions & 2 deletions src/azul/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
chain,
)
import json
import logging
from pathlib import (
Path,
)
Expand Down Expand Up @@ -32,6 +33,8 @@
JSONs,
)

log = logging.getLogger(__name__)


@attr.s(auto_attribs=True, kw_only=True, frozen=True)
class TerraformSchema:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())


Expand Down
10 changes: 8 additions & 2 deletions terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; \
Expand Down

0 comments on commit 60ed45f

Please sign in to comment.