I am trying to automate the deployment of azure infrastructure using Terraform and Azure Devops and would appreciate some assistance
Im trying to create variables for the output shown below so i can use it in a pipeline.
output "appid_tfazsp" {
value = data.azuread_application.tfazsp.application_id
sensitive = true
}
output "pass_tfazsp" {
value = azuread_application_password.tfazsp.value
sensitive = true
}
output "stg_SASPass" {
value = data.azurerm_storage_account.stg.primary_access_key
sensitive = true
}
Pipeline
trigger:
branches:
include:
- main
paths:
include:
- /TF/variables.tf
- /TF/main.tf
pool:
vmImage: "ubuntu-latest"
variables:
- group: hawaVB
steps:
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-installer-task.TerraformInstaller@0
displayName: 'Install Terraform'
- script: terraform version
displayName: Terraform Version
- script: terraform init
displayName: "Terraform Init"
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=storage_account_SASPass;isOutput=true]$(terraform output -raw outputvar)"
echo "##vso[task.setvariable variable=pass_tfazsp;isOutput=true]$(terraform output -raw outputvar)"
echo "##vso[task.setvariable variable=appid_tfazsp;isOutput=true]$(terraform output -raw outputvar)"
workingDirectory: $(System.DefaultWorkingDirectory)/TF
- script: az login --service-principal -u $(appid_tfazsp) -p $(pass_tfazsp) --tenant $(tenant_id)
displayName: 'Log Into Azure'
- script: terraform init -backend-config=resource_group_name=$(rg_name) -backend-config="storage_account_name=$(storageAccount_name)" -backend-config="container_name=$(cont_name)" -backend-config="access_key=$(storage_account_SASPass)" -backend-config="key=$(state_file)"
displayName: "Terraform Init"
workingDirectory: $(System.DefaultWorkingDirectory)/TF
- script: terraform plan -var=$(appid_tfazsp) -var="$(pass_tfazsp)" -var="tenant_id=$(tenant_id)" -var="subscription_id=$(subscription_id)" -var=$(VMAdminPass) -out="out.plan"
displayName: Terraform Plan
workingDirectory: $(System.DefaultWorkingDirectory)/TF
- script: terraform apply out.plan
displayName: 'Terraform Apply'
workingDirectory: $(System.DefaultWorkingDirectory)/TF
Error
Warning: No outputs found
│
│ The state file either has no outputs defined, or all the defined outputs
│ are empty. Please define an output in your configuration with the `output`
│ keyword and run `terraform refresh` for it to become available. If you are
│ using interpolation, please verify the interpolated value is not empty. You
│ can use the `terraform console` command to assist.