Terraform 0.13.5, azuredevsop provider 0.1.0
azuredevops_build_definitiondata "azuredevops_project" "project" {
name = "MyProject"
}
resource "azuredevops_build_definition" "build_infra" {
project_id = data.azuredevops_project.project.id
name = "infra-build"
ci_trigger {
use_yaml = true
}
pull_request_trigger {
use_yaml = true
forks {
enabled = false
share_secrets = false
}
}
repository {
repo_type = "Bitbucket"
service_connection_id = var.BitbucketConnectionID
repo_id = "MyOrg/MyRepo"
yml_path = "infra/azure-pipelines.yml"
}
variable {
name = "system.debug"
value = "false"
}
}
resource "azuredevops_build_definition" "build_code" {
project_id = data.azuredevops_project.project.id
name = "code-build"
ci_trigger {
use_yaml = true
}
pull_request_trigger {
use_yaml = true
forks {
enabled = false
share_secrets = false
}
}
repository {
repo_type = "Bitbucket"
service_connection_id = var.BitbucketConnectionID
repo_id = "MyOrg/MyRepo"
yml_path = "src/azure-pipelines.yml"
}
variable {
name = "system.debug"
value = "false"
}
}
infra folder triggers the infra-build pipeline triggers oncesrc folder triggers the code-build pipeline triggers onceinfra folder somehow triggers the infra-build build twicesrc folder somehow triggers the src-build build twiceCould not retrieve file content for /infra/azure-pipelines.yml from repository self hosted on Bitbucket using commit <Guid>. Bitbucket reported the error, "Too Many Requests"
terraform apply with the the sample code aboveinfra and src, with two different azure-pipelines.yml files inside, each one triggering the pipeline only when the corresponding infra or src folder changeinfra folder and pushsrc folder and pushIf I create the same build definitions "organically" using the Azure DevOps UI there's only one trigger as expected.
I started getting this behavior when I removed all my build definitions and recreated them from scratch with this provider.
The var.BitbucketConnectionID value is the guid corresponding to the Bitbucket Connection from the Azure DevOps portal
I tried removing the code-build definition, and keeping only the infra-build one, and I still got 4 triggered builds from one repo change. It's almost like the build definition subscribes 4 times to the Bitbucket webhook.
@oscarmorasu In your configuration, you set the configure: use_yaml = true which means the trigger is managed in your pipeline.xml, ADO provider cannot control the build triggers, you can find some configure example at: https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/bitbucket?view=azure-devops&tabs=yaml#ci-triggers
Thanks for the information @xuzhang3
So if I use a Bitbucket as the connection and use_yaml = true with multiple build definition is an invalid setup?
This is how I came up with that configuration:
terraform import on each build definitionterraform plan and look at the differencesuse_yaml = true flagterraform plan again and now there are no differencesI am still trying to understand why this setup works ok using the Web UI, but doesn't when using the ADO Provider
Hi @oscarmorasu Pipeline triggers can be set from UI or yaml configuration. Here you use use_yaml = true which means pipeline trigger is controlled by your pipeline.xml.
If you set user_yaml=false, an example UI configuration would look like:

I understand @xuzhang3
Now the issue I described originally happens when:
use_yaml = true in the TF module I think there's still a bug there
Now, for my use case I took a step back and realized that NOT setting use_yaml at all and manage the triggers in TF is actually better:
pipelines folder, with a TF module to setup the build definition(s). That's where the ci and pr triggers can be overridden if the default is not good enough.I think this is cleaner. Having the triggers defined in the .yml is odd to me.
hi @oscarmorasu Have you set different path filter for different pipeline.xml configure?
BTW, good job with the ADO provider @xuzhang3
It boils down to this:
resource "azuredevops_build_definition" "code_build" {
project_id = data.azuredevops_project.project.id
name = var.src_name
path = "\\${var.path}"
agent_pool_name = var.agent_pool_name
variable_groups = local.group_ids
ci_trigger {
override {
batch = false
branch_filter {
include = ["master"]
}
path_filter {
include = ["src"]
}
}
}
pull_request_trigger {
forks {
enabled = false
share_secrets = false
}
override {
auto_cancel = true
branch_filter {
include = ["master"]
}
path_filter {
include = ["src"]
}
}
}
}
resource "azuredevops_build_definition" "infra_build" {
project_id = data.azuredevops_project.project.id
name = var.infra_name
path = "\\${var.path}"
agent_pool_name = var.agent_pool_name
variable_groups = local.group_ids
ci_trigger {
override {
batch = false
branch_filter {
include = ["master"]
}
path_filter {
include = ["infra"]
}
}
}
pull_request_trigger {
forks {
enabled = false
share_secrets = false
}
override {
auto_cancel = true
branch_filter {
include = ["master"]
}
path_filter {
include = ["infra"]
}
}
}
}
Some more notes:
azuredevops_build_definition in a module and generate multiple definitions at the same time using TF count. I suggest adding a section in the documentation about mono-repos, where multiple build definitions map to the same repo, and the path_filter maps to different folders in the mono-repoagent_pool_name and variable_groups to be part of the TF module, which allows me to keep the azure-pipelines.yml much cleaner (DRY).@oscarmorasu Good suggestions, add example documents for different scenario 馃槃
Close this issue, feel free to reopen it if you have questions.
Most helpful comment
I understand @xuzhang3
Now the issue I described originally happens when:
use_yaml = truein the TF moduleI think there's still a bug there
Now, for my use case I took a step back and realized that NOT setting
use_yamlat all and manage the triggers in TF is actually better:pipelinesfolder, with a TF module to setup the build definition(s). That's where the ci and pr triggers can be overridden if the default is not good enough.I think this is cleaner. Having the triggers defined in the .yml is odd to me.