Skip to content

Commit 44ca98c

Browse files
committed
tagging: tofu resource updates
1 parent 6b163bd commit 44ca98c

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

flake/cluster.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ with flake.lib; {
3434
function = "cardano-parts";
3535
repo = "https://github.com/input-output-hk/cardano-playground";
3636

37+
owner = "ioe";
38+
environment = "testnets";
39+
project = "cardano-playground";
40+
41+
# This is the tf var secrets name
42+
costCenter = "tag_costCenter";
43+
3744
# These options must remain true for the playground cluster as ip info is required
3845
abortOnMissingIpModule = true;
3946
warnOnMissingIpModule = true;

flake/colmena.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ in
5858

5959
# Since all machines are assigned a group, this is a good place to include default aws instance tags
6060
aws.instance.tags = {
61-
inherit (cfgGeneric) organization tribe function repo;
61+
# This group environment name will override the
62+
# flake.cluster.infra.generic environment name for aws instances.
6263
environment = config.flake.cardano-parts.cluster.groups.${name}.meta.environmentName;
6364
group = name;
6465
};

flake/opentofu/cluster.nix

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
};
141163
in {
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:
@@ -328,6 +356,8 @@ in {
328356
gateway_id = "\${data.aws_internet_gateway.${region}.id}";
329357
}
330358
];
359+
360+
tags = defaultTags;
331361
};
332362
}
333363
);
@@ -350,6 +380,7 @@ in {
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

@@ -362,6 +393,7 @@ in {
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 = {
@@ -437,6 +469,7 @@ in {
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 = {
@@ -451,6 +484,8 @@ in {
451484
}
452485
];
453486
};
487+
488+
tags = defaultTags;
454489
};
455490

456491
aws_iam_role_policy_attachment = let
@@ -499,6 +534,8 @@ in {
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

@@ -627,6 +667,8 @@ in {
627667
protocol = "-1";
628668
})
629669
];
670+
671+
tags = defaultTags;
630672
};
631673
});
632674

secrets/tf/cluster.tfvars

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"data": "ENC[AES256_GCM,data:yUKRMJYqndqoso8X0fePrUAKV795AfpX2A==,iv:wX8mTXgj0l8lPI+If+GxYjvjiytkFMF+vWyXjHiwHfM=,tag:z04eAemWLBZdx5jJS3LEBg==,type:str]",
3+
"sops": {
4+
"age": [
5+
{
6+
"recipient": "age1rj7vaq0rsarnum2fx6zq0k3l64f6mca9t9mlhqu4nfvpqhux6uts5zud2m",
7+
"enc": "-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB0LzR0ai9vU013MjhSdEtR\neklsWGZ0b2FIclZxMEovTWFENWhRQXQwcWgwCmlma09ESlJscG9Sb0wzVmkwQTll\nOWNNcWpXOVhObzlGckxsaVYvVDlCU0kKLS0tIEIva1pZdGkxbjRNOUFSbC9iMC9B\nUTF5QVl0aHAwRjZtR1RJTGhLdkl4OHMKlEL+knVa0NjGKDH/bqBGavjdzOMQHq4X\nHRVcIRGo4spB73zV0iBtN8jbYIjF0FSIkQEJDzLH19zeIgjr/5MWsw==\n-----END AGE ENCRYPTED FILE-----\n"
8+
}
9+
],
10+
"lastmodified": "2025-11-06T23:32:11Z",
11+
"mac": "ENC[AES256_GCM,data:fwjB0ICWhWH1+MFPzwddSqGVxHS5TFbWM5vSk5EZRpEW3G09UA0gHFhqPrnlb3V16ghZRtPTvj0xL5FMu1/7Gjj+jd9L1w0Crm7jPHSVkEs+3vOH+BI97ij/QfTrYlK0UoFV2ak+ZK0uDlHMh/K2qRcdIX1414bZEnjz6KWCPZk=,iv:vjZtax9ndd+JqZBcaVTe9IJZEbFQP5YCKiFOb7mdpQY=,tag:sBgDkV3qQXNfqyv+Ep8FyA==,type:str]",
12+
"unencrypted_suffix": "_unencrypted",
13+
"version": "3.10.2"
14+
}
15+
}

0 commit comments

Comments
 (0)