@@ -138,6 +138,28 @@ with lib; let
138138 groupMultivalueDnsAttrs = mkMultivalueDnsAttrs "groupRelayMultivalueDns" groupMultivalueDnsList ;
139139
140140 mkCustomRoute53Records = import ./cluster/route53.nix-import ;
141+
142+ sensitiveString = {
143+ type = "string" ;
144+ sensitive = true ;
145+ nullable = false ;
146+ } ;
147+
148+ defaultTags = {
149+ inherit
150+ ( infra . generic )
151+ environment
152+ function
153+ organization
154+ owner
155+ project
156+ repo
157+ tribe
158+ ;
159+
160+ # costCenter is saved as a secret
161+ costCenter = "\ ${var.${ infra . generic . costCenter } }" ;
162+ } ;
141163in {
142164 flake . opentofu . cluster = inputs . cardano-parts . inputs . terranix . lib . terranixConfiguration {
143165 inherit system ;
@@ -161,13 +183,19 @@ in {
161183 } ;
162184 } ;
163185
186+ variable = {
187+ # costCenter tag should remain secret in public repos
188+ "${ infra . generic . costCenter } " = sensitiveString ;
189+ } ;
190+
164191 provider . aws = forEach ( attrNames cluster . regions ) ( region : {
165192 inherit region ;
166193 alias = underscore region ;
167- default_tags . tags = {
168- inherit ( infra . generic ) organization tribe function repo ;
169- environment = "generic" ;
170- } ;
194+
195+ # Default tagging is inconsistent across aws resources, but including
196+ # it may help tag some resources that might have otherwise been
197+ # missed.
198+ default_tags . tags = defaultTags ;
171199 } ) ;
172200
173201 # Common parameters:
328356 gateway_id = "\ ${data.aws_internet_gateway.${ region } .id}" ;
329357 }
330358 ] ;
359+
360+ tags = defaultTags ;
331361 } ;
332362 }
333363 ) ;
350380 + " cidrsubnet(${ ipv6CidrBlock } , ${ toString ipv6SubnetCidrBits } - parseint(tolist(regex(\" /([0-9]+)$\" , ${ ipv6CidrBlock } ))[0], 10), each.key)}" ;
351381
352382 availability_zone = "\ ${each.value.availability_zone}" ;
383+ tags = defaultTags ;
353384 } ;
354385 } ) ;
355386
362393 ${ region } = {
363394 provider = awsProviderFor region ;
364395 assign_generated_ipv6_cidr_block = true ;
396+ tags = defaultTags ;
365397 } ;
366398 }
367399 ) ;
@@ -382,22 +414,22 @@ in {
382414 vpc_security_group_ids = [
383415 "\ ${aws_security_group.common_${ underscore region } [0].id}"
384416 ] ;
417+
418+ # Provider level `default_tags` are automatically inherited at
419+ # the instance level. Instance specific tags defined in
420+ # flake/colmena.nix are merged.
385421 tags = { Name = name ; } // node . aws . instance . tags or { } ;
386422
423+ # Using volume_tags ensures all created volumes get tagged.
424+ # Default tags are not inherited to the volume level automatically.
425+ volume_tags = defaultTags // { Name = name ; } // node . aws . instance . tags or { } ;
426+
387427 root_block_device = {
388428 inherit ( node . aws . instance . root_block_device ) volume_size ;
389429 volume_type = "gp3" ;
390430 iops = node . aws . instance . root_block_device . iops or 3000 ;
391431 throughput = node . aws . instance . root_block_device . throughput or 125 ;
392432 delete_on_termination = true ;
393- tags =
394- # Root block device tags aren't applied like the other
395- # resources since terraform-aws-provider v5.39.0.
396- #
397- # We need to strip the following tag attrs or tofu
398- # constantly tries to re-apply them.
399- { Name = name ; }
400- // removeAttrs ( node . aws . instance . tags or { } ) [ "organization" "tribe" "function" "repo" ] ;
401433 } ;
402434
403435 metadata_options = {
437469 aws_iam_instance_profile . ec2_profile = {
438470 name = "ec2Profile" ;
439471 role = "\ ${aws_iam_role.ec2_role.name}" ;
472+ tags = defaultTags ;
440473 } ;
441474
442475 aws_iam_role . ec2_role = {
451484 }
452485 ] ;
453486 } ;
487+
488+ tags = defaultTags ;
454489 } ;
455490
456491 aws_iam_role_policy_attachment = let
499534 }
500535 ] ;
501536 } ;
537+
538+ tags = defaultTags ;
502539 } ;
503540
504541 tls_private_key . bootstrap . algorithm = "ED25519" ;
@@ -512,13 +549,16 @@ in {
512549 provider = awsProviderFor region ;
513550 key_name = "bootstrap" ;
514551 public_key = "\ ${tls_private_key.bootstrap.public_key_openssh}" ;
552+ tags = defaultTags ;
515553 } ;
516554 } ) ;
517555
518556 aws_eip = mapNodes ( name : node : {
519557 inherit ( node . aws . instance ) count ;
520558 provider = awsProviderFor node . aws . region ;
521559 instance = "\ ${aws_instance.${ name } [0].id}" ;
560+
561+ # Provider level `default_tags` are automatically inherited.
522562 tags = { Name = name ; } // node . aws . instance . tags or { } ;
523563 } ) ;
524564
627667 protocol = "-1" ;
628668 } )
629669 ] ;
670+
671+ tags = defaultTags ;
630672 } ;
631673 } ) ;
632674
0 commit comments