Skip to content

Commit

Permalink
Remove state file retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKotowick committed Jul 30, 2021
1 parent 0f4afe2 commit 1ac8ecb
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 118 deletions.
32 changes: 0 additions & 32 deletions local.tf

This file was deleted.

27 changes: 1 addition & 26 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,12 @@ locals {
backend = local.backend_found ? lookup(local.backend_contents, "backend", null) : null
backend_configured = local.backend != null
workspace = fileexists(local.workspace_path) ? file(local.workspace_path) : null
supported_backends = [
"s3",
"local"
]
}

// Fetch the state, if desired
data "terraform_remote_state" "state" {
count = local.backend_configured && var.fetch_output_state ? 1 : 0
count = local.backend_configured && var.fetch_remote_state ? 1 : 0
backend = local.backend.type
config = local.backend.config
workspace = local.workspace
}

// Ensure that the backend type is supported
module "assert_valid_backend" {
source = "Invicton-Labs/assertion/null"
version = "0.1.2"
condition = var.fetch_raw_state && local.backend_configured ? contains(local.supported_backends, local.backend.type) : true
error_message = local.backend_configured ? "The '${local.backend.type}' backend type is not supported for the 'Invicton-Labs/backend-config/null' module." : null
}

locals {
raw_states = [
local.default_state,
local.s3_state
]
non_null_raw_states = [
for state in local.raw_states :
state
if state != null
]
raw_state = length(local.non_null_raw_states) > 0 ? local.non_null_raw_states[0] : null
}
9 changes: 2 additions & 7 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ output "workspace" {
value = local.workspace
}

output "output_state" {
description = "The current (pre-apply) Terraform state of this configuration, as provided by the `terraform_remote_state` data source. If no backend is configured or the `fetch_output_state` variable is set to `false`, this value will be `null`."
output "remote_state" {
description = "The current (pre-apply) Terraform state of this configuration, as provided by the `terraform_remote_state` data source. If no backend is configured or the `fetch_remote_state` variable is set to `false`, this value will be `null`."
value = length(data.terraform_remote_state.state) > 0 ? data.terraform_remote_state.state[0].outputs : null
}

output "raw_state" {
description = "The raw, current (pre-apply) Terraform state of this configuration, as stored in the terraform.tfstate file (or remote equivalent). If no backend is configured or the `fetch_raw_state` variable is set to `false`, this value will be `null`."
value = local.raw_state
}
46 changes: 0 additions & 46 deletions s3.tf

This file was deleted.

8 changes: 1 addition & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@ variable "working_dir" {
default = null
}

variable "fetch_output_state" {
variable "fetch_remote_state" {
description = "Whether the current (pre-apply) Terraform state of this configuration should be retrieved, as provided by the `terraform_remote_state` data source."
type = bool
default = false
}

variable "fetch_raw_state" {
description = "Whether the raw, current (pre-apply) Terraform state of this configuration should be retrieved, as stored in the terraform.tfstate file (or remote equivalent)."
type = bool
default = false
}

0 comments on commit 1ac8ecb

Please sign in to comment.