I was recently testing ChatGPT on terraform scripts and came across something that I can’t tell if it’s a GPT "cannon fodder" or if this is an undocumented feature.
On a trained ChatGPT session I input:
generate a bash script that can use random_pet resources from terraform
And this was the output:
#!/bin/bash
# Download metadata for the random_pet resource from the Terraform state file
metadata=$(curl -s http://169.254.169.254/latest/meta-data/attributes/terraform)
# Parse the metadata and extract the value of the "id" attribute
id=$(echo $metadata | jq -r '.random_pet_generator_id')
# Use the value of the "id" attribute in your Bash script
echo "Hello, $id!"
This looked bogus to me:
http://169.254.169.254/latest/meta-data/attributes/terraform
Until I read about Referring to Alternate Provider Configurations
2
Answers
@Marcin, I'm pretty sure that's not a real endpoint but hidden features are always a possibility. I ended up with:
foo.tf
bar.sh
I'm really curious how ChatGPT derived that endpoint. It definitely makes mistakes sometimes but even the mistakes are based on some element of truth.
There is no
terraform
value in EC2 metadata. For the valid values please check Instance metadata categories – Amazon Elastic Compute Cloud.