diff --git a/modules/runners/main.tf b/modules/runners/main.tf index 80eed67c..76bf3a70 100644 --- a/modules/runners/main.tf +++ b/modules/runners/main.tf @@ -81,6 +81,15 @@ resource "aws_launch_template" "runner" { http_endpoint = metadata_options.value.http_endpoint http_tokens = metadata_options.value.http_tokens http_put_response_hop_limit = metadata_options.value.http_put_response_hop_limit + instance_metadata_tags = "enabled" + } + } + + dynamic "metadata_options" { + for_each = var.metadata_options != null ? [] : [0] + + content { + instance_metadata_tags = "enabled" } } diff --git a/modules/runners/templates/start-runner.sh b/modules/runners/templates/start-runner.sh index 6d7994a9..9dedb6a8 100644 --- a/modules/runners/templates/start-runner.sh +++ b/modules/runners/templates/start-runner.sh @@ -11,10 +11,7 @@ echo "Retrieved REGION from AWS API ($region)" instance_id=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/instance-id) echo "Retrieved INSTANCE_ID from AWS API ($instance_id)" -tags=$(aws ec2 describe-tags --region "$region" --filters "Name=resource-id,Values=$instance_id") -echo "Retrieved tags from AWS API ($tags)" - -environment=$(echo "$tags" | jq -r '.Tags[] | select(.Key == "ghr:environment") | .Value') +environment=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/tags/instance/ghr:environment) echo "Retrieved ghr:environment tag - ($environment)" parameters=$(aws ssm get-parameters-by-path --path "/$environment/runner" --region "$region" --query "Parameters[*].{Name:Name,Value:Value}")