terraform
Module Dagger pour exécuter Terraform dans un conteneur
Installation
dagger install dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9Entrypoint
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 \
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() 🔗
Return Type
StateConfig ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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() 🔗
Return Type
String ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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()
}withVariable() 🔗
WithVariable ajoute une variable (non-secrète) au module
Return Type
Terraform !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| key | String ! | - | No description provided |
| value | String ! | - | No description provided |
| tfVar | Boolean | false | No description provided |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}withSecret() 🔗
WithSecret ajoute un secret au module
Return Type
Terraform !Arguments
| Name | Type | Default Value | Description |
|---|---|---|---|
| key | String ! | - | No description provided |
| value | Secret ! | - | No description provided |
| tfVar | Boolean | false | No description provided |
Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 call \
with-secret --key string --value env:MYSECRETfunc (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
| 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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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)
}test() 🔗
Return Type
String ! Example
dagger -m dev.azure.com/dordogne/DAGGER-TEMPLATES/_git/DAGGER-TEMPLATES/iac/terraform@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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()
}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@8df5d40cf6eadab4667c2d5ee4b7f68662fd8ab9 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 🔗
key() 🔗
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() 🔗
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 modulesecretValue() 🔗
Return Type
Secret ! Example
Function TerraformVariable.secretValue is not accessible from the terraform moduleFunction TerraformVariable.secretValue is not accessible from the terraform moduleFunction TerraformVariable.secretValue is not accessible from the terraform moduleFunction TerraformVariable.secretValue is not accessible from the terraform moduletfVar() 🔗
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 🔗
backend() 🔗
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() 🔗
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() 🔗
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() 🔗
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