Skip to content

Commit

Permalink
fix(runners): Fetch instance environment tag though metadata (philips…
Browse files Browse the repository at this point in the history
…-labs#2346)

Co-authored-by: Niek Palm <[email protected]>
  • Loading branch information
rasmus and npalm authored Sep 16, 2022
1 parent 7f3f4bf commit 27db290
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
9 changes: 9 additions & 0 deletions modules/runners/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Expand Down
5 changes: 1 addition & 4 deletions modules/runners/templates/start-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down

0 comments on commit 27db290

Please sign in to comment.