Dagger
Search

terraform

Module Dagger pour exécuter Terraform dans un conteneur

Installation

dagger install dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9

Entrypoint

Return Type
Terraform !
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
func (m *MyModule) Example() *dagger.Terraform  {
	return dag.
			Terraform()
}
@function
def example() -> dagger.Terraform:
	return (
		dag.terraform()
	)
@func()
example(): Terraform {
	return dag
		.terraform()
}

Types

Terraform 🔗

variables() 🔗

Return Type
[Variable ! ] !
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 variables
func (m *MyModule) Example() []*dagger.TerraformVariable  {
	return dag.
			Terraform().
			Variables()
}
@function
def example() -> List[dagger.TerraformVariable]:
	return (
		dag.terraform()
		.variables()
	)
@func()
example(): TerraformVariable[] {
	return dag
		.terraform()
		.variables()
}

state() 🔗

Return Type
StateConfig !
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 state
func (m *MyModule) Example() *dagger.TerraformStateConfig  {
	return dag.
			Terraform().
			State()
}
@function
def example() -> dagger.TerraformStateConfig:
	return (
		dag.terraform()
		.state()
	)
@func()
example(): TerraformStateConfig {
	return dag
		.terraform()
		.state()
}

terraformVersion() 🔗

Return Type
String !
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 terraform-version
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Terraform().
			TerraformVersion(ctx)
}
@function
async def example() -> str:
	return await (
		dag.terraform()
		.terraform_version()
	)
@func()
async example(): Promise<string> {
	return dag
		.terraform()
		.terraformVersion()
}

withVariable() 🔗

WithVariable ajoute une variable (non-secrète) au module

Return Type
Terraform !
Arguments
NameTypeDefault ValueDescription
keyString !-No description provided
valueString !-No description provided
tfVarBoolean falseNo description provided
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 with-variable --key string --value string
func (m *MyModule) Example(key string, value string) *dagger.Terraform  {
	return dag.
			Terraform().
			WithVariable(key, value)
}
@function
def example(key: str, value: str) -> dagger.Terraform:
	return (
		dag.terraform()
		.with_variable(key, value)
	)
@func()
example(key: string, value: string): Terraform {
	return dag
		.terraform()
		.withVariable(key, value)
}

apply() 🔗

Apply applique les changements Terraform à l’infrastructure

Cette fonction exécute terraform init suivi de terraform apply. Les variables doivent être configurées au préalable via WithVariable().

Exemple:

