I am creating the pipeline in Azure DevOps with diffrent results and to diffrent errors I faced into.
I have several files in /test directory (main.tf, variables.tf and output.tf) which creates pubsub topic and subscription. I want Azure DevOps pipeline use to execute terraform init/plan and apply steps.
This is my configuration for main.tf (only part to which I have questions):
provider "google" {
project = var.project_id
region = "us-east1"
access_token = <<EOF
{
<content>
}
EOF
pipeline.yaml
variables:
projectName: sandbox
terraformConfigDirectory: '$(Build.SourcesDirectory)/test'
trigger:
branches:
include:
- test/pipeline
stages:
- stage: Start
displayName: 'Preparation to task execution'
jobs:
- job: BeginJob
displayName: Beginning'
steps:
- script: |
echo "Project Name: $(projectName)"
terraform version
- script: |
cd $(terraformConfigDirectory)
terraform init
-backend-config="bucket=$(projectName)-tf-state"
-backend-config="$(projectName)@test.iam.gserviceaccount.com"
-backend-config="prefix=$(System.DefaultWorkingDirectory)/test"
-backend-config="region= us-east1"
displayName: 'tfi'
- script: |
cd $(terraformConfigDirectory)
terraform plan
-compact-warnings -refresh=false -lock=false
-out=tfplan.out
displayName: 'tfp'
- script: |
cd $(terraformConfigDirectory)
terraform apply -auto-approve
displayName: 'tfa'
Questions:
- Now when I comment the
access_token
it fails ontfp
script with error:
Error: Attempted to load application default credentials since neither
credentials
noraccess_token
was set in the provider block. No credentials loaded. To use your gcloud credentials, run ‘gcloud auth application-default login’
However, when I use access_token
it fails on tfa
script with the error:
Error creating Topic: Put “https://pubsub.googleapis.com/v1/projects/sandbox/topics/pipeline-topic?alt=json”: net/http: invalid header field value for “Authorization”
1a. Anyway how to resolve it to have terraform plan working?
- I would like to see the output of terraform plan command in Terraform Plan section on Azure DevOps webpage. I found out that I should use
publishPlanResult
parameter however intask
block which I am not using in my code snippet. Is that some workaround to pass that parameter to my code?
I try to debuggining without the final effect of applying resources in GCP console.
Kreg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.