From 98287daeb37446bd6c0a18460496d3c8a6e761a5 Mon Sep 17 00:00:00 2001 From: Byungjin Park Date: Mon, 29 Apr 2024 17:38:36 +0900 Subject: [PATCH] Add project module --- modules/project/README.md | 53 ++++++++++++++++++++++++++++++++++++ modules/project/main.tf | 34 +++++++++++++++++++++++ modules/project/outputs.tf | 35 ++++++++++++++++++++++++ modules/project/variables.tf | 37 +++++++++++++++++++++++++ modules/project/versions.tf | 10 +++++++ 5 files changed, 169 insertions(+) create mode 100644 modules/project/README.md create mode 100644 modules/project/main.tf create mode 100644 modules/project/outputs.tf create mode 100644 modules/project/variables.tf create mode 100644 modules/project/versions.tf diff --git a/modules/project/README.md b/modules/project/README.md new file mode 100644 index 0000000..b92e0c5 --- /dev/null +++ b/modules/project/README.md @@ -0,0 +1,53 @@ +# project + +This module creates following resources. + +- `tfe_project` +- `tfe_project_policy_set` (optional) +- `tfe_project_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_project.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/project) | resource | +| [tfe_project_policy_set.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/project_policy_set) | resource | +| [tfe_project_variable_set.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/project_variable_set) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [name](#input\_name) | (Required) The name of the project. | `string` | n/a | yes | +| [description](#input\_description) | (Optional) A description to help you identify the project. | `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 | +| [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 project. | +| [id](#output\_id) | The ID of the project. | +| [name](#output\_name) | The name of the project. | +| [organization](#output\_organization) | The name of the organization. | + diff --git a/modules/project/main.tf b/modules/project/main.tf new file mode 100644 index 0000000..d27eeaf --- /dev/null +++ b/modules/project/main.tf @@ -0,0 +1,34 @@ +################################################### +# Project in Terraform Enterprise +################################################### + +resource "tfe_project" "this" { + organization = var.organization + + name = var.name + description = var.description +} + + +################################################### +# Policy Set for Project +################################################### + +resource "tfe_project_policy_set" "this" { + count = var.policy_set != null ? 1 : 0 + + project_id = tfe_project.this.id + policy_set_id = var.policy_set +} + + +################################################### +# Variable Set for Project +################################################### + +resource "tfe_project_variable_set" "this" { + count = var.variable_set != null ? 1 : 0 + + project_id = tfe_project.this.id + variable_set_id = var.variable_set +} diff --git a/modules/project/outputs.tf b/modules/project/outputs.tf new file mode 100644 index 0000000..fd78228 --- /dev/null +++ b/modules/project/outputs.tf @@ -0,0 +1,35 @@ +output "id" { + description = "The ID of the project." + value = tfe_project.this.id +} + +output "organization" { + description = "The name of the organization." + value = tfe_project.this.organization +} + +output "name" { + description = "The name of the project." + value = tfe_project.this.name +} + +output "description" { + description = "The description of the project." + value = tfe_project.this.description +} + +# output "debug" { +# value = { +# for k, v in tfe_project.this : +# k => v +# if !contains(["name", "id", "organization", "description"], k) +# } +# } + +# output "debug2" { +# value = tfe_project_policy_set.this +# } +# +# output "debug3" { +# value = tfe_project_variable_set.this +# } diff --git a/modules/project/variables.tf b/modules/project/variables.tf new file mode 100644 index 0000000..761ca0b --- /dev/null +++ b/modules/project/variables.tf @@ -0,0 +1,37 @@ +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 "name" { + description = "(Required) The name of the project." + type = string + nullable = false +} + +variable "description" { + description = "(Optional) A description to help you identify the project." + type = string + default = "Managed by Terraform." + nullable = false +} + +variable "policy_set" { + description = <