dagger call \
  with-variable --key vsphere_user --value env:VSPHERE_USER --secret --tf-var \
  with-variable --key vsphere_password --value env:VSPHERE_PASSWORD --secret --tf-var \
  with-state --backend s3 --bucket my-state --key terraform.tfstate --region us-east-1 \
  apply --source ./terraform --auto-approve
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
autoApproveBoolean falseAppliquer automatiquement sans confirmation
applyArgs[String ! ] -Options supplémentaires pour terraform apply
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 apply --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Apply(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.apply(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.apply(source)
}

destroy() 🔗

Destroy détruit l’infrastructure gérée par Terraform

Cette fonction exécute terraform init suivi de terraform destroy. Les variables doivent être configurées au préalable via WithVariable().

Exemple:

dagger call \
  with-variable --key vsphere_user --value env:VSPHERE_USER --secret --tf-var \
  with-variable --key vsphere_password --value env:VSPHERE_PASSWORD --secret --tf-var \
  with-state --backend s3 --bucket my-state --key terraform.tfstate --region us-east-1 \
  destroy --source ./terraform --auto-approve
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
autoApproveBoolean falseDétruire automatiquement sans confirmation
destroyArgs[String ! ] -Options supplémentaires pour terraform destroy
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 destroy --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Destroy(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.destroy(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.destroy(source)
}

output() 🔗

Output récupère les outputs Terraform

Cette fonction exécute terraform init suivi de terraform output. Les outputs sont retournés au format JSON par défaut.

Exemple (tous les outputs):

dagger call \
  with-state --backend s3 --bucket my-state --key terraform.tfstate --region us-east-1 \
  output --source ./terraform

Exemple (output spécifique):

dagger call \
  with-state --backend s3 --bucket my-state --key terraform.tfstate --region us-east-1 \
  output --source ./terraform --output-name instance_ip
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
outputNameString -Nom d'un output spécifique (laisser vide pour tous)
asJsonBoolean trueFormat JSON
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 output --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Output(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.output(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.output(source)
}

withState() 🔗

WithState configure le backend Terraform pour la gestion de l’état Supporte plusieurs types de backends : s3, gcs, azurerm, local

Le fichier backend.tf est généré dynamiquement au moment de l’exécution

Exemple S3:

dagger call \
  with-state --backend s3 --bucket my-terraform-state --key myapp/terraform.tfstate --region us-east-1 \
  plan --source . --workdir terraform

Exemple GCS:

dagger call \
  with-state --backend gcs --bucket my-terraform-state --key myapp/terraform.tfstate \
  plan --source . --workdir terraform

Exemple Azure:

dagger call \
  with-state --backend azurerm --bucket mycontainer --key myapp.tfstate \
  plan --source . --workdir terraform

Exemple Local:

dagger call \
  with-state --backend local --key terraform.tfstate \
  plan --source . --workdir terraform
Return Type
Terraform !
Arguments
NameTypeDefault ValueDescription
backendString !-Type de backend (s3, gcs, azurerm, local)
bucketString -Nom du bucket/container (non utilisé pour local)
keyString -Chemin de la clé/fichier d'état
regionString -Région (utilisé pour S3)
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 with-state --backend string
func (m *MyModule) Example(backend string) *dagger.Terraform  {
	return dag.
			Terraform().
			WithState(backend)
}
@function
def example(backend: str) -> dagger.Terraform:
	return (
		dag.terraform()
		.with_state(backend)
	)
@func()
example(backend: string): Terraform {
	return dag
		.terraform()
		.withState(backend)
}

validate() 🔗

Validate valide la configuration Terraform

Cette fonction exécute terraform init suivi de terraform validate.

Exemple:

dagger call \
  validate --source ./terraform
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 validate --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Validate(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.validate(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.validate(source)
}

plan() 🔗

Plan génère et affiche un plan d’exécution Terraform

Cette fonction exécute terraform init suivi de terraform plan. Les variables doivent être configurées au préalable via WithVariable().

Exemple:

dagger call \
  with-variable --key vsphere_user --value env:VSPHERE_USER --secret --tf-var \
  with-variable --key vsphere_password --value env:VSPHERE_PASSWORD --secret --tf-var \
  with-variable --key vsphere_server --value vcenter.local --tf-var \
  with-state --backend s3 --bucket my-state --key terraform.tfstate --region us-east-1 \
  plan --source ./terraform
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
detailedExitcodeBoolean falseUtiliser -detailed-exitcode (0=no changes, 1=error, 2=changes)
planArgs[String ! ] -Options supplémentaires pour terraform plan
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 plan --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Plan(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.plan(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.plan(source)
}

withSecret() 🔗

WithSecret ajoute un secret au module

Return Type
Terraform !
Arguments
NameTypeDefault ValueDescription
keyString !-No description provided
valueSecret !-No description provided
tfVarBoolean falseNo description provided
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 with-secret --key string --value env:MYSECRET
func (m *MyModule) Example(key string, value *dagger.Secret) *dagger.Terraform  {
	return dag.
			Terraform().
			WithSecret(key, value)
}
@function
def example(key: str, value: dagger.Secret) -> dagger.Terraform:
	return (
		dag.terraform()
		.with_secret(key, value)
	)
@func()
example(key: string, value: Secret): Terraform {
	return dag
		.terraform()
		.withSecret(key, value)
}

format() 🔗

Format formate les fichiers Terraform

Cette fonction exécute terraform fmt pour formater le code.

Exemple:

dagger call \
  format --source ./terraform
Return Type
String !
Arguments
NameTypeDefault ValueDescription
sourceDirectory !-Répertoire contenant le code Terraform
subpathString "."Sous-chemin relatif dans source (défaut: ".")
checkBoolean falseVérifier seulement si les fichiers sont formatés (sans modifier)
recursiveBoolean trueFormatter récursivement les sous-répertoires
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 format --source DIR_PATH
func (m *MyModule) Example(ctx context.Context, source *dagger.Directory) string  {
	return dag.
			Terraform().
			Format(ctx, source)
}
@function
async def example(source: dagger.Directory) -> str:
	return await (
		dag.terraform()
		.format(source)
	)
@func()
async example(source: Directory): Promise<string> {
	return dag
		.terraform()
		.format(source)
}

test() 🔗

Return Type
String !
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 test
func (m *MyModule) Example(ctx context.Context) string  {
	return dag.
			Terraform().
			Test(ctx)
}
@function
async def example() -> str:
	return await (
		dag.terraform()
		.test()
	)
@func()
async example(): Promise<string> {
	return dag
		.terraform()
		.test()
}

withTerraformVersion() 🔗

WithTerraformVersion configure la version de Terraform à utiliser

Par défaut, la version 1.9.8 est utilisée

Exemple:

dagger call \
  with-terraform-version --version 1.10.0 \
  plan --source . --workdir terraform
Return Type
Terraform !
Arguments
NameTypeDefault ValueDescription
versionString !-Version de Terraform (ex: "1.9.8", "1.10.0", "latest")
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
 with-terraform-version --version string
func (m *MyModule) Example(version string) *dagger.Terraform  {
	return dag.
			Terraform().
			WithTerraformVersion(version)
}
@function
def example(version: str) -> dagger.Terraform:
	return (
		dag.terraform()
		.with_terraform_version(version)
	)
@func()
example(version: string): Terraform {
	return dag
		.terraform()
		.withTerraformVersion(version)
}

Variable 🔗

key() 🔗

Return Type
String !
Example
Function TerraformVariable.key is not accessible from the terraform module
Function TerraformVariable.key is not accessible from the terraform module
Function TerraformVariable.key is not accessible from the terraform module
Function TerraformVariable.key is not accessible from the terraform module

value() 🔗

Return Type
String !
Example
Function TerraformVariable.value is not accessible from the terraform module
Function TerraformVariable.value is not accessible from the terraform module
Function TerraformVariable.value is not accessible from the terraform module
Function TerraformVariable.value is not accessible from the terraform module

secretValue() 🔗

Return Type
Secret !
Example
Function TerraformVariable.secretValue is not accessible from the terraform module
Function TerraformVariable.secretValue is not accessible from the terraform module
Function TerraformVariable.secretValue is not accessible from the terraform module
Function TerraformVariable.secretValue is not accessible from the terraform module

tfVar() 🔗

Return Type
Boolean !
Example
Function TerraformVariable.tfVar is not accessible from the terraform module
Function TerraformVariable.tfVar is not accessible from the terraform module
Function TerraformVariable.tfVar is not accessible from the terraform module
Function TerraformVariable.tfVar is not accessible from the terraform module

StateConfig 🔗

backend() 🔗

Return Type
String !
Example
Function TerraformStateConfig.backend is not accessible from the terraform module
Function TerraformStateConfig.backend is not accessible from the terraform module
Function TerraformStateConfig.backend is not accessible from the terraform module
Function TerraformStateConfig.backend is not accessible from the terraform module

bucket() 🔗

Return Type
String !
Example
Function TerraformStateConfig.bucket is not accessible from the terraform module
Function TerraformStateConfig.bucket is not accessible from the terraform module
Function TerraformStateConfig.bucket is not accessible from the terraform module
Function TerraformStateConfig.bucket is not accessible from the terraform module

key() 🔗

Return Type
String !
Example
Function TerraformStateConfig.key is not accessible from the terraform module
Function TerraformStateConfig.key is not accessible from the terraform module
Function TerraformStateConfig.key is not accessible from the terraform module
Function TerraformStateConfig.key is not accessible from the terraform module

region() 🔗

Return Type
String !
Example
Function TerraformStateConfig.region is not accessible from the terraform module
Function TerraformStateConfig.region is not accessible from the terraform module
Function TerraformStateConfig.region is not accessible from the terraform module
Function TerraformStateConfig.region is not accessible from the terraform module