diff --git a/README.md b/README.md index ecc3405..9af016c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Terraform module to provision and manage Terraform Cloud workspaces - Version Control - Variables -:warning: For Notifications configuration, only "webhook" and "slack" types are supported at the moment +:warning: For Notifications configuration, only "webhook", "slack" and "microsoft-teams" types are supported at the moment ## Usage @@ -18,7 +18,7 @@ Terraform module to provision and manage Terraform Cloud workspaces ``` module "workspace_only_for_remote_state" { source = "flowingis/workspace/tfe" - version = "0.2.0" + version = "0.3.0" name = "my-workspace-name" organization = "my-organization" @@ -51,7 +51,7 @@ module "workspace_only_for_remote_state" { ``` module "my_workspace" { source = "flowingis/workspace/tfe" - version = "0.2.0" + version = "0.3.0" name = "my-workspace-name" organization = "my-organization" @@ -100,14 +100,14 @@ module "my_workspace" { | Name | Version | |------|---------| -| [terraform](#requirement\_terraform) | >= 0.14.0 | -| [tfe](#requirement\_tfe) | ~> 0.31.0 | +| [terraform](#requirement\_terraform) | >= 1.0.0 | +| [tfe](#requirement\_tfe) | >= 0.39.0 | ## Providers | Name | Version | |------|---------| -| [tfe](#provider\_tfe) | ~> 0.31.0 | +| [tfe](#provider\_tfe) | >= 0.39.0 | ## Modules @@ -117,6 +117,7 @@ No modules. | Name | Type | |------|------| +| [tfe_notification_configuration.microsoft_teams](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource | | [tfe_notification_configuration.slack](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource | | [tfe_notification_configuration.webhook](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource | | [tfe_run_trigger.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/run_trigger) | resource | @@ -128,14 +129,17 @@ No modules. | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | [allow\_destroy\_plan](#input\_allow\_destroy\_plan) | (Optional) Whether destroy plans can be queued on the workspace | `bool` | `false` | no | +| [assessments\_enabled](#input\_assessments\_enabled) | (Optional) Whether to regularly run health assessments such as drift detection on the workspace | `bool` | `false` | no | | [auto\_apply](#input\_auto\_apply) | (Optional) Whether to automatically apply changes when a Terraform plan is successful | `bool` | `false` | no | | [description](#input\_description) | (Optional) A description for the workspace | `string` | `""` | no | | [environment\_sensitive\_variables](#input\_environment\_sensitive\_variables) | (Optional) Map of sensitive variables of 'environment' category used in the workspace

Item syntax:
{
variable1\_name = value1
variable2\_name = value2
...
} | `map(any)` | `{}` | no | | [environment\_variables](#input\_environment\_variables) | (Optional) Map of variables of 'environment' category used in the workspace

Item syntax:
{
variable1\_name = value1
variable2\_name = value2
...
} | `map(any)` | `{}` | no | | [execution\_mode](#input\_execution\_mode) | (Optional) Which execution mode to use | `string` | `"remote"` | no | | [file\_triggers\_enabled](#input\_file\_triggers\_enabled) | (Optional) Whether to filter runs based on the changed files in a VCS push | `bool` | `true` | no | +| [force\_delete](#input\_force\_delete) | (Optional) If this attribute is present on a workspace that is being deleted through the provider, it will use the existing force delete API. If this attribute is not present or false it will safe delete the workspace | `bool` | `false` | no | | [global\_remote\_state](#input\_global\_remote\_state) | (Optional) Whether the workspace allows all workspaces in the organization to access its state data during runs | `bool` | `false` | no | | [name](#input\_name) | (Required) Name of the workspace | `string` | n/a | yes | +| [notification\_microsoft\_teams\_configuration](#input\_notification\_microsoft\_teams\_configuration) | (Optional) List of notification configuration of 'Microsoft Teams' type

Item syntax:
[
{
name = "webhook\_1"
enabled = true
url = "https://ms1234567890abcde.webhook.office.com"
triggers = [
"created",
"planning",
"needs\_attention",
"applying",
"completed",
"errored"
]
},
{
name = "webhook\_2"
enabled = false
url = "https://ms0987654321edcba.webhook.office.com"
},
{
...
}
] |
list(object({
name = string,
enabled = bool,
url = string,
triggers = list(string) #Optional
}))
| `[]` | no | | [notification\_slack\_configuration](#input\_notification\_slack\_configuration) | (Optional) List of notification configuration of 'Slack' type

Item syntax:
[
{
name = "webhook\_1"
enabled = true
url = "https://hooks.slack.com/services/VeryLongHash1"
triggers = [
"created",
"planning",
"needs\_attention",
"applying",
"completed",
"errored"
]
},
{
name = "webhook\_2"
enabled = false
url = "https://hooks.slack.com/services/VeryLongHash2"
},
{
...
}
] |
list(object({
name = string,
enabled = bool,
url = string,
triggers = list(string) #Optional
}))
| `[]` | no | | [notification\_webhook\_configuration](#input\_notification\_webhook\_configuration) | (Optional) List of notification configuration of 'Webhook' type

Item syntax:
[
{
name = "webhook\_1"
enabled = true
token = "mysupersecrettoken1"
url = "https://myendpoint1.domain.ext"
triggers = [
"created",
"planning",
"needs\_attention",
"applying",
"completed",
"errored"
]
},
{
name = "webhook\_2"
enabled = false
token = "mysupersecrettoken2"
url = "https://myendpoint2.domain.ext"
},
{
...
}
] |
list(object({
name = string,
enabled = bool,
token = string,
url = string,
triggers = list(string) #Optional
}))
| `[]` | no | | [oauth\_token\_id](#input\_oauth\_token\_id) | (Optional) The token ID of the VCS connection to use | `string` | `""` | no | @@ -152,11 +156,13 @@ No modules. | [terraform\_sensitive\_variables](#input\_terraform\_sensitive\_variables) | (Optional) Map of sensitive variables of 'Terraform' category used in the workspace

Item syntax:
{
variable1\_name = value1
variable2\_name = value2
...
} | `map(any)` | `{}` | no | | [terraform\_variables](#input\_terraform\_variables) | (Optional) Map of variables of 'Terraform' category used in the workspace

Item syntax:
{
variable1\_name = value1
variable2\_name = value2
...
} | `map(any)` | `{}` | no | | [terraform\_version](#input\_terraform\_version) | (Required) The version of Terraform to use for this workspace | `string` | n/a | yes | -| [trigger\_prefixes](#input\_trigger\_prefixes) | (Optional) List of repository-root-relative paths which describe all locations to be tracked for changes | `list(string)` | `[]` | no | +| [trigger\_patterns](#input\_trigger\_patterns) | (Optional) List of glob patterns that describe the files Terraform Cloud monitors for changes. Trigger patterns are always appended to the root directory of the repository. Mutually exclusive with trigger-prefixes. Only available for Terraform Cloud | `list(string)` | `null` | no | +| [trigger\_prefixes](#input\_trigger\_prefixes) | (Optional) List of repository-root-relative paths which describe all locations to be tracked for changes | `list(string)` | `null` | no | | [variables\_descriptions](#input\_variables\_descriptions) | (Optional) Map of descriptions applied to workspace variables

Item syntax:
{
variable1\_name = "description"
variable2\_name = "description"
...
} | `map(string)` | `{}` | no | | [vcs\_repository\_branch](#input\_vcs\_repository\_branch) | (Optional) The repository branch that Terraform will execute from | `string` | `""` | no | | [vcs\_repository\_identifier](#input\_vcs\_repository\_identifier) | (Optional) A reference to your VCS repository in the format / where and refer to the organization and repository in your VCS provider. The format for Azure DevOps is //\_git/ | `string` | `""` | no | | [vcs\_repository\_ingress\_submodules](#input\_vcs\_repository\_ingress\_submodules) | (Optional) Whether submodules should be fetched when cloning the VCS repository | `bool` | `false` | no | +| [vcs\_repository\_tags\_regex](#input\_vcs\_repository\_tags\_regex) | (Optional) (Optional) A regular expression used to trigger a Workspace run for matching Git tags. This option conflicts with trigger\_patterns and trigger\_prefixes. Should only set this value if the former is not being used | `string` | `null` | no | | [working\_directory](#input\_working\_directory) | (Optional) A relative path that Terraform will execute within | `string` | `null` | no | ## Outputs diff --git a/examples/advanced-workspace/README.md b/examples/advanced-workspace/README.md index e8b8e1a..889665f 100644 --- a/examples/advanced-workspace/README.md +++ b/examples/advanced-workspace/README.md @@ -32,7 +32,7 @@ Choose the appropriate method to automatically specify these values, like descri | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | ~> 1.1.0 | -| [tfe](#requirement\_tfe) | ~> 0.31.0 | +| [tfe](#requirement\_tfe) | ~> 0.39.0 | ## Providers diff --git a/examples/advanced-workspace/main.tf b/examples/advanced-workspace/main.tf index c248858..383894c 100644 --- a/examples/advanced-workspace/main.tf +++ b/examples/advanced-workspace/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { tfe = { source = "hashicorp/tfe" - version = "~> 0.31.0" + version = "~> 0.39.0" } } } diff --git a/examples/simple-workspace/README.md b/examples/simple-workspace/README.md index 24e0735..830b730 100644 --- a/examples/simple-workspace/README.md +++ b/examples/simple-workspace/README.md @@ -27,7 +27,7 @@ for further information. | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | ~> 1.1.0 | -| [tfe](#requirement\_tfe) | ~> 0.31.0 | +| [tfe](#requirement\_tfe) | ~> 0.39.0 | ## Providers diff --git a/examples/simple-workspace/main.tf b/examples/simple-workspace/main.tf index 528f5eb..ef6f58b 100644 --- a/examples/simple-workspace/main.tf +++ b/examples/simple-workspace/main.tf @@ -4,7 +4,7 @@ terraform { required_providers { tfe = { source = "hashicorp/tfe" - version = "~> 0.31.0" + version = "~> 0.39.0" } } } diff --git a/main.tf b/main.tf index 4952880..4e99be0 100644 --- a/main.tf +++ b/main.tf @@ -71,6 +71,7 @@ resource "tfe_workspace" "this" { allow_destroy_plan = var.allow_destroy_plan auto_apply = var.auto_apply execution_mode = var.execution_mode + assessments_enabled = var.assessments_enabled file_triggers_enabled = var.file_triggers_enabled global_remote_state = var.global_remote_state remote_state_consumer_ids = var.remote_state_consumer_ids @@ -80,8 +81,10 @@ resource "tfe_workspace" "this" { ssh_key_id = var.ssh_key_id terraform_version = var.terraform_version trigger_prefixes = var.trigger_prefixes + trigger_patterns = var.trigger_patterns tag_names = var.tag_names working_directory = var.working_directory + force_delete = var.force_delete dynamic "vcs_repo" { for_each = length(var.vcs_repository_identifier) > 0 && length(var.oauth_token_id) > 0 ? [1] : [] @@ -91,6 +94,7 @@ resource "tfe_workspace" "this" { branch = var.vcs_repository_branch ingress_submodules = var.vcs_repository_ingress_submodules oauth_token_id = var.oauth_token_id + tags_regex = var.vcs_repository_tags_regex } } } @@ -136,3 +140,14 @@ resource "tfe_notification_configuration" "slack" { url = lookup(var.notification_slack_configuration[count.index], "url") workspace_id = tfe_workspace.this.id } + +resource "tfe_notification_configuration" "microsoft_teams" { + count = length(var.notification_microsoft_teams_configuration) + + name = lookup(var.notification_microsoft_teams_configuration[count.index], "name") + destination_type = "microsoft-teams" + enabled = lookup(var.notification_microsoft_teams_configuration[count.index], "enabled", false) + triggers = [for trigger in lookup(var.notification_microsoft_teams_configuration[count.index], "triggers", []) : "run:${trigger}"] + url = lookup(var.notification_microsoft_teams_configuration[count.index], "url") + workspace_id = tfe_workspace.this.id +} diff --git a/variables.tf b/variables.tf index 6c1ed71..c09b6ae 100644 --- a/variables.tf +++ b/variables.tf @@ -37,6 +37,12 @@ variable "execution_mode" { } } +variable "assessments_enabled" { + description = "(Optional) Whether to regularly run health assessments such as drift detection on the workspace" + type = bool + default = false +} + variable "file_triggers_enabled" { description = "(Optional) Whether to filter runs based on the changed files in a VCS push" type = bool @@ -87,7 +93,13 @@ variable "terraform_version" { variable "trigger_prefixes" { description = "(Optional) List of repository-root-relative paths which describe all locations to be tracked for changes" type = list(string) - default = [] + default = null +} + +variable "trigger_patterns" { + description = "(Optional) List of glob patterns that describe the files Terraform Cloud monitors for changes. Trigger patterns are always appended to the root directory of the repository. Mutually exclusive with trigger-prefixes. Only available for Terraform Cloud" + type = list(string) + default = null } variable "tag_names" { @@ -102,6 +114,12 @@ variable "working_directory" { default = null } +variable "force_delete" { + description = "(Optional) If this attribute is present on a workspace that is being deleted through the provider, it will use the existing force delete API. If this attribute is not present or false it will safe delete the workspace" + type = bool + default = false +} + variable "vcs_repository_identifier" { description = "(Optional) A reference to your VCS repository in the format / where and refer to the organization and repository in your VCS provider. The format for Azure DevOps is //_git/" type = string @@ -126,6 +144,12 @@ variable "oauth_token_id" { default = "" } +variable "vcs_repository_tags_regex" { + description = "(Optional) (Optional) A regular expression used to trigger a Workspace run for matching Git tags. This option conflicts with trigger_patterns and trigger_prefixes. Should only set this value if the former is not being used" + type = string + default = null +} + variable "terraform_variables" { description = <