Skip to content

Commit 5f5331f

Browse files
committed
revert label modules to avoid resource replacement
1 parent 7fd92a4 commit 5f5331f

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
8585
| <a name="module_asg_label"></a> [asg\_label](#module\_asg\_label) | cloudposse/label/null | 0.25.0 |
8686
| <a name="module_kms_key"></a> [kms\_key](#module\_kms\_key) | cloudposse/kms-key/aws | 0.12.1 |
8787
| <a name="module_logs_bucket"></a> [logs\_bucket](#module\_logs\_bucket) | cloudposse/s3-bucket/aws | 0.40.1 |
88+
| <a name="module_logs_label"></a> [logs\_label](#module\_logs\_label) | cloudposse/label/null | 0.25.0 |
89+
| <a name="module_role_label"></a> [role\_label](#module\_role\_label) | cloudposse/label/null | 0.25.0 |
8890
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
8991

9092
## Resources
@@ -131,7 +133,6 @@ Use [the awesome `gossm` project](https://github.com/gjbae1212/gossm).
131133
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
132134
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
133135
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
134-
| <a name="input_max_instance_lifetime"></a> [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | Maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 86400 and 31536000 seconds. | `number` | `0` | no |
135136
| <a name="input_name"></a> [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.<br>This is the only ID element not also included as a `tag`.<br>The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
136137
| <a name="input_namespace"></a> [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
137138
| <a name="input_permissions_boundary"></a> [permissions\_boundary](#input\_permissions\_boundary) | The ARN of the permissions boundary that will be applied to the SSM Agent role. | `string` | `""` | no |

main.tf

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ module "asg_label" {
22
source = "cloudposse/label/null"
33
version = "0.25.0"
44

5-
context = module.this.context
5+
context = module.this.context
6+
attributes = compact(concat(["asg"], var.attributes))
67

78
# This tag attribute is required.
89
# See https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group#propagate_at_launch
@@ -11,11 +12,27 @@ module "asg_label" {
1112
}
1213
}
1314

15+
module "role_label" {
16+
source = "cloudposse/label/null"
17+
version = "0.25.0"
18+
19+
context = module.this.context
20+
attributes = compact(concat(["role"], var.attributes))
21+
}
22+
23+
module "logs_label" {
24+
source = "cloudposse/label/null"
25+
version = "0.25.0"
26+
27+
context = module.this.context
28+
attributes = compact(concat(["logs"], var.attributes))
29+
}
30+
1431
locals {
1532
region = coalesce(var.region, data.aws_region.current.name)
1633
account_id = data.aws_caller_identity.current.account_id
1734

18-
session_logging_bucket_name = try(coalesce(var.session_logging_bucket_name, "${module.this.id}-logs"), "")
35+
session_logging_bucket_name = try(coalesce(var.session_logging_bucket_name, module.logs_label.id), "")
1936
session_logging_kms_key_arn = try(coalesce(var.session_logging_kms_key_arn, module.kms_key.key_arn), "")
2037

2138
logs_bucket_enabled = var.session_logging_enabled && length(var.session_logging_bucket_name) == 0
@@ -88,10 +105,10 @@ data "aws_iam_policy_document" "session_logging" {
88105
}
89106

90107
resource "aws_iam_role" "default" {
91-
name = module.this.id
108+
name = module.role_label.id
92109
assume_role_policy = data.aws_iam_policy_document.default.json
93110
permissions_boundary = var.permissions_boundary
94-
tags = module.this.tags
111+
tags = module.role_label.tags
95112
}
96113

97114
resource "aws_iam_role_policy_attachment" "default" {
@@ -102,13 +119,13 @@ resource "aws_iam_role_policy_attachment" "default" {
102119
resource "aws_iam_role_policy" "session_logging" {
103120
count = var.session_logging_enabled ? 1 : 0
104121

105-
name = module.this.id
122+
name = "${module.role_label.id}-session-logging"
106123
role = aws_iam_role.default.name
107124
policy = join("", data.aws_iam_policy_document.session_logging.*.json)
108125
}
109126

110127
resource "aws_iam_instance_profile" "default" {
111-
name = module.this.id
128+
name = module.role_label.id
112129
role = aws_iam_role.default.name
113130
}
114131

@@ -141,7 +158,7 @@ module "kms_key" {
141158
version = "0.12.1"
142159

143160
enabled = var.session_logging_enabled && var.session_logging_encryption_enabled && length(var.session_logging_kms_key_arn) == 0
144-
context = module.this.context
161+
context = module.logs_label.context
145162

146163
description = "KMS key for encrypting Session Logs in S3 and CloudWatch."
147164
deletion_window_in_days = 10
@@ -151,7 +168,7 @@ module "kms_key" {
151168
policy = <<DOC
152169
{
153170
"Version" : "2012-10-17",
154-
"Id" : "${module.this.id}",
171+
"Id" : "${module.logs_label.id}-policy",
155172
"Statement" : [
156173
{
157174
"Sid" : "Enable IAM User Permissions",
@@ -177,7 +194,7 @@ module "kms_key" {
177194
"Resource": "*",
178195
"Condition": {
179196
"ArnLike": {
180-
"kms:EncryptionContext:aws:logs:arn": "arn:aws:logs:${local.region}:${local.account_id}:log-group:${module.this.id}"
197+
"kms:EncryptionContext:aws:logs:arn": "arn:aws:logs:${local.region}:${local.account_id}:log-group:${module.logs_label.id}"
181198
}
182199
}
183200
}
@@ -191,9 +208,7 @@ module "logs_bucket" {
191208
version = "0.40.1"
192209

193210
enabled = local.logs_bucket_enabled
194-
context = module.this.context
195-
196-
bucket_name = local.session_logging_bucket_name
211+
context = module.logs_label.context
197212

198213
# Encryption / Security
199214
acl = "private"
@@ -233,18 +248,18 @@ module "logs_bucket" {
233248
resource "aws_cloudwatch_log_group" "session_logging" {
234249
count = var.session_logging_enabled ? 1 : 0
235250

236-
name = module.this.id
251+
name = module.logs_label.id
237252
retention_in_days = var.cloudwatch_retention_in_days
238253
kms_key_id = var.session_logging_encryption_enabled ? local.session_logging_kms_key_arn : ""
239-
tags = module.this.tags
254+
tags = module.logs_label.tags
240255
}
241256

242257
resource "aws_ssm_document" "session_logging" {
243258
count = var.session_logging_enabled && var.create_run_shell_document ? 1 : 0
244259

245260
name = var.session_logging_ssm_document_name
246261
document_type = "Session"
247-
tags = module.this.tags
262+
tags = module.logs_label.tags
248263
content = <<DOC
249264
{
250265
"schemaVersion": "1.0",
@@ -305,18 +320,17 @@ resource "aws_launch_template" "default" {
305320
}
306321

307322
resource "aws_autoscaling_group" "default" {
308-
name_prefix = module.this.id
323+
name_prefix = module.asg_label.id
309324
tags = module.asg_label.tags_as_list_of_maps
310325

311326
launch_template {
312327
id = aws_launch_template.default.id
313328
version = "$Latest"
314329
}
315330

316-
max_size = var.instance_count
317-
min_size = var.instance_count
318-
desired_capacity = var.instance_count
319-
max_instance_lifetime = var.max_instance_lifetime
331+
max_size = var.instance_count
332+
min_size = var.instance_count
333+
desired_capacity = var.instance_count
320334

321335
vpc_zone_identifier = var.subnet_ids
322336

variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ variable "additional_security_group_ids" {
6262
default = []
6363
}
6464

65-
variable "max_instance_lifetime" {
66-
description = "Maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 86400 and 31536000 seconds."
67-
type = number
68-
default = 0
69-
}
70-
7165
######################
7266
## SESSION LOGGING ##
7367
####################

0 commit comments

Comments
 (0)