Skip to content

Commit

Permalink
update to account for empty keys and for using native locking
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Sep 11, 2025
1 parent 4415901 commit 5908b7a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
13 changes: 10 additions & 3 deletions local-app/tf-directory-setup/remote_state.backend.tf.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
# version: 1.0.0
# version: 1.1.0

#---
# {{ data.account_alias }}: {{ data.directory }}
#---
{% set s3key = [ data.account_alias,data.directory,"terraform.tfstate"] | join("/") %}

terraform {
backend "s3" {
profile = "{{ data.profile }}"
bucket = "{{ data.bucket }}"
key = "{{ data.account_alias }}/{{ data.directory }}/terraform.tfstate"
key = "{{ s3key }}"
region = "{{ data.bucket_region }}"
dynamodb_table = "tf_remote_state"
{% if data.use_lockfile is defined and not data.use_lockfile %}
dynamodb_table = "{{ data.table_name | default('tf_remote_state') }}"
{% endif %}
{% if data.use_lockfile is defined %}
use_lockfile = {{ data.use_lockfile | default('false') | lower }}
{% endif %}
}
}
15 changes: 2 additions & 13 deletions local-app/tf-directory-setup/remote_state.data.tf.j2
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
# version: 1.0.0

## #---
## # {{ data.account_alias }}: {{ data.directory }}
## # local backend (bootstrapping)
## #---
## data "terraform_remote_state" "{{ data.directory_replaced }}" {
## backend = "local"
## config = {
## path = "../{{ data.directory }}/terraform.tfstate"
## }
## }
# version: 1.1.0

#---
# {{ data.account_alias }}: {{ data.directory }}
Expand All @@ -20,7 +9,7 @@ data "terraform_remote_state" "{{ data.directory_replaced }}" {
config = {
profile = var.profile
bucket = var.tfstate_bucket
key = "${var.tfstate_key_prefix}/{{ data.directory }}/${var.tfstate_key_suffix}"
key = join("/",compact([var.tfstate_key_prefix,{{ data.directory }},var.tfstate_key_suffix]))
region = var.tfstate_region
dynamodb_table = var.tfstate_table
}
Expand Down
4 changes: 2 additions & 2 deletions local-app/tf-directory-setup/remote_state.data.tf.s3.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# version: 1.0.0
# version: 1.1.0

#---
# {{ data.account_alias }}: {{ data.directory }}
Expand All @@ -9,7 +9,7 @@ data "terraform_remote_state" "{{ data.directory_replaced }}" {
config = {
profile = var.profile
bucket = var.tfstate_bucket
key = "${var.tfstate_key_prefix}/{{ data.directory }}/${var.tfstate_key_suffix}"
key = join("/",compact([var.tfstate_key_prefix,{{ data.directory }},var.tfstate_key_suffix]))
region = var.tfstate_region
dynamodb_table = var.tfstate_table
}
Expand Down

0 comments on commit 5908b7a

Please sign in to comment.