@@ -24,6 +24,13 @@ function parseInputs {
2424 exit 1
2525 fi
2626
27+ if [ " ${INPUT_TG_ACTIONS_VERSION} " != " " ]; then
28+ tgVersion=${INPUT_TG_ACTIONS_VERSION}
29+ else
30+ echo " Input terragrunt_version cannot be empty"
31+ exit 1
32+ fi
33+
2734 if [ " ${INPUT_TF_ACTIONS_SUBCOMMAND} " != " " ]; then
2835 tfSubcommand=${INPUT_TF_ACTIONS_SUBCOMMAND}
2936 else
@@ -103,62 +110,94 @@ function installTerraform {
103110 echo " Successfully unzipped Terraform v${tfVersion} "
104111}
105112
113+ function installTerragrunt {
114+ if [[ " ${tgVersion} " == " latest" ]]; then
115+ echo " Checking the latest version of Terragrunt"
116+ latestURL=$( curl -Ls -o /dev/null -w %{url_effective} https://github.com/gruntwork-io/terragrunt/releases/latest)
117+ tgVersion=${latestURL##*/ }
118+
119+ if [[ -z " ${tgVersion} " ]]; then
120+ echo " Failed to fetch the latest version"
121+ exit 1
122+ fi
123+ fi
124+
125+ url=" https://github.com/gruntwork-io/terragrunt/releases/download/${tgVersion} /terragrunt_linux_386"
126+
127+ echo " Downloading Terragrunt ${tgVersion} "
128+ curl -s -S -L -o /tmp/terragrunt_${tgVersion} ${url}
129+ if [ " ${?} " -ne 0 ]; then
130+ echo " Failed to download Terragrunt v${tgVersion} "
131+ exit 1
132+ fi
133+ echo " Successfully downloaded Terragrunt v${tgVersion} "
134+
135+ echo " Unzipping Terragrunt v${tgVersion} "
136+ unzip -d /usr/local/bin /tmp/terragrunt_${tgVersion} & > /dev/null
137+ if [ " ${?} " -ne 0 ]; then
138+ echo " Failed to unzip Terragrunt ${tgVersion} "
139+ exit 1
140+ fi
141+ echo " Successfully unzipped Terragrunt ${tgVersion} "
142+ }
143+
106144function main {
107145 # Source the other files to gain access to their functions
108146 scriptDir=$( dirname ${0} )
109- source ${scriptDir} /terraform_fmt.sh
110- source ${scriptDir} /terraform_init.sh
111- source ${scriptDir} /terraform_validate.sh
112- source ${scriptDir} /terraform_plan.sh
113- source ${scriptDir} /terraform_apply.sh
114- source ${scriptDir} /terraform_output.sh
115- source ${scriptDir} /terraform_import.sh
116- source ${scriptDir} /terraform_taint.sh
117- source ${scriptDir} /terraform_destroy.sh
118-
147+ source ${scriptDir} /terragrunt_fmt.sh
148+ source ${scriptDir} /terragrunt_init.sh
149+ source ${scriptDir} /terragrunt_validate.sh
150+ source ${scriptDir} /terragrunt_plan.sh
151+ source ${scriptDir} /terragrunt_apply.sh
152+ source ${scriptDir} /terragrunt_output.sh
153+ source ${scriptDir} /terragrunt_import.sh
154+ source ${scriptDir} /terragrunt_taint.sh
155+ source ${scriptDir} /terragrunt_destroy.sh
156+
157+ installTerraform
119158 parseInputs
120159 configureCLICredentials
121160 cd ${GITHUB_WORKSPACE} /${tfWorkingDir}
122161
123162 case " ${tfSubcommand} " in
124163 fmt)
125- installTerraform
126- terraformFmt ${* }
164+ installTerragrunt
165+ terragruntFmt ${* }
127166 ;;
128167 init)
129- installTerraform
130- terraformInit ${* }
168+ installTerragrunt
169+ terragruntInit ${* }
131170 ;;
132171 validate)
133- installTerraform
134- terraformValidate ${* }
172+ installTerragrunt
173+ terragruntValidate ${* }
135174 ;;
136175 plan)
137- installTerraform
138- terraformPlan ${* }
176+ installTerragrunt
177+ terragruntPlan ${* }
139178 ;;
140179 apply)
141- installTerraform
142- terraformApply ${* }
180+ installTerragrunt
181+ terragruntApply ${* }
143182 ;;
144183 output)
145- installTerraform
146- terraformOutput ${* }
184+ installTerragrunt
185+ terragruntOutput ${* }
147186 ;;
148187 import)
149- installTerraform
150- terraformImport ${* }
188+ installTerragrunt
189+ terragruntImport ${* }
151190 ;;
152191 taint)
153- installTerraform
154- terraformTaint ${* }
192+ installTerragrunt
193+ terragruntTaint ${* }
155194 ;;
156195 destroy)
157- installTerraform
158- terraformDestroy ${* }
196+ installTerragrunt
197+ terragruntDestroy ${* }
159198 ;;
160199 * )
161- echo " Error: Must provide a valid value for terraform_subcommand "
200+ echo " Error: Must provide a valid value for terragrunt_subcommand "
162201 exit 1
163202 ;;
164203 esac
0 commit comments