Skip to content

Commit

Permalink
Merge pull request #3 from dasmeta/DMVP-2230-project
Browse files Browse the repository at this point in the history
fix(DMVP-2230): Added project resource
  • Loading branch information
viktoryathegreat authored Apr 7, 2023
2 parents c7a217c + 6edf7a1 commit dfb190d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ No modules.
| Name | Type |
|------|------|
| [local_file.this](https://registry.terraform.io/providers/hashicorp/local/latest/docs/resources/file) | resource |
| [tfe_project.project](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/project) | resource |
| [tfe_workspace.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace) | resource |
| [tfe_workspace_variable_set.this](https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/resources/workspace_variable_set) | resource |

Expand All @@ -63,7 +64,7 @@ No modules.
| <a name="input_terraform_backend"></a> [terraform\_backend](#input\_terraform\_backend) | Allows to set terraform backend configurations | <pre>object({<br> name = string<br> configs = optional(any, {})<br> })</pre> | <pre>{<br> "configs": null,<br> "name": null<br>}</pre> | no |
| <a name="input_terraform_version"></a> [terraform\_version](#input\_terraform\_version) | The required\_version variable value for terraform{} block in versions.tf | `string` | `">= 1.3.0"` | no |
| <a name="input_variable_set_ids"></a> [variable\_set\_ids](#input\_variable\_set\_ids) | The list of variable set ids to attach to workspace | `list(string)` | `null` | no |
| <a name="input_workspace"></a> [workspace](#input\_workspace) | Terraform cloud workspace configurations | <pre>object({<br> org = string<br> tags = optional(list(string), null)<br> description = optional(string, null)<br> directory = optional(string, "./") # this seems supposed to be the root directory of git repo<br> global_remote_state = optional(bool, true) # allow org workspaces access to this workspace state, TODO: there is a way to implement specific workspaces whitelisting using remote_state_consumer_ids, needs apply and testing<br><br> })</pre> | n/a | yes |
| <a name="input_workspace"></a> [workspace](#input\_workspace) | Terraform cloud workspace configurations | <pre>object({<br> org = string<br> tags = optional(list(string), null)<br> description = optional(string, null)<br> directory = optional(string, "./") # this seems supposed to be the root directory of git repo<br> global_remote_state = optional(bool, true) # allow org workspaces access to this workspace state, TODO: there is a way to implement specific workspaces whitelisting using remote_state_consumer_ids, needs apply and testing<br> project = optional(string, null) # name of the project to be created and where the workspace should be created<br> project_id = optional(string, null) # ID of the project which already exists, if none of project and project_id is provided Default Project is used for storing workspaces<br> })</pre> | n/a | yes |

## Outputs

Expand Down
41 changes: 41 additions & 0 deletions git-conventional-commits.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"convention" : {
"commitTypes": [
"feat",
"fix",
"perf",
"refactor",
"style",
"test",
"build",
"ops",
"docs",
"merge",
"chore"
],
"commitScopes": [],
"releaseTagGlobPattern": "v[0-9]*.[0-9]*.[0-9]*",
"issueRegexPattern": "(^|\\s)#\\d+(\\s|$)"
},
"changelog" : {
"commitTypes": [
"feat",
"fix",
"perf",
"merge"
],
"includeInvalidCommits": true,
"commitScopes": [],
"commitIgnoreRegexPattern": "^WIP ",
"headlines": {
"feat": "Features",
"fix": "Bug Fixes",
"perf": "Performance Improvements",
"merge": "Merged Branches",
"breakingChange": "BREAKING CHANGES"
},
"commitUrl": "https://github.com/ACCOUNT/REPOSITORY/commit/%commit%",
"commitRangeUrl": "https://github.com/ACCOUNT/REPOSITORY/compare/%from%...%to%?diff=split",
"issueUrl": "https://github.com/ACCOUNT/REPOSITORY/issues/%issue%"
}
}
5 changes: 3 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
locals {
name_specials_clean = replace(var.name, "/\\W+/", "_")
linked_workspaces_mapping = { for workspace in coalesce(var.linked_workspaces, []) : workspace => "data.tfe_outputs.this[\"${workspace}\"].values.results" }
name_specials_clean = replace(var.name, "/[^a-zA-Z0-9_-]+/", "_")
project_name_specials_clean = var.workspace.project != null ? replace(var.workspace.project, "/[^a-zA-Z0-9 _-]+/", "") : null
linked_workspaces_mapping = { for workspace in coalesce(var.linked_workspaces, []) : workspace => "data.tfe_outputs.this[\"${workspace}\"].values.results" }
main_content = templatefile(
"${path.module}/templates/main.tftpl",
{
Expand Down
11 changes: 9 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ resource "local_file" "this" {
filename = "${trimsuffix(var.target_dir, "/")}/${var.name}/${each.value.name}.tf"
}

resource "tfe_project" "project" {
count = var.workspace.project != null ? 1 : 0

organization = var.workspace.org
name = local.project_name_specials_clean
}

resource "tfe_workspace" "this" {
name = local.name_specials_clean
description = var.workspace.description
organization = var.workspace.org
tag_names = var.workspace.tags
global_remote_state = var.workspace.global_remote_state

working_directory = "${var.workspace.directory}${var.name}"
project_id = try(tfe_project.project[0].id, var.workspace.project_id)
working_directory = "${var.workspace.directory}${var.name}"

dynamic "vcs_repo" {
for_each = try(var.repo.identifier, null) == null ? [] : [var.repo]
Expand Down
3 changes: 1 addition & 2 deletions tests/yaml-conf-and-workspace-link/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
the TF_VAR_github_token and GITHUB_TOKEN are same and contain user github personal access token, check the docs here:
https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token


for TFE_TOKEN check the docs here:
https://registry.terraform.io/providers/hashicorp/tfe/latest/docs

Expand Down Expand Up @@ -40,7 +39,7 @@ for aws access tokens you will need to have a user having api/cli access to crea
| Name | Version |
|------|---------|
| <a name="provider_test"></a> [test](#provider\_test) | n/a |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | 0.40.0 |
| <a name="provider_tfe"></a> [tfe](#provider\_tfe) | ~> 0.40.0 |

## Modules

Expand Down
3 changes: 2 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ variable "workspace" {
description = optional(string, null)
directory = optional(string, "./") # this seems supposed to be the root directory of git repo
global_remote_state = optional(bool, true) # allow org workspaces access to this workspace state, TODO: there is a way to implement specific workspaces whitelisting using remote_state_consumer_ids, needs apply and testing

project = optional(string, null) # name of the project to be created and where the workspace should be created
project_id = optional(string, null) # ID of the project which already exists, if none of project and project_id is provided Default Project is used for storing workspaces
})

description = "Terraform cloud workspace configurations"
Expand Down

0 comments on commit dfb190d

Please sign in to comment.