Jeff
Jeff

Reputation: 850

AzureDevOps+Terraform - create agent job and job tasks

We have an existing AzureDevOps CI/CD. For every project, we have to manually set it up and add the job agent tasks one by one for each project.

Now, we decided to use IaC to auto deploy it using Terraform (as we have been using it for other projects as well). But there isn't much of documentation available there yet aside from this. It does have information on how to provision the project itself, but not the pipelines and other stuffs there, kind of limited at the moment, or I may have just not been able to find the complete documentation of the resources available.

We are keen to use Terraform for automating the creation of our CI/CD infrastructure, I just can't create agent jobs and tasks.

Upvotes: 0

Views: 383

Answers (1)

Lachie White
Lachie White

Reputation: 1251

we ended up creating our own forked off of this last year, and added things that were missing, like service connections and things like that.

However, for the pipelines and such Azure DevOps is expecting you to use azure-pipelines.yml for the actual pipeline definition.

To have a build defined by Terraform and Azure something like this would work:

resource "azuredevops_build_definition" "build_definition" {
  project_id = azuredevops_project.project.id
  name       = "My Awesome Build Pipeline"
  path       = "\\"

  repository {
    repo_type   = "TfsGit"
    repo_name   = azuredevops_azure_git_repository.repository.name
    branch_name = azuredevops_azure_git_repository.repository.default_branch
    yml_path    = "path to your azure-pipelines.yaml file in the repo"
  }
}

So within the repo you are running the terraform from just have azure-pipeline.yaml describing the pipeline you wish to execute.

Damian Brady has a good blog on this from October 2 years ago: https://damianbrady.com.au/2018/10/10/what-yaml-do-i-need-for-azure-pipelines/

There is also a lot of documentation around the supported Azure DevOps YAML Schema: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema

Once comfortable with the basics you can start to look towards using templates if there are seemingly common patterns you find: https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#template-references

Hope this helps!

Upvotes: 1

Related Questions