Skip to content

Commit 7a990bf

Browse files
authored
feat: add support for terraform cloud "projects" feature #9 (#10)
1 parent 7c5aaa1 commit 7a990bf

8 files changed

Lines changed: 50 additions & 22 deletions

File tree

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ Terraform module to provision and manage Terraform Cloud workspaces
1111
- Variables
1212
- Variable Set assignments
1313

14-
:warning: For Notifications configuration, only "webhook", "slack" and "microsoft-teams" types are supported at the moment
14+
> **Warning**
15+
>
16+
> For Notifications configuration, only "webhook", "slack" and "microsoft-teams" types are supported at the moment
1517
1618
## Usage
1719

1820
### Simple workspace with local run mode
1921
```
2022
module "workspace_only_for_remote_state" {
2123
source = "flowingis/workspace/tfe"
22-
version = "0.3.0"
24+
version = "0.5.0"
2325
2426
name = "my-workspace-name"
2527
organization = "my-organization"
2628
description = "Simple workspace that only manages the remote state for some resource on AWS"
2729
28-
terraform_version = "1.1.9"
30+
terraform_version = "1.3.7"
2931
execution_mode = "local"
3032
3133
terraform_variables = {
@@ -52,13 +54,13 @@ module "workspace_only_for_remote_state" {
5254
```
5355
module "my_workspace" {
5456
source = "flowingis/workspace/tfe"
55-
version = "0.3.0"
57+
version = "0.5.0"
5658
5759
name = "my-workspace-name"
5860
organization = "my-organization"
5961
description = "Advanced workspace with remote run mode"
6062
61-
terraform_version = "1.1.9"
63+
terraform_version = "1.3.7"
6264
6365
queue_all_runs = false
6466
working_directory = "/my/sub/path"
@@ -106,13 +108,13 @@ It is possible to integrate this module with [tfe-variable-set module](https://r
106108
| Name | Version |
107109
|------|---------|
108110
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.0 |
109-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | >= 0.39.0 |
111+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | >= 0.40.0 |
110112

111113
## Providers
112114

113115
| Name | Version |
114116
|------|---------|
115-
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | >= 0.39.0 |
117+
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | >= 0.40.0 |
116118

117119
## Modules
118120

@@ -150,6 +152,7 @@ No modules.
150152
| <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 |
151153
| <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 |
152154
| <a name="input_organization"></a> [organization](#input\_organization) | (Required) Name of the organization | `string` | n/a | yes |
155+
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | (Optional) ID of the project where the workspace should be created | `string` | `""` | no |
153156
| <a name="input_queue_all_runs"></a> [queue\_all\_runs](#input\_queue\_all\_runs) | (Optional) Whether the workspace should start automatically performing runs immediately after its creation | `bool` | `true` | no |
154157
| <a name="input_remote_state_consumer_ids"></a> [remote\_state\_consumer\_ids](#input\_remote\_state\_consumer\_ids) | (Optional) The set of workspace IDs set as explicit remote state consumers for the given workspace | `list(string)` | `[]` | no |
155158
| <a name="input_run_triggers"></a> [run\_triggers](#input\_run\_triggers) | List of source workspaces IDs that trigger runs in this workspace | `list(string)` | `[]` | no |
@@ -164,7 +167,7 @@ No modules.
164167
| <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 |
165168
| <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 |
166169
| <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 |
167-
| <a name="input_variable_set_ids"></a> [variable\_set\_ids](#input\_variable\_set\_ids) | List of variable set ids applied to this workspace | `list(string)` | `[]` | no |
170+
| <a name="input_variable_set_ids"></a> [variable\_set\_ids](#input\_variable\_set\_ids) | (Optional) List of variable set ids applied to this workspace | `list(string)` | `[]` | no |
168171
| <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 |
169172
| <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 |
170173
| <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 |

examples/advanced-workspace/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ Choose the appropriate method to automatically specify these values, like descri
3131

3232
| Name | Version |
3333
|------|---------|
34-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.1.0 |
35-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.39.0 |
34+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3.0 |
35+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.40.0 |
3636

3737
## Providers
3838

39-
No providers.
39+
| Name | Version |
40+
|------|---------|
41+
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.40.0 |
4042

4143
## Modules
4244

@@ -46,7 +48,10 @@ No providers.
4648

4749
## Resources
4850

49-
No resources.
51+
| Name | Type |
52+
|------|------|
53+
| [tfe_project.myproject](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/project) | resource |
54+
| [tfe_organization.myorg](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/data-sources/organization) | data source |
5055

5156
## Inputs
5257

examples/advanced-workspace/main.tf

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
terraform {
2-
required_version = "~> 1.1.0"
2+
required_version = "~> 1.3.0"
33

44
required_providers {
55
tfe = {
66
source = "hashicorp/tfe"
7-
version = "~> 0.39.0"
7+
version = "~> 0.40.0"
88
}
99
}
1010
}
@@ -13,13 +13,26 @@ provider "tfe" {
1313
token = var.tfc_token
1414
}
1515

16+
# Use existing organization
17+
data "tfe_organization" "myorg" {
18+
name = "myorg"
19+
}
20+
21+
# Use a dedicated project for this workspace
22+
resource "tfe_project" "myproject" {
23+
organization = data.tfe_organization.myorg.name
24+
name = "myproject"
25+
}
26+
1627
module "advanced_workspace" {
1728
source = "../../"
1829

1930
name = "advanced-workspace"
20-
organization = "myorg"
31+
organization = data.tfe_organization.myorg.name
2132
description = "An advanced Terraform Cloud/Enterprise workspace"
22-
terraform_version = "1.1.9"
33+
terraform_version = "1.3.7"
34+
35+
project_id = tfe_project.myproject.id
2336

2437
terraform_variables = {
2538
string_variable = "stringvalue"

examples/simple-workspace/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ for further information.
2626

2727
| Name | Version |
2828
|------|---------|
29-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.1.0 |
30-
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.39.0 |
29+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3.0 |
30+
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | ~> 0.40.0 |
3131

3232
## Providers
3333

examples/simple-workspace/main.tf

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

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

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ resource "tfe_workspace" "this" {
7575
file_triggers_enabled = var.file_triggers_enabled
7676
global_remote_state = var.global_remote_state
7777
remote_state_consumer_ids = var.remote_state_consumer_ids
78+
project_id = var.project_id
7879
queue_all_runs = var.queue_all_runs
7980
speculative_enabled = var.speculative_enabled
8081
structured_run_output_enabled = var.structured_run_output_enabled

variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,13 @@ EOT
415415
}
416416

417417
variable "variable_set_ids" {
418-
description = "List of variable set ids applied to this workspace"
418+
description = "(Optional) List of variable set ids applied to this workspace"
419419
type = list(string)
420420
default = []
421421
}
422+
423+
variable "project_id" {
424+
description = "(Optional) ID of the project where the workspace should be created"
425+
type = string
426+
default = ""
427+
}

versions.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.39.0"
7+
version = ">= 0.40.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)