Skip to content

Commit

Permalink
chore: use k8s backend for kubernetes resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonemms committed Sep 16, 2024
1 parent b5ffded commit adac989
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion stacks/dev/hetzner/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
}

include {
path = "../../common.hcl"
path = "../../tf-backend.hcl"
}

inputs = {
Expand Down
2 changes: 1 addition & 1 deletion stacks/dev/kubernetes/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
}

include {
path = "../../common.hcl"
path = "../../k8s-backend.hcl"
}

dependency "hetzner" {
Expand Down
36 changes: 36 additions & 0 deletions stacks/k8s-backend.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 Simon Emms <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

locals {
workspace = "infra-${basename(dirname(get_terragrunt_dir()))}-${reverse(split("/", get_terragrunt_dir()))[0]}"
}

inputs = {
workspace = local.workspace
}

# Use Kubernetes backend
generate "remote_state" {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
contents = <<EOF
terraform {
backend "kubernetes" {
secret_suffix = "state"
config_path = "~/.kube/config"
namespace = "kube-system"
}
}
EOF
}
2 changes: 1 addition & 1 deletion stacks/prod/hetzner/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
}

include {
path = "../../common.hcl"
path = "../../tf-backend.hcl"
}

inputs = {
Expand Down
2 changes: 1 addition & 1 deletion stacks/prod/kubernetes/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ terraform {
}

include {
path = "../../common.hcl"
path = "../../k8s-backend.hcl"
}

dependency "hetzner" {
Expand Down
16 changes: 1 addition & 15 deletions stacks/staging/hetzner/terragrunt.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Copyright 2024 Simon Emms <[email protected]>
#
# Licensed under the Apache gitLicense, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

terraform {
source = "../../../modules/${basename(get_terragrunt_dir())}"
}

include {
path = "../../common.hcl"
path = "../../tf-backend.hcl"
}

inputs = {
Expand Down
9 changes: 5 additions & 4 deletions stacks/common.hcl → stacks/tf-backend.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ locals {
workspace = "infra-${basename(dirname(get_terragrunt_dir()))}-${reverse(split("/", get_terragrunt_dir()))[0]}"
}

inputs = {
workspace = local.workspace
}

# Use Terraform cloud backend
generate "remote_state" {
path = "backend.tf"
if_exists = "overwrite_terragrunt"
Expand All @@ -33,7 +38,3 @@ terraform {
}
EOF
}

inputs = {
workspace = local.workspace
}

0 comments on commit adac989

Please sign in to comment.