File tree Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Expand file tree Collapse file tree 3 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 29
29
# IDE
30
30
.idea /
31
31
32
+ /assets /terraform /examples /** /provider.tf
33
+ /assets /terraform /examples /provider.tf.template
34
+
32
35
# Local semantic-release configuration if you create one for testing
33
36
release.config.local.js
34
37
release.config.local.json
Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ $(GENERATED_OUT_PATH)/%: assets/%
28
28
@mkdir -p $(@D )
29
29
cp $< $@
30
30
31
+ .PHONY : install
32
+ install : codegen
33
+ cd $(GENERATED_OUT_PATH ) /terraform/ && go install
34
+
35
+ .PHONY : examples
36
+ examples : install
37
+ TF_CLI_CONFIG_FILE= ./scripts/validate-terraform-examples.sh
38
+
31
39
.PHONY : test
32
40
test : test/codegen test/pango test/terraform
33
41
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+
3
+ set -e
4
+
5
+ # This script validates all terraform examples.
6
+ # It should be run from the root of the repository.
7
+
8
+ cd assets/terraform/examples
9
+
10
+ # Create provider configuration template
11
+ cat << EOF > provider.tf.template
12
+ terraform {
13
+ required_providers {
14
+ panos = {
15
+ source = "PaloAltoNetworks/panos"
16
+ version = "1.0.0"
17
+ }
18
+ }
19
+ }
20
+
21
+ provider "panos" {
22
+ alias = "ci"
23
+ }
24
+ EOF
25
+
26
+ # Find all directories containing .tf files
27
+ DIRS=$( find . -type f -name " *.tf" -exec dirname {} \; | grep -v " ./provider" | sort -u)
28
+
29
+ # Loop through each directory and validate
30
+ for dir in $DIRS ; do
31
+
32
+ # Copy provider configuration for validation
33
+ cp provider.tf.template " $dir /provider.tf"
34
+
35
+ echo " Validating configurations in: $dir "
36
+ (
37
+ cd " $dir "
38
+
39
+ # Initialize and validate
40
+ [[ $CI == " true" ]] && terraform init -no-color
41
+ OUTPUT=$( terraform validate -no-color)
42
+ if [ $? -ne 0 ]; then
43
+ echo " Vailed to validate examples: $dir "
44
+ echo " ${OUTPUT} "
45
+ exit 1
46
+ fi
47
+
48
+ # Clean up provider configuration
49
+ rm provider.tf
50
+ )
51
+ done
52
+
53
+ # Clean up template
54
+ rm provider.tf.template
55
+
56
+ echo " All examples validated successfully."
You can’t perform that action at this time.
0 commit comments