Showing posts with label devops. Show all posts
Showing posts with label devops. Show all posts

Thursday, June 30, 2022

Terraform Azure Devops hosted pipelines

 In setting up my homelab using AZDO, I wanted to run some builds and steps using the Azure Hosted Agent. 

The documentation is a little unclear on this so I imported resources as follows. 

If codeblock output is clipped by css, don't worry, the code is there. Not working on that tonight as I have homelab to set up. 

For given TF code:

resource "azuredevops_agent_pool" "pipelinesagent" {
  name           = "Azure Pipelines"
  auto_provision = true
}

resource "azuredevops_agent_queue" "pipelinesqueue" {
  project_id    = azuredevops_project.project.id
  agent_pool_id = azuredevops_agent_pool.pipelinesagent.id
}

I found the azuredevops_agent_pool ID and the azuredevops_agent_queue ID as follows:

az pipelines queue list
// There were a lot of queues, but I am interested in the last in the output: 
// guids replaced with <guidhere>, get your own.
// 
[
{
    "id":  45,
    "name":  "Azure Pipelines",
    "pool":  {
                 "id":  9,
                 "isHosted":  true,
                 "isLegacy":  false,
                 "name":  "Azure Pipelines",
                 "options":  "none",
                 "poolType":  "automation",
                 "scope":  "<guidhere>",
                 "size":  1
             },
    "projectId":  "<guidhere>"
}
]

Now I can run my imports:

terraform import azuredevops_agent_pool.pipelinesagent 9
terraform import azuredevops_agent_queue.pipelinesqueue <guidhere>/45

And a `terraform apply` shows no changes needed.