terraform
Ce module fournit des fonctions réutilisables pour gérer l'infrastructure avec Terraformde manière portable et reproductible.
Le module utilise un pattern immutable avec accumulation d'état :
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 . --workdir terraform
Installation
dagger install dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6baEntrypoint
Return Type
Terraform ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba 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 🔗
Terraform est le module principal
variables() 🔗
Variables accumulées
Return Type
[Variable ! ] ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
variablesfunc (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() 🔗
Configuration du backend
Return Type
StateConfig ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
statefunc (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() 🔗
Version de Terraform à utiliser
Return Type
String ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
terraform-versionfunc (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()
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
| autoApprove | Boolean | false | Dé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@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
destroy --source DIR_PATHfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
| autoApprove | Boolean | false | Appliquer 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@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
apply --source DIR_PATHfunc (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)
}withVariable() 🔗
WithVariable ajoute une variable au module Terraform Supporte les valeurs littérales et les préfixes Dagger (env://, file://, etc.)
Les préfixes sont gérés nativement par Dagger : - env:MY_VAR : Résout la variable d’environnement MY_VAR - file:/path/to/file : Lit le contenu du fichier - Valeur littérale : Utilisée telle quelle
Exemple:
dagger call \
with-variable --key proxmox_api_url --value env:PM_API_URL --secret --tf-var \
with-variable --key target_node --value pve-node-01 --tf-var \
plan --source . --workdir terraform
Return Type
Terraform !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| key | String ! | - | Nom de la variable |
| value | String ! | - | Valeur (supporte env:, file:, ou valeur littérale) |
| secret | Boolean | false | Marquer comme secret (injecté via WithSecretVariable) |
| tfVar | Boolean | false | Ajouter le préfixe TF_VAR_ (pour variables Terraform) |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
with-variable --key string --value stringfunc (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)
}test() 🔗
Test vérifie que le module est chargé correctement
Return Type
String ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
testfunc (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()
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
| check | Boolean | false | Vérifier seulement si les fichiers sont formatés (sans modifier) |
| recursive | Boolean | true | Formatter récursivement les sous-répertoires |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
format --source DIR_PATHfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
| detailedExitcode | Boolean | false | Utiliser -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@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
plan --source DIR_PATHfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
| outputName | String | - | Nom d'un output spécifique (laisser vide pour tous) |
| asJson | Boolean | true | Format JSON |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
output --source DIR_PATHfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| source | Directory ! | - | Répertoire contenant le code Terraform |
| subpath | String | "." | Sous-chemin relatif dans source (défaut: ".") |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
validate --source DIR_PATHfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| backend | String ! | - | Type de backend (s3, gcs, azurerm, local) |
| bucket | String | - | Nom du bucket/container (non utilisé pour local) |
| key | String | - | Chemin de la clé/fichier d'état |
| region | String | - | Région (utilisé pour S3) |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
with-state --backend stringfunc (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)
}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
| Name | Type | Default Value | Description |
|---|---|---|---|
| version | String ! | - | 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@e8a57c7760d532181a6c42cbdbb97c695527d6ba call \
with-terraform-version --version stringfunc (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 🔗
Variable représente une variable à injecter dans Terraform Supporte les valeurs littérales et les préfixes Dagger (env://, file://, etc.)
key() 🔗
Nom de la variable
Return Type
String ! Example
Function TerraformVariable.key is not accessible from the terraform moduleFunction TerraformVariable.key is not accessible from the terraform moduleFunction TerraformVariable.key is not accessible from the terraform moduleFunction TerraformVariable.key is not accessible from the terraform modulevalue() 🔗
Valeur (supporte env://, file://, etc.)
Return Type
String ! Example
Function TerraformVariable.value is not accessible from the terraform moduleFunction TerraformVariable.value is not accessible from the terraform moduleFunction TerraformVariable.value is not accessible from the terraform moduleFunction TerraformVariable.value is not accessible from the terraform moduleisSecret() 🔗
Si true, injecté comme secret
Return Type
Boolean ! Example
Function TerraformVariable.isSecret is not accessible from the terraform moduleFunction TerraformVariable.isSecret is not accessible from the terraform moduleFunction TerraformVariable.isSecret is not accessible from the terraform moduleFunction TerraformVariable.isSecret is not accessible from the terraform moduletfVar() 🔗
Si true, préfixe avec TFVAR
Return Type
Boolean ! Example
Function TerraformVariable.tfVar is not accessible from the terraform moduleFunction TerraformVariable.tfVar is not accessible from the terraform moduleFunction TerraformVariable.tfVar is not accessible from the terraform moduleFunction TerraformVariable.tfVar is not accessible from the terraform moduleStateConfig 🔗
StateConfig configure le backend Terraform
backend() 🔗
Type de backend (s3, gcs, azurerm, local)
Return Type
String ! Example
Function TerraformStateConfig.backend is not accessible from the terraform moduleFunction TerraformStateConfig.backend is not accessible from the terraform moduleFunction TerraformStateConfig.backend is not accessible from the terraform moduleFunction TerraformStateConfig.backend is not accessible from the terraform modulebucket() 🔗
Nom du bucket/container
Return Type
String ! Example
Function TerraformStateConfig.bucket is not accessible from the terraform moduleFunction TerraformStateConfig.bucket is not accessible from the terraform moduleFunction TerraformStateConfig.bucket is not accessible from the terraform moduleFunction TerraformStateConfig.bucket is not accessible from the terraform modulekey() 🔗
Chemin de la clé/fichier d’état
Return Type
String ! Example
Function TerraformStateConfig.key is not accessible from the terraform moduleFunction TerraformStateConfig.key is not accessible from the terraform moduleFunction TerraformStateConfig.key is not accessible from the terraform moduleFunction TerraformStateConfig.key is not accessible from the terraform moduleregion() 🔗
Région (pour S3)
Return Type
String ! Example
Function TerraformStateConfig.region is not accessible from the terraform moduleFunction TerraformStateConfig.region is not accessible from the terraform moduleFunction TerraformStateConfig.region is not accessible from the terraform moduleFunction TerraformStateConfig.region is not accessible from the terraform module