From 6e28da9d1c69915e80f745d2b9edaf3c291163fa Mon Sep 17 00:00:00 2001 From: Byungjin Park Date: Fri, 3 May 2024 02:23:10 +0900 Subject: [PATCH] Add workspace module --- modules/workspace/README.md | 57 ++++++++++++++++++++++++++++++++++ modules/workspace/main.tf | 35 +++++++++++++++++++++ modules/workspace/outputs.tf | 54 ++++++++++++++++++++++++++++++++ modules/workspace/variables.tf | 44 ++++++++++++++++++++++++++ modules/workspace/versions.tf | 10 ++++++ 5 files changed, 200 insertions(+) create mode 100644 modules/workspace/README.md create mode 100644 modules/workspace/main.tf create mode 100644 modules/workspace/outputs.tf create mode 100644 modules/workspace/variables.tf create mode 100644 modules/workspace/versions.tf diff --git a/modules/workspace/README.md b/modules/workspace/README.md new file mode 100644 index 0000000..dc7ef0e --- /dev/null +++ b/modules/workspace/README.md @@ -0,0 +1,57 @@ +# workspace + +This module creates following resources. + +- `tfe_workspace` +- `tfe_workspace_policy_set` (optional) +- `tfe_workspace_variable_set` (optional) + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.6 | +| [tfe](#requirement\_tfe) | >= 0.53 | + +## Providers + +| Name | Version | +|------|---------| +| [tfe](#provider\_tfe) | 0.54.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [tfe_workspace.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace) | resource | +| [tfe_workspace_policy_set.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace_policy_set) | resource | +| [tfe_workspace_variable_set.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace_variable_set) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [name](#input\_name) | (Required) The name of the workspace. | `string` | n/a | yes | +| [description](#input\_description) | (Optional) A description to help you identify the workspace. | `string` | `"Managed by Terraform."` | no | +| [organization](#input\_organization) | (Optional) A name of the organization. If omitted, organization must be defined in the provider config. | `string` | `null` | no | +| [policy\_set](#input\_policy\_set) | (Optional) The ID of the policy set to configure. | `string` | `null` | no | +| [project](#input\_project) | (Optional) The ID of the project where the workspace should be created. | `string` | `null` | no | +| [variable\_set](#input\_variable\_set) | (Optional) A name of the variable set to configure. | `string` | `null` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [description](#output\_description) | The description of the workspace. | +| [id](#output\_id) | The ID of the workspace. | +| [name](#output\_name) | The name of the workspace. | +| [organization](#output\_organization) | The name of the organization. | +| [project](#output\_project) | The project which the workspace belongs to. | +| [statistics](#output\_statistics) | The statistics of the workspace. | +| [url](#output\_url) | The URL to the browsable HTML overview of the workspace. | + diff --git a/modules/workspace/main.tf b/modules/workspace/main.tf new file mode 100644 index 0000000..09c7578 --- /dev/null +++ b/modules/workspace/main.tf @@ -0,0 +1,35 @@ +################################################### +# Workspace in Terraform Enterprise +################################################### + +resource "tfe_workspace" "this" { + organization = var.organization + project_id = var.project + + name = var.name + description = var.description +} + + +################################################### +# Policy Set for Workspace +################################################### + +resource "tfe_workspace_policy_set" "this" { + count = var.policy_set != null ? 1 : 0 + + workspace_id = tfe_workspace.this.id + policy_set_id = var.policy_set +} + + +################################################### +# Variable Set for Workspace +################################################### + +resource "tfe_workspace_variable_set" "this" { + count = var.variable_set != null ? 1 : 0 + + workspace_id = tfe_workspace.this.id + variable_set_id = var.variable_set +} diff --git a/modules/workspace/outputs.tf b/modules/workspace/outputs.tf new file mode 100644 index 0000000..ada9dc0 --- /dev/null +++ b/modules/workspace/outputs.tf @@ -0,0 +1,54 @@ +output "id" { + description = "The ID of the workspace." + value = tfe_workspace.this.id +} + +output "organization" { + description = "The name of the organization." + value = tfe_workspace.this.organization +} + +output "project" { + description = "The project which the workspace belongs to." + value = { + id = tfe_workspace.this.project_id + } +} + +output "name" { + description = "The name of the workspace." + value = tfe_workspace.this.name +} + +output "description" { + description = "The description of the workspace." + value = tfe_workspace.this.description +} + +output "url" { + description = "The URL to the browsable HTML overview of the workspace." + value = tfe_workspace.this.html_url +} + +output "statistics" { + description = "The statistics of the workspace." + value = { + resource_count = tfe_workspace.this.resource_count + } +} + +# output "debug" { +# value = { +# for k, v in tfe_workspace.this : +# k => v +# if !contains(["name", "id", "organization", "description", "resource_count", "html_url", "project_id"], k) +# } +# } + +# output "debug2" { +# value = tfe_workspace_policy_set.this +# } +# +# output "debug3" { +# value = tfe_workspace_variable_set.this +# } diff --git a/modules/workspace/variables.tf b/modules/workspace/variables.tf new file mode 100644 index 0000000..2c518bb --- /dev/null +++ b/modules/workspace/variables.tf @@ -0,0 +1,44 @@ +variable "organization" { + description = "(Optional) A name of the organization. If omitted, organization must be defined in the provider config." + type = string + default = null + nullable = true +} + +variable "project" { + description = "(Optional) The ID of the project where the workspace should be created." + type = string + default = null + nullable = true +} + +variable "name" { + description = "(Required) The name of the workspace." + type = string + nullable = false +} + +variable "description" { + description = "(Optional) A description to help you identify the workspace." + type = string + default = "Managed by Terraform." + nullable = false +} + +variable "policy_set" { + description = <