Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixed resource naming #2

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/all-labels/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module "example" {
source = "../.."

tenant = "t"
namespace = "ns"
environment = "env"
stage = "st"
name = "nm"
attributes = ["a1", "a2"]
label_value_case = "none" # only for keeping case
redis_ecs_cluster_arn = "arn:aws:ecs:eu-central-1:123456789123:cluster/my-cluster"
redis_service_discovery_dns_namespace_id = "ns-ab12c34defghij5k"
}
Empty file added examples/all-labels/outputs.tf
Empty file.
3 changes: 3 additions & 0 deletions examples/all-labels/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
provider "aws" {
region = "eu-central-1"
}
Empty file.
10 changes: 10 additions & 0 deletions examples/all-labels/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.45.0"
}
}

required_version = "1.3.6"
}
14 changes: 8 additions & 6 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
locals {
redis_container_name = "redis"
has_additional_attributes = length(var.attributes) > 1
redis_container_name = "redis"
}

# can't just pull in the context here because the attributes add up instead of being replaced by the input
Expand Down Expand Up @@ -31,14 +32,15 @@ module "redis_label" {
version = "0.25.0"

context = module.ddb_label.context
attributes = concat(["kvstore_${try(var.attributes[0], "")}"], local.has_additional_attributes ? slice(var.attributes, 1, length(var.attributes)) : [])
label_order = var.redis_label_order
}

module "ddb" {
source = "github.com/justtrackio/terraform-aws-dynamodb-table?ref=v1.0.0"

context = module.ddb_label.context
attributes = ["kvstore-${join("", var.attributes)}"]
attributes = concat(["kvstore-${try(var.attributes[0], "")}"], local.has_additional_attributes ? slice(var.attributes, 1, length(var.attributes)) : [])

billing_mode = var.ddb_billing_mode

Expand All @@ -55,7 +57,7 @@ module "ddb" {
ttl_enabled = false

tags = {
Model = "kvstore_${join("", var.attributes)}"
Model = "kvstore_${try(var.attributes[0], "")}"
}
}

Expand Down Expand Up @@ -96,7 +98,7 @@ module "redis" {
desired_count = var.redis_desired_count
ecs_cluster_arn = var.redis_ecs_cluster_arn
launch_type = var.redis_launch_type
name = "${module.redis_label[0].id}-redis-kvstore_${join("", var.attributes)}"
name = "${var.name}${module.this.delimiter}redis"
network_mode = var.redis_network_mode
propagate_tags = var.redis_propagate_tags
vpc_id = var.redis_vpc_id
Expand All @@ -108,7 +110,7 @@ module "redis" {
}]

tags = {
Model = "kvstore_${join("", var.attributes)}"
Model = "kvstore_${try(var.attributes[0], "")}"
ApplicationType = "redis"
}

Expand All @@ -120,7 +122,7 @@ module "redis" {

resource "aws_service_discovery_service" "this" {
count = var.use_redis ? 1 : 0
name = "kvstore_${join("", var.attributes)}.${module.this.name}.redis"
name = "kvstore_${try(var.attributes[0], "")}.${module.this.name}.redis"

dns_config {
namespace_id = var.redis_service_discovery_dns_namespace_id
Expand Down