Skip to content

Commit f6053ca

Browse files
authored
feat: upgrade version and add new available attributes and resources #5 (#6)
* use latest stable versione of tfe provider, enforce initial stable version (>=1.0.0) of terraform cli * handle notification_configuration resource of type "microsoft-teams" * add assessment_enabled, trigger_patterns and force_delete attributes to tfe_workspace resource * add "tags_regex" attribute in vcs_repo block of tfe_workspace_resource
1 parent 8d3d433 commit f6053ca

8 files changed

Lines changed: 99 additions & 14 deletions

File tree

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Terraform module to provision and manage Terraform Cloud workspaces
1010
- Version Control
1111
- Variables
1212

13-
:warning: For Notifications configuration, only "webhook" and "slack" types are supported at the moment
13+
:warning: For Notifications configuration, only "webhook", "slack" and "microsoft-teams" types are supported at the moment
1414

1515
## Usage
1616

1717
### Simple workspace with local run mode
1818
```
1919
module "workspace_only_for_remote_state" {
2020
source = "flowingis/workspace/tfe"
21-
version = "0.2.0"
21+
version = "0.3.0"
2222
2323
name = "my-workspace-name"
2424
organization = "my-organization"
@@ -51,7 +51,7 @@ module "workspace_only_for_remote_state" {
5151
```
5252
module "my_workspace" {
5353
source = "flowingis/workspace/tfe"
54-
version = "0.2.0"
54+
version = "0.3.0"
5555
5656
name = "my-workspace-name"
5757
organization = "my-organization"
@@ -100,14 +100,14 @@ module "my_workspace" {
100100

101101
| Name | Version |
102102
|------|---------|
103-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 |
104-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.31.0 |
103+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
104+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | >= 0.39.0 |
105105

106106
## Providers
107107

108108
| Name | Version |
109109
|------|---------|
110-
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.31.0 |
110+
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | >= 0.39.0 |
111111

112112
## Modules
113113

@@ -117,6 +117,7 @@ No modules.
117117

118118
| Name | Type |
119119
|------|------|
120+
| [tfe_notification_configuration.microsoft_teams](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource |
120121
| [tfe_notification_configuration.slack](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource |
121122
| [tfe_notification_configuration.webhook](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/notification_configuration) | resource |
122123
| [tfe_run_trigger.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/run_trigger) | resource |
@@ -128,14 +129,17 @@ No modules.
128129
| Name | Description | Type | Default | Required |
129130
|------|-------------|------|---------|:--------:|
130131
| <a name="input_allow_destroy_plan"></a> [allow\_destroy\_plan](#input\_allow\_destroy\_plan) | (Optional) Whether destroy plans can be queued on the workspace | `bool` | `false` | no |
132+
| <a name="input_assessments_enabled"></a> [assessments\_enabled](#input\_assessments\_enabled) | (Optional) Whether to regularly run health assessments such as drift detection on the workspace | `bool` | `false` | no |
131133
| <a name="input_auto_apply"></a> [auto\_apply](#input\_auto\_apply) | (Optional) Whether to automatically apply changes when a Terraform plan is successful | `bool` | `false` | no |
132134
| <a name="input_description"></a> [description](#input\_description) | (Optional) A description for the workspace | `string` | `""` | no |
133135
| <a name="input_environment_sensitive_variables"></a> [environment\_sensitive\_variables](#input\_environment\_sensitive\_variables) | (Optional) Map of sensitive variables of 'environment' category used in the workspace<br><br> Item syntax:<br> {<br> variable1\_name = value1<br> variable2\_name = value2<br> ...<br> } | `map(any)` | `{}` | no |
134136
| <a name="input_environment_variables"></a> [environment\_variables](#input\_environment\_variables) | (Optional) Map of variables of 'environment' category used in the workspace<br><br> Item syntax:<br> {<br> variable1\_name = value1<br> variable2\_name = value2<br> ...<br> } | `map(any)` | `{}` | no |
135137
| <a name="input_execution_mode"></a> [execution\_mode](#input\_execution\_mode) | (Optional) Which execution mode to use | `string` | `"remote"` | no |
136138
| <a name="input_file_triggers_enabled"></a> [file\_triggers\_enabled](#input\_file\_triggers\_enabled) | (Optional) Whether to filter runs based on the changed files in a VCS push | `bool` | `true` | no |
139+
| <a name="input_force_delete"></a> [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 |
137140
| <a name="input_global_remote_state"></a> [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 |
138141
| <a name="input_name"></a> [name](#input\_name) | (Required) Name of the workspace | `string` | n/a | yes |
142+
| <a name="input_notification_microsoft_teams_configuration"></a> [notification\_microsoft\_teams\_configuration](#input\_notification\_microsoft\_teams\_configuration) | (Optional) List of notification configuration of 'Microsoft Teams' type<br><br> Item syntax:<br> [<br> {<br> name = "webhook\_1"<br> enabled = true<br> url = "https://ms1234567890abcde.webhook.office.com"<br> triggers = [<br> "created",<br> "planning",<br> "needs\_attention",<br> "applying",<br> "completed",<br> "errored"<br> ]<br> },<br> {<br> name = "webhook\_2"<br> enabled = false<br> url = "https://ms0987654321edcba.webhook.office.com"<br> },<br> {<br> ...<br> }<br> ] | <pre>list(object({<br> name = string,<br> enabled = bool,<br> url = string,<br> triggers = list(string) #Optional<br> }))</pre> | `[]` | no |
139143
| <a name="input_notification_slack_configuration"></a> [notification\_slack\_configuration](#input\_notification\_slack\_configuration) | (Optional) List of notification configuration of 'Slack' type<br><br> Item syntax:<br> [<br> {<br> name = "webhook\_1"<br> enabled = true<br> url = "https://hooks.slack.com/services/VeryLongHash1"<br> triggers = [<br> "created",<br> "planning",<br> "needs\_attention",<br> "applying",<br> "completed",<br> "errored"<br> ]<br> },<br> {<br> name = "webhook\_2"<br> enabled = false<br> url = "https://hooks.slack.com/services/VeryLongHash2"<br> },<br> {<br> ...<br> }<br> ] | <pre>list(object({<br> name = string,<br> enabled = bool,<br> url = string,<br> triggers = list(string) #Optional<br> }))</pre> | `[]` | no |
140144
| <a name="input_notification_webhook_configuration"></a> [notification\_webhook\_configuration](#input\_notification\_webhook\_configuration) | (Optional) List of notification configuration of 'Webhook' type<br><br> Item syntax:<br> [<br> {<br> name = "webhook\_1"<br> enabled = true<br> token = "mysupersecrettoken1"<br> url = "https://myendpoint1.domain.ext"<br> triggers = [<br> "created",<br> "planning",<br> "needs\_attention",<br> "applying",<br> "completed",<br> "errored"<br> ]<br> },<br> {<br> name = "webhook\_2"<br> enabled = false<br> token = "mysupersecrettoken2"<br> url = "https://myendpoint2.domain.ext"<br> },<br> {<br> ...<br> }<br> ] | <pre>list(object({<br> name = string,<br> enabled = bool,<br> token = string,<br> url = string,<br> triggers = list(string) #Optional<br> }))</pre> | `[]` | no |
141145
| <a name="input_oauth_token_id"></a> [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.
152156
| <a name="input_terraform_sensitive_variables"></a> [terraform\_sensitive\_variables](#input\_terraform\_sensitive\_variables) | (Optional) Map of sensitive variables of 'Terraform' category used in the workspace<br><br>Item syntax:<br>{<br> variable1\_name = value1<br> variable2\_name = value2<br> ...<br>} | `map(any)` | `{}` | no |
153157
| <a name="input_terraform_variables"></a> [terraform\_variables](#input\_terraform\_variables) | (Optional) Map of variables of 'Terraform' category used in the workspace<br><br> Item syntax:<br> {<br> variable1\_name = value1<br> variable2\_name = value2<br> ...<br> } | `map(any)` | `{}` | no |
154158
| <a name="input_terraform_version"></a> [terraform\_version](#input\_terraform\_version) | (Required) The version of Terraform to use for this workspace | `string` | n/a | yes |
155-
| <a name="input_trigger_prefixes"></a> [trigger\_prefixes](#input\_trigger\_prefixes) | (Optional) List of repository-root-relative paths which describe all locations to be tracked for changes | `list(string)` | `[]` | no |
159+
| <a name="input_trigger_patterns"></a> [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 |
160+
| <a name="input_trigger_prefixes"></a> [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 |
156161
| <a name="input_variables_descriptions"></a> [variables\_descriptions](#input\_variables\_descriptions) | (Optional) Map of descriptions applied to workspace variables<br><br> Item syntax:<br> {<br> variable1\_name = "description"<br> variable2\_name = "description"<br> ...<br> } | `map(string)` | `{}` | no |
157162
| <a name="input_vcs_repository_branch"></a> [vcs\_repository\_branch](#input\_vcs\_repository\_branch) | (Optional) The repository branch that Terraform will execute from | `string` | `""` | no |
158163
| <a name="input_vcs_repository_identifier"></a> [vcs\_repository\_identifier](#input\_vcs\_repository\_identifier) | (Optional) A reference to your VCS repository in the format <organization>/<repository> where <organization> and <repository> refer to the organization and repository in your VCS provider. The format for Azure DevOps is //\_git/ | `string` | `""` | no |
159164
| <a name="input_vcs_repository_ingress_submodules"></a> [vcs\_repository\_ingress\_submodules](#input\_vcs\_repository\_ingress\_submodules) | (Optional) Whether submodules should be fetched when cloning the VCS repository | `bool` | `false` | no |
165+
| <a name="input_vcs_repository_tags_regex"></a> [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 |
160166
| <a name="input_working_directory"></a> [working\_directory](#input\_working\_directory) | (Optional) A relative path that Terraform will execute within | `string` | `null` | no |
161167

162168
## Outputs

examples/advanced-workspace/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Choose the appropriate method to automatically specify these values, like descri
3232
| Name | Version |
3333
|------|---------|
3434
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.1.0 |
35-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.31.0 |
35+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.39.0 |
3636

3737
## Providers
3838

examples/advanced-workspace/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
tfe = {
66
source = "hashicorp/tfe"
7-
version = "~> 0.31.0"
7+
version = "~> 0.39.0"
88
}
99
}
1010
}

examples/simple-workspace/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ for further information.
2727
| Name | Version |
2828
|------|---------|
2929
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.1.0 |
30-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.31.0 |
30+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.39.0 |
3131

3232
## Providers
3333

examples/simple-workspace/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
tfe = {
66
source = "hashicorp/tfe"
7-
version = "~> 0.31.0"
7+
version = "~> 0.39.0"
88
}
99
}
1010
}

main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ resource "tfe_workspace" "this" {
7171
allow_destroy_plan = var.allow_destroy_plan
7272
auto_apply = var.auto_apply
7373
execution_mode = var.execution_mode
74+
assessments_enabled = var.assessments_enabled
7475
file_triggers_enabled = var.file_triggers_enabled
7576
global_remote_state = var.global_remote_state
7677
remote_state_consumer_ids = var.remote_state_consumer_ids
@@ -80,8 +81,10 @@ resource "tfe_workspace" "this" {
8081
ssh_key_id = var.ssh_key_id
8182
terraform_version = var.terraform_version
8283
trigger_prefixes = var.trigger_prefixes
84+
trigger_patterns = var.trigger_patterns
8385
tag_names = var.tag_names
8486
working_directory = var.working_directory
87+
force_delete = var.force_delete
8588

8689
dynamic "vcs_repo" {
8790
for_each = length(var.vcs_repository_identifier) > 0 && length(var.oauth_token_id) > 0 ? [1] : []
@@ -91,6 +94,7 @@ resource "tfe_workspace" "this" {
9194
branch = var.vcs_repository_branch
9295
ingress_submodules = var.vcs_repository_ingress_submodules
9396
oauth_token_id = var.oauth_token_id
97+
tags_regex = var.vcs_repository_tags_regex
9498
}
9599
}
96100
}
@@ -136,3 +140,14 @@ resource "tfe_notification_configuration" "slack" {
136140
url = lookup(var.notification_slack_configuration[count.index], "url")
137141
workspace_id = tfe_workspace.this.id
138142
}
143+
144+
resource "tfe_notification_configuration" "microsoft_teams" {
145+
count = length(var.notification_microsoft_teams_configuration)
146+
147+
name = lookup(var.notification_microsoft_teams_configuration[count.index], "name")
148+
destination_type = "microsoft-teams"
149+
enabled = lookup(var.notification_microsoft_teams_configuration[count.index], "enabled", false)
150+
triggers = [for trigger in lookup(var.notification_microsoft_teams_configuration[count.index], "triggers", []) : "run:${trigger}"]
151+
url = lookup(var.notification_microsoft_teams_configuration[count.index], "url")
152+
workspace_id = tfe_workspace.this.id
153+
}

variables.tf

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ variable "execution_mode" {
3737
}
3838
}
3939

40+
variable "assessments_enabled" {
41+
description = "(Optional) Whether to regularly run health assessments such as drift detection on the workspace"
42+
type = bool
43+
default = false
44+
}
45+
4046
variable "file_triggers_enabled" {
4147
description = "(Optional) Whether to filter runs based on the changed files in a VCS push"
4248
type = bool
@@ -87,7 +93,13 @@ variable "terraform_version" {
8793
variable "trigger_prefixes" {
8894
description = "(Optional) List of repository-root-relative paths which describe all locations to be tracked for changes"
8995
type = list(string)
90-
default = []
96+
default = null
97+
}
98+
99+
variable "trigger_patterns" {
100+
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"
101+
type = list(string)
102+
default = null
91103
}
92104

93105
variable "tag_names" {
@@ -102,6 +114,12 @@ variable "working_directory" {
102114
default = null
103115
}
104116

117+
variable "force_delete" {
118+
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"
119+
type = bool
120+
default = false
121+
}
122+
105123
variable "vcs_repository_identifier" {
106124
description = "(Optional) A reference to your VCS repository in the format <organization>/<repository> where <organization> and <repository> refer to the organization and repository in your VCS provider. The format for Azure DevOps is //_git/"
107125
type = string
@@ -126,6 +144,12 @@ variable "oauth_token_id" {
126144
default = ""
127145
}
128146

147+
variable "vcs_repository_tags_regex" {
148+
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"
149+
type = string
150+
default = null
151+
}
152+
129153
variable "terraform_variables" {
130154
description = <<EOF
131155
(Optional) Map of variables of 'Terraform' category used in the workspace
@@ -349,3 +373,43 @@ EOT
349373

350374
default = []
351375
}
376+
377+
variable "notification_microsoft_teams_configuration" {
378+
description = <<EOT
379+
(Optional) List of notification configuration of 'Microsoft Teams' type
380+
381+
Item syntax:
382+
[
383+
{
384+
name = "webhook_1"
385+
enabled = true
386+
url = "https://ms1234567890abcde.webhook.office.com"
387+
triggers = [
388+
"created",
389+
"planning",
390+
"needs_attention",
391+
"applying",
392+
"completed",
393+
"errored"
394+
]
395+
},
396+
{
397+
name = "webhook_2"
398+
enabled = false
399+
url = "https://ms0987654321edcba.webhook.office.com"
400+
},
401+
{
402+
...
403+
}
404+
]
405+
EOT
406+
407+
type = list(object({
408+
name = string,
409+
enabled = bool,
410+
url = string,
411+
triggers = list(string) #Optional
412+
}))
413+
414+
default = []
415+
}

versions.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = ">= 0.14.0"
2+
required_version = ">= 1.0.0"
33

44
required_providers {
55
tfe = {
66
source = "hashicorp/tfe"
7-
version = "~> 0.31.0"
7+
version = ">= 0.39.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)