Skip to content

Commit

Permalink
breaking: (Configuration) Add enable flag triggers for generic, code …
Browse files Browse the repository at this point in the history
…review, deploy pipelines (#81)

* added flag to enable ci and pr trigger

* minor fix

* pre-commit fixs

* PR title now accept all values
  • Loading branch information
diegolagospagopa committed Feb 21, 2024
1 parent d5d9aca commit cb5bb14
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
requireScope: false
# Configure additional validation for the subject based on a regex.
# This example ensures the subject starts with an uppercase character.
subjectPattern: ^[A-Z].+$
subjectPattern: ^.+$
# If `subjectPattern` is configured, you can use this property to override
# the default error message that is shown when the pattern doesn't match.
# The variables `subject` and `title` can be used within the message.
Expand Down
4 changes: 3 additions & 1 deletion azuredevops_build_definition_code_review/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_agent_pool_name"></a> [agent\_pool\_name](#input\_agent\_pool\_name) | The agent pool that should execute the build | `string` | `"Azure Pipelines"` | no |
| <a name="input_ci_trigger_enabled"></a> [ci\_trigger\_enabled](#input\_ci\_trigger\_enabled) | Enabled or disabled Continuous Integration | `bool` | `false` | no |
| <a name="input_ci_trigger_use_yaml"></a> [ci\_trigger\_use\_yaml](#input\_ci\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_github_service_connection_id"></a> [github\_service\_connection\_id](#input\_github\_service\_connection\_id) | (Required) GitHub service connection ID used to link Azure DevOps. | `string` | n/a | yes |
| <a name="input_path"></a> [path](#input\_path) | (Required) Pipeline path on Azure DevOps | `string` | n/a | yes |
| <a name="input_pipeline_name_prefix"></a> [pipeline\_name\_prefix](#input\_pipeline\_name\_prefix) | (Optional) Pipeline name prefix to join to the .code-review suffix | `string` | `null` | no |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | (Required) Azure DevOps project ID | `string` | n/a | yes |
| <a name="input_pull_request_trigger_auto_cancel"></a> [pull\_request\_trigger\_auto\_cancel](#input\_pull\_request\_trigger\_auto\_cancel) | Allow to cancel previous runs | `bool` | `true` | no |
| <a name="input_pull_request_trigger_use_yaml"></a> [pull\_request\_trigger\_use\_yaml](#input\_pull\_request\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_pull_request_trigger_enabled"></a> [pull\_request\_trigger\_enabled](#input\_pull\_request\_trigger\_enabled) | Enabled or disabled pull request validation trigger | `bool` | `true` | no |
| <a name="input_pull_request_trigger_use_yaml"></a> [pull\_request\_trigger\_use\_yaml](#input\_pull\_request\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `true` | no |
| <a name="input_repository"></a> [repository](#input\_repository) | (Required) GitHub repository attributes | <pre>object({<br> organization = string # organization name (e.g. pagopaspa)<br> name = string # repository name inside the organizzation<br> branch_name = string<br> pipelines_path = string # path where i can find the pipelines yaml<br> yml_prefix_name = string # prefix for yaml pipeline<br> })</pre> | n/a | yes |
| <a name="input_repository_repo_type"></a> [repository\_repo\_type](#input\_repository\_repo\_type) | (Optional) The repository type. Valid values: GitHub or GitHub Enterprise. Defaults to GitHub. If repo\_type is GitHubEnterprise, must use existing project and GitHub Enterprise service connection. | `string` | `"GitHub"` | no |
| <a name="input_service_connection_ids_authorization"></a> [service\_connection\_ids\_authorization](#input\_service\_connection\_ids\_authorization) | (Optional) List service connection IDs that pipeline needs authorization. github\_service\_connection\_id is authorized by default | `list(string)` | `null` | no |
Expand Down
4 changes: 2 additions & 2 deletions azuredevops_build_definition_code_review/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "azuredevops_build_definition" "pipeline" {
}

dynamic "ci_trigger" {
for_each = var.ci_trigger_use_yaml == false ? [] : ["dummy"]
for_each = var.ci_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.ci_trigger_use_yaml
Expand All @@ -26,7 +26,7 @@ resource "azuredevops_build_definition" "pipeline" {

dynamic "pull_request_trigger" {

for_each = ["dummy"]
for_each = var.pull_request_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.pull_request_trigger_use_yaml == false ? null : true
Expand Down
14 changes: 13 additions & 1 deletion azuredevops_build_definition_code_review/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,28 @@ variable "pipeline_name_prefix" {
default = null
}

variable "ci_trigger_enabled" {
type = bool
description = "Enabled or disabled Continuous Integration"
default = false
}

variable "ci_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
default = false
}

variable "pull_request_trigger_enabled" {
type = bool
description = "Enabled or disabled pull request validation trigger"
default = true
}

variable "pull_request_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
default = false
default = true
}

variable "pull_request_trigger_auto_cancel" {
Expand Down
2 changes: 2 additions & 0 deletions azuredevops_build_definition_deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,13 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_agent_pool_name"></a> [agent\_pool\_name](#input\_agent\_pool\_name) | The agent pool that should execute the build | `string` | `"Azure Pipelines"` | no |
| <a name="input_ci_trigger_enabled"></a> [ci\_trigger\_enabled](#input\_ci\_trigger\_enabled) | Enabled or disabled Continuous Integration | `bool` | `false` | no |
| <a name="input_ci_trigger_use_yaml"></a> [ci\_trigger\_use\_yaml](#input\_ci\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_github_service_connection_id"></a> [github\_service\_connection\_id](#input\_github\_service\_connection\_id) | (Required) GitHub service connection ID used to link Azure DevOps. | `string` | n/a | yes |
| <a name="input_path"></a> [path](#input\_path) | (Required) Pipeline path on Azure DevOps | `string` | n/a | yes |
| <a name="input_pipeline_name_prefix"></a> [pipeline\_name\_prefix](#input\_pipeline\_name\_prefix) | (Optional) Prefix name of the pipeline. If null it will be the repository name. To attach to .deploy suffix | `string` | `null` | no |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | (Required) Azure DevOps project ID | `string` | n/a | yes |
| <a name="input_pull_request_trigger_enabled"></a> [pull\_request\_trigger\_enabled](#input\_pull\_request\_trigger\_enabled) | Enabled or disabled pull request validation trigger | `bool` | `false` | no |
| <a name="input_pull_request_trigger_use_yaml"></a> [pull\_request\_trigger\_use\_yaml](#input\_pull\_request\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_repository"></a> [repository](#input\_repository) | (Required) GitHub repository attributes | <pre>object({<br> organization = string # organization name (e.g. pagopaspa)<br> name = string # repository name inside the organizzation<br> branch_name = string<br> pipelines_path = string # path where i can find the pipelines yaml<br> yml_prefix_name = string # prefix for yaml pipeline<br> })</pre> | n/a | yes |
| <a name="input_repository_repo_type"></a> [repository\_repo\_type](#input\_repository\_repo\_type) | (Optional) The repository type. Valid values: GitHub or GitHub Enterprise. Defaults to GitHub. If repo\_type is GitHubEnterprise, must use existing project and GitHub Enterprise service connection. | `string` | `"GitHub"` | no |
Expand Down
4 changes: 2 additions & 2 deletions azuredevops_build_definition_deploy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "azuredevops_build_definition" "pipeline" {
}

dynamic "ci_trigger" {
for_each = var.ci_trigger_use_yaml == false ? [] : ["dummy"]
for_each = var.ci_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.ci_trigger_use_yaml
Expand All @@ -26,7 +26,7 @@ resource "azuredevops_build_definition" "pipeline" {

dynamic "pull_request_trigger" {

for_each = var.pull_request_trigger_use_yaml == false ? [] : ["dummy"]
for_each = var.pull_request_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.pull_request_trigger_use_yaml == false ? null : true
Expand Down
27 changes: 12 additions & 15 deletions azuredevops_build_definition_deploy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ variable "path" {
description = "(Required) Pipeline path on Azure DevOps"
}

variable "ci_trigger_enabled" {
type = bool
description = "Enabled or disabled Continuous Integration"
default = false
}

variable "ci_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
default = false
}

variable "pull_request_trigger_enabled" {
type = bool
description = "Enabled or disabled pull request validation trigger"
default = false
}

variable "pull_request_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
Expand All @@ -42,21 +54,6 @@ variable "repository_repo_type" {
description = " (Optional) The repository type. Valid values: GitHub or GitHub Enterprise. Defaults to GitHub. If repo_type is GitHubEnterprise, must use existing project and GitHub Enterprise service connection."
default = "GitHub"
}
# todo not works
# variable "ci_trigger" {
# type = object({
# branch_filter = object({
# exclude = list(string)
# include = list(string)
# })
# path_filter = object({
# exclude = list(string)
# include = list(string)
# })
# })
# description = "(Optional) CI trigger policy"
# default = null
# }

variable "github_service_connection_id" {
type = string
Expand Down
3 changes: 3 additions & 0 deletions azuredevops_build_definition_generic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ No modules.
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_agent_pool_name"></a> [agent\_pool\_name](#input\_agent\_pool\_name) | The agent pool that should execute the build | `string` | `"Azure Pipelines"` | no |
| <a name="input_ci_trigger_enabled"></a> [ci\_trigger\_enabled](#input\_ci\_trigger\_enabled) | Enabled or disabled Continuous Integration | `bool` | `false` | no |
| <a name="input_ci_trigger_use_yaml"></a> [ci\_trigger\_use\_yaml](#input\_ci\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_github_service_connection_id"></a> [github\_service\_connection\_id](#input\_github\_service\_connection\_id) | (Required) GitHub service connection ID used to link Azure DevOps. | `string` | n/a | yes |
| <a name="input_path"></a> [path](#input\_path) | (Required) The path where the pipelines will be created | `string` | n/a | yes |
| <a name="input_pipeline_name"></a> [pipeline\_name](#input\_pipeline\_name) | (Required) Pipeline name | `string` | n/a | yes |
| <a name="input_pipeline_yml_filename"></a> [pipeline\_yml\_filename](#input\_pipeline\_yml\_filename) | (Required) Yaml pipeline filename | `string` | n/a | yes |
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | (Required) Azure DevOps project ID | `string` | n/a | yes |
| <a name="input_pull_request_trigger_auto_cancel"></a> [pull\_request\_trigger\_auto\_cancel](#input\_pull\_request\_trigger\_auto\_cancel) | Allow to cancel previous runs | `bool` | `true` | no |
| <a name="input_pull_request_trigger_enabled"></a> [pull\_request\_trigger\_enabled](#input\_pull\_request\_trigger\_enabled) | Enabled or disabled pull request validation trigger | `bool` | `false` | no |
| <a name="input_pull_request_trigger_use_yaml"></a> [pull\_request\_trigger\_use\_yaml](#input\_pull\_request\_trigger\_use\_yaml) | (Optional) Use the azure-pipeline file for the build configuration. Defaults to false. | `bool` | `false` | no |
| <a name="input_repository"></a> [repository](#input\_repository) | (Required) GitHub repository attributes | <pre>object({<br> organization = string<br> name = string<br> branch_name = string<br> pipelines_path = string<br> })</pre> | n/a | yes |
| <a name="input_repository_repo_type"></a> [repository\_repo\_type](#input\_repository\_repo\_type) | (Optional) The repository type. Valid values: GitHub or GitHub Enterprise. Defaults to GitHub. If repo\_type is GitHubEnterprise, must use existing project and GitHub Enterprise service connection. | `string` | `"GitHub"` | no |
| <a name="input_schedules"></a> [schedules](#input\_schedules) | Allow to setup schedules trigger in azure devops. Usign that the schedules used in the yaml will be disabled | <pre>object({<br> days_to_build = list(string)<br> schedule_only_with_changes = bool<br> start_hours = number<br> start_minutes = number<br> time_zone = string<br> branch_filter = object({<br> include = list(string)<br> exclude = list(string)<br> })<br> })</pre> | `null` | no |
| <a name="input_service_connection_ids_authorization"></a> [service\_connection\_ids\_authorization](#input\_service\_connection\_ids\_authorization) | (Optional) List service connection IDs that pipeline needs authorization. github\_service\_connection\_id is authorized by default | `list(string)` | `null` | no |
| <a name="input_variables"></a> [variables](#input\_variables) | (Optional) Pipeline variables | `map(any)` | `null` | no |
| <a name="input_variables_secret"></a> [variables\_secret](#input\_variables\_secret) | (Optional) Pipeline secret variables | `map(any)` | `null` | no |
Expand Down
24 changes: 18 additions & 6 deletions azuredevops_build_definition_generic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@ resource "azuredevops_build_definition" "pipeline" {
service_connection_id = var.github_service_connection_id
}

# ci_trigger {
# use_yaml = var.ci_trigger_use_yaml == false ? null : true
# }

dynamic "ci_trigger" {
for_each = var.ci_trigger_use_yaml == false ? [] : ["dummy"]
for_each = var.ci_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.ci_trigger_use_yaml
Expand All @@ -26,7 +22,7 @@ resource "azuredevops_build_definition" "pipeline" {

dynamic "pull_request_trigger" {

for_each = ["dummy"]
for_each = var.pull_request_trigger_enabled == false ? [] : ["dummy"]

content {
use_yaml = var.pull_request_trigger_use_yaml == false ? null : true
Expand Down Expand Up @@ -77,6 +73,22 @@ resource "azuredevops_build_definition" "pipeline" {
}
}

dynamic "schedules" {
for_each = var.schedules != null ? [var.schedules] : []
iterator = s
content {
days_to_build = s.value.days_to_build
schedule_only_with_changes = s.value.schedule_only_with_changes
start_hours = s.value.start_hours
start_minutes = s.value.start_minutes
time_zone = s.value.time_zone
branch_filter {
include = s.value.branch_filter.include
exclude = s.value.branch_filter.exclude
}
}
}

lifecycle {
ignore_changes = [
pull_request_trigger.0.override.0.auto_cancel,
Expand Down
44 changes: 28 additions & 16 deletions azuredevops_build_definition_generic/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@ variable "repository" {
description = "(Required) GitHub repository attributes"
}

variable "ci_trigger_enabled" {
type = bool
description = "Enabled or disabled Continuous Integration"
default = false
}

variable "ci_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
default = false
}

variable "pull_request_trigger_enabled" {
type = bool
description = "Enabled or disabled pull request validation trigger"
default = false
}

variable "pull_request_trigger_use_yaml" {
type = bool
description = "(Optional) Use the azure-pipeline file for the build configuration. Defaults to false."
Expand All @@ -42,22 +54,6 @@ variable "repository_repo_type" {
default = "GitHub"
}

# todo not works
# variable "ci_trigger" {
# type = object({
# branch_filter = object({
# exclude = list(string)
# include = list(string)
# })
# path_filter = object({
# exclude = list(string)
# include = list(string)
# })
# })
# description = "(Optional) CI trigger policy"
# default = null
# }

variable "github_service_connection_id" {
type = string
description = "(Required) GitHub service connection ID used to link Azure DevOps."
Expand Down Expand Up @@ -96,3 +92,19 @@ variable "pipeline_name" {
type = string
description = "(Required) Pipeline name"
}

variable "schedules" {
type = object({
days_to_build = list(string)
schedule_only_with_changes = bool
start_hours = number
start_minutes = number
time_zone = string
branch_filter = object({
include = list(string)
exclude = list(string)
})
})
default = null
description = "Allow to setup schedules trigger in azure devops. Usign that the schedules used in the yaml will be disabled"
}

0 comments on commit cb5bb14

Please sign in to comment.