Supports for executing Terraform command-line tools.
https://plugins.gradle.org/plugin/com.github.ayltai.terraform-plugin
Using the plugins DSL:
plugins {
id 'com.github.ayltai.terraform-plugin' version '0.2.13'
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'gradle.plugin.com.github.ayltai:terraform-plugin:0.2.13'
}
}
apply plugin: 'com.github.ayltai.terraform-plugin'
Using the plugins DSL:
plugins {
id('com.github.ayltai.terraform-plugin') version '0.2.13'
}
Using legacy plugin application:
buildscript {
repositories {
maven {
url = uri('https://plugins.gradle.org/m2/')
}
}
dependencies {
classpath('gradle.plugin.com.github.ayltai:terraform-plugin:0.2.13')
}
}
Example:
terraform {
toolVersion = '0.12.29'
backend = 'app.terraform.io'
apiToken = System.getenv('TERRAFORM_API_TOKEN')
workspace = 'main'
variables {
var 'access_key', System.getenv('TERRAFORM_ACCESS_KEY')
var 'secret key', System.getenv('TERRAFORM_SECRET_KEY')
}
}
HKVPN is a Terraform project that uses this plugin. Check build.gradle for a sample configuration, and README for usage instructions.
Task | Description |
---|---|
tfDownload |
Download and cache a copy of Terraform command-line tools |
tfFmt |
Rewrite Terraform source scripts to a canonical format and style |
tfInit |
Initialize Terraform source scripts |
tfValidate |
Validate the Terraform source scripts to verify whether they are syntactically valid and internally consistent |
tfPlan |
Create a Terraform execution plan |
tfApply |
Apply the changes required to reach the desired state of the configuration, or the pre-determined set of actions generated by an execution plan |
tfDestroy |
Destroy the Terraform-managed infrastructure |
tfWorkspaceList |
List all existing workspaces |
tfWorkspaceSelect |
Choose a different workspace to use for further |
tfWorkspaceNew |
Create a new workspace |
tfWorkspaceDelete |
Delete an existing workspace |
tfWorkspaceShow |
Output the current workspace |
Property | Type | Default | Description |
---|---|---|---|
backend |
String |
The endpoint of remote state | |
apiToken |
String |
The API token to authenticate with the remote state endpoint | |
toolVersion |
String |
The version of the Terraform command-line tools to be downloaded | |
forceDownload |
boolean |
false |
Terraform command-line tools will be re-downloaded even if they are already downloaded |
source |
String |
src/main/terraform |
The path to the Terraform source set |
configFile |
java.io.File |
The path to the Terraform configuration file | |
init |
See init | ||
fmt |
See fmt | ||
validate |
See validate | ||
plan |
See plan | ||
apply |
See apply | ||
destroy |
See destroy | ||
variables |
See variables | ||
workspace |
String |
default |
The name of the workspace to select, create or delete |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
input |
boolean |
true |
Asks for input if necessary |
lock |
boolean |
true |
Disables locking of state files during state-related operations |
lockTimeout |
int |
0 |
Overrides the time Terraform will wait to acquire a state lock |
useBackend |
boolean |
true |
Initializes a working directory for validation without accessing any configured remote backend |
upgrade |
boolean |
true |
Opts to upgrade modules and plugins as part of their respective installation steps |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
list |
boolean |
false |
Lists the files containing formatting inconsistencies |
write |
boolean |
false |
Overwrites the input files |
diff |
boolean |
false |
Displays diffs of formatting changes |
check |
boolean |
false |
Checks if the input is formatted |
recursive |
boolean |
false |
Processes files in subdirectories |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
json |
boolean |
false |
Produces output in a machine-readable JSON format, suitable for use in text editor integrations and other automated systems |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
input |
boolean |
true |
Asks for input if necessary |
lock |
boolean |
true |
Disables locking of state files during state-related operations |
lockTimeout |
int |
0 |
Overrides the time Terraform will wait to acquire a state lock |
compactWarnings |
boolean |
false |
If the warnings Terraform produces are not accompanied by errors, shows warning in a more compact form that includes only the summary messages |
parallelism |
int |
10 |
Limits the number of concurrent operation as Terraform walks the graph |
state |
String |
terraform.tfstate |
The path to the state file |
targets |
java.util.List |
Resource Addresses to target | |
destroy |
boolean |
false |
Generates a plan to destroy all the known resources |
detailedExitCode |
boolean |
false |
Returns a detailed exit code when the command exits |
out |
String |
The path to save the generated execution plan | |
refresh |
boolean |
true |
Updates the state prior to checking for differences |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
input |
boolean |
true |
Asks for input if necessary |
lock |
boolean |
true |
Disables locking of state files during state-related operations |
lockTimeout |
int |
0 |
Overrides the time Terraform will wait to acquire a state lock |
backup |
String |
The path to backup the existing state file | |
compactWarnings |
boolean |
false |
If the warnings Terraform produces are not accompanied by errors, shows warning in a more compact form that includes only the summary messages |
parallelism |
int |
10 |
Limits the number of concurrent operation as Terraform walks the graph |
state |
String |
terraform.tfstate |
The path to the state file |
targets |
java.util.List |
Resource Addresses to target | |
refresh |
boolean |
true |
Updates the state prior to checking for differences |
stateOut |
String |
The path to write updated state file | |
in |
String |
The path to the Terraform source scripts or an execution plan to apply |
Property | Type | Default | Description |
---|---|---|---|
noColor |
boolean |
false |
Disables color codes in the command output. |
input |
boolean |
true |
Asks for input if necessary |
lock |
boolean |
true |
Disables locking of state files during state-related operations |
lockTimeout |
int |
0 |
Overrides the time Terraform will wait to acquire a state lock |
backup |
String |
The path to backup the existing state file | |
compactWarnings |
boolean |
false |
If the warnings Terraform produces are not accompanied by errors, shows warning in a more compact form that includes only the summary messages |
parallelism |
int |
10 |
Limits the number of concurrent operation as Terraform walks the graph |
state |
String |
terraform.tfstate |
The path to the state file |
targets |
java.util.List |
Resource Addresses to target | |
refresh |
boolean |
true |
Updates the state prior to checking for differences |
stateOut |
String |
The path to write updated state file | |
in |
String |
The path to the Terraform source scripts to destroy |
Example:
variables {
var 'foo', 'bar'
var 'name', 'value'
file 'vars-file.tf'
}
See the official documentation for more details.