The following code gives me a list of all EC2 instances that are part of my cluster:
data "aws_instances" "emrMaster" {
instance_tags {
Name = "emr-cluster-name"
}
}
But when I try to narrow the list using the AWS generated tag for the master instance, I get the same list.
data "aws_instances" "emrMaster" {
instance_tags {
Name = "emr-cluster-name"
"aws:elasticmapreduce:instance-group-role" = "MASTER"
}
}
If I remove the quotes on the key name, I get a illegal character error due to the colons in the key name.
data "aws_instances" "emrMaster" {
instance_tags {
Name = "emr-cluster-name"
aws:elasticmapreduce:instance-group-role = "MASTER"
}
}
Is there a better way to do this, am I doing something wrong, or have I uncovered a bug in Terraform?
I am using Terraform v0.11.7
I am looking to capture this value so I can build specific cloudwatch alerts for the master instance that are different from the Core instances.
For this purpose better use aws_instance (not aws_instances)
resource "aws_emr_cluster" "emr-cluster" {
....
}
data "aws_instance" "master" {
filter {
name = "tag:Name"
values = ["${aws_emr_cluster.emr-cluster.name}"]
}
filter {
name = "tag:aws:elasticmapreduce:instance-group-role"
values = ["MASTER"]
}
}
And then just use output:
output "master_id" {
value = "${data.aws_instance.master.id}"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With