File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22
3- set -e
4-
53# This is a clone of https://github.com/gruntwork-io/pre-commit/blob/master/hooks/terraform-validate.sh
64# It adds support for modules that use the Azure Resource Manager provider 2.0+.
75# This provider requires an explicit `features` block which in most cases is supplied by a super module.
@@ -15,19 +13,27 @@ function main() {
1513 fi
1614
1715 for dir in $( echo " $@ " | xargs -n1 dirname | sort -u | uniq) ; do
18- pushd " $dir " > /dev/null
19- if [ -n " $azurerm_provider_version " ]; then
20- cat << EOF > provider.tf
16+ local -r inline_provider_match=" $( grep ' provider "azurerm" {' " $dir /main.tf" ) "
17+ if [[ -z " $inline_provider_match " ]]; then
18+ continue
19+ fi
20+
21+ pushd " $dir " > /dev/null || exit 1
22+ if [ -n " $azurerm_provider_version " ]; then
23+ cat << EOF > provider.tf
2124provider "azurerm" {
2225 version = "$azurerm_provider_version "
2326 features {}
2427}
2528EOF
26- fi
27- terraform init -backend=false
28- terraform validate
29- rm provider.tf
30- popd > /dev/null
29+ fi
30+ terraform init -backend=false
31+ terraform validate
32+ local -r result=" $? "
33+ rm provider.tf
34+ # TODO: Make sure the provider.tf gets removed.
35+ popd > /dev/null || exit 1
36+ exit " $result "
3137 done
3238}
3339
You can’t perform that action at this time.
0 commit comments