Skip to content

Commit

Permalink
Default include_component_in_workspace_name to false (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored Jan 21, 2021
1 parent ebcaa46 commit fb855bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 0 additions & 8 deletions modules/remote-state/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ locals {
backend_type = module.backend_config.backend_type
backend = module.backend_config.backend

workspace_from_environment_stage = var.include_component_in_workspace_name ? format("%s-%s-%s", module.this.environment, module.this.stage, var.component) : (
format("%s-%s", module.this.environment, module.this.stage)
)

workspace = var.workspace != null ? var.workspace : (
try(local.backend.workspace, null) != null ? local.backend.workspace : local.workspace_from_environment_stage
)

remote_states = {
s3 = data.terraform_remote_state.s3
remote = data.terraform_remote_state.remote
Expand Down
10 changes: 9 additions & 1 deletion modules/remote-state/remote.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
locals {
remote_workspace_from_environment_stage = format("%s-%s-%s", module.this.environment, module.this.stage, var.component)

remote_workspace = var.workspace != null ? var.workspace : (
try(local.backend.workspace, null) != null ? local.backend.workspace : local.remote_workspace_from_environment_stage
)
}

data "terraform_remote_state" "remote" {
count = local.backend_type == "remote" ? 1 : 0

Expand All @@ -7,7 +15,7 @@ data "terraform_remote_state" "remote" {
organization = local.backend.organization

workspaces = {
name = local.workspace
name = local.remote_workspace
}
}

Expand Down
12 changes: 11 additions & 1 deletion modules/remote-state/s3.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
locals {
s3_workspace_from_environment_stage = var.include_component_in_workspace_name ? format("%s-%s-%s", module.this.environment, module.this.stage, var.component) : (
format("%s-%s", module.this.environment, module.this.stage)
)

s3_workspace = var.workspace != null ? var.workspace : (
try(local.backend.workspace, null) != null ? local.backend.workspace : local.s3_workspace_from_environment_stage
)
}

data "terraform_remote_state" "s3" {
count = local.backend_type == "s3" ? 1 : 0

backend = "s3"

workspace = local.workspace
workspace = local.s3_workspace

config = {
encrypt = local.backend.encrypt
Expand Down
2 changes: 1 addition & 1 deletion modules/remote-state/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ variable "workspace" {
variable "include_component_in_workspace_name" {
type = bool
description = "Whether to include the component name in the workspace name"
default = true
default = false
}

0 comments on commit fb855bc

Please sign in to comment.