Skip to content

Commit

Permalink
Add workspace module
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 committed May 2, 2024
1 parent 86c4adf commit 6e28da9
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 0 deletions.
57 changes: 57 additions & 0 deletions modules/workspace/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# workspace

This module creates following resources.

- `tfe_workspace`
- `tfe_workspace_policy_set` (optional)
- `tfe_workspace_variable_set` (optional)

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6 |
| <a name="requirement_tfe"></a> [tfe](#requirement\_tfe) | >= 0.53 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_tfe"></a> [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 |
|------|-------------|------|---------|:--------:|
| <a name="input_name"></a> [name](#input\_name) | (Required) The name of the workspace. | `string` | n/a | yes |
| <a name="input_description"></a> [description](#input\_description) | (Optional) A description to help you identify the workspace. | `string` | `"Managed by Terraform."` | no |
| <a name="input_organization"></a> [organization](#input\_organization) | (Optional) A name of the organization. If omitted, organization must be defined in the provider config. | `string` | `null` | no |
| <a name="input_policy_set"></a> [policy\_set](#input\_policy\_set) | (Optional) The ID of the policy set to configure. | `string` | `null` | no |
| <a name="input_project"></a> [project](#input\_project) | (Optional) The ID of the project where the workspace should be created. | `string` | `null` | no |
| <a name="input_variable_set"></a> [variable\_set](#input\_variable\_set) | (Optional) A name of the variable set to configure. | `string` | `null` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_description"></a> [description](#output\_description) | The description of the workspace. |
| <a name="output_id"></a> [id](#output\_id) | The ID of the workspace. |
| <a name="output_name"></a> [name](#output\_name) | The name of the workspace. |
| <a name="output_organization"></a> [organization](#output\_organization) | The name of the organization. |
| <a name="output_project"></a> [project](#output\_project) | The project which the workspace belongs to. |
| <a name="output_statistics"></a> [statistics](#output\_statistics) | The statistics of the workspace. |
| <a name="output_url"></a> [url](#output\_url) | The URL to the browsable HTML overview of the workspace. |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
35 changes: 35 additions & 0 deletions modules/workspace/main.tf
Original file line number Diff line number Diff line change
@@ -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
}
54 changes: 54 additions & 0 deletions modules/workspace/outputs.tf
Original file line number Diff line number Diff line change
@@ -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
# }
44 changes: 44 additions & 0 deletions modules/workspace/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = <<EOF
(Optional) The ID of the policy set to configure.
EOF
type = string
default = null
nullable = true
}

variable "variable_set" {
description = <<EOF
(Optional) A name of the variable set to configure.
EOF
type = string
default = null
nullable = true
}
10 changes: 10 additions & 0 deletions modules/workspace/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.6"

required_providers {
tfe = {
source = "hashicorp/tfe"
version = ">= 0.53"
}
}
}

0 comments on commit 6e28da9

Please # to comment.