diff --git a/README.md b/README.md index 3134834..967534d 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -63,7 +64,7 @@ No modules. | [terraform\_backend](#input\_terraform\_backend) | Allows to set terraform backend configurations |
object({|
name = string
configs = optional(any, {})
})
{| no | | [terraform\_version](#input\_terraform\_version) | The required\_version variable value for terraform{} block in versions.tf | `string` | `">= 1.3.0"` | no | | [variable\_set\_ids](#input\_variable\_set\_ids) | The list of variable set ids to attach to workspace | `list(string)` | `null` | no | -| [workspace](#input\_workspace) | Terraform cloud workspace configurations |
"configs": null,
"name": null
}
object({| n/a | yes | +| [workspace](#input\_workspace) | Terraform cloud workspace configurations |
org = string
tags = optional(list(string), null)
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
})
object({| n/a | yes | ## Outputs diff --git a/git-conventional-commits.json b/git-conventional-commits.json new file mode 100644 index 0000000..009fca5 --- /dev/null +++ b/git-conventional-commits.json @@ -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%" + } +} diff --git a/locals.tf b/locals.tf index 4de5f9f..a374083 100644 --- a/locals.tf +++ b/locals.tf @@ -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", { diff --git a/main.tf b/main.tf index 4312a36..f8fb0a4 100644 --- a/main.tf +++ b/main.tf @@ -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] diff --git a/tests/yaml-conf-and-workspace-link/README.md b/tests/yaml-conf-and-workspace-link/README.md index cacbedd..8d69c6b 100644 --- a/tests/yaml-conf-and-workspace-link/README.md +++ b/tests/yaml-conf-and-workspace-link/README.md @@ -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 @@ -40,7 +39,7 @@ for aws access tokens you will need to have a user having api/cli access to crea | Name | Version | |------|---------| | [test](#provider\_test) | n/a | -| [tfe](#provider\_tfe) | 0.40.0 | +| [tfe](#provider\_tfe) | ~> 0.40.0 | ## Modules diff --git a/variables.tf b/variables.tf index 4c231a8..7eeed9a 100644 --- a/variables.tf +++ b/variables.tf @@ -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"
org = string
tags = optional(list(string), null)
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
})