Skip to content

Pinning generated resource IDs ​

A create-time tag, gopherstack:id, pins the ID a resource would otherwise get at random. Real AWS ignores unknown tags, so the same IaC works against both. The LocalStack tag _custom_id_ is accepted as an alias.

Rules ​

  • Honoured only on the create call. The tag is consumed: it is not stored and does not appear in List*Tags, Describe* tag sets or the create response.
  • A value that does not match the resource's ID format is rejected with the service's validation error naming the expected format.
  • A value already in use is rejected with the service's already-exists or conflict error.
  • Tagging an existing resource with gopherstack:id is rejected.

Supported resources ​

ServiceCreate callPinned valueFormat
EC2RunInstances (one instance)Instance ID, TagSpecification type instancei- + 8 or 17 lowercase hex
EC2CreateVpcVPC ID, type vpcvpc- + 8 or 17 lowercase hex
EC2CreateSubnetSubnet ID, type subnetsubnet- + 8 or 17 lowercase hex
EC2CreateSecurityGroupGroup ID, type security-groupsg- + 8 or 17 lowercase hex
ECSRunTask (one task)Task ID32 hex digits (UUID dashes allowed)
API GatewayCreateRestApiREST API ID1-32 lowercase alphanumerics or hyphens
API Gateway v2CreateApiAPI ID1-32 lowercase alphanumerics or hyphens
CognitoCreateUserPool (UserPoolTags)User pool ID<region>_ + alphanumerics
CognitoCreateUserPoolClientClient ID, via client name _custom_id_:<id>[\w+]{1,128}
Secrets ManagerCreateSecretARN suffix6 alphanumerics
KMSCreateKeyKey IDLowercase UUID, or mrk- + 32 hex when MultiRegion
CloudFrontCreateDistributionWithTagsDistribution IDE + 13 uppercase alphanumerics
ELBv2CreateLoadBalancerARN suffix16 lowercase hex
EFSCreateFileSystemFile system IDfs- + 8 to 40 lowercase hex
RDSCreateDBInstanceDbiResourceIddb- + 26 uppercase alphanumerics

Lambda, SQS and DynamoDB identifiers derive from the resource name, so there is nothing to pin.

Example ​

sh
aws ec2 create-vpc --cidr-block 10.0.0.0/16 \
  --tag-specifications 'ResourceType=vpc,Tags=[{Key=gopherstack:id,Value=vpc-0a1b2c3d4e5f60718}]'

The VPC is created as vpc-0a1b2c3d4e5f60718 with no gopherstack:id tag.

Released under the MIT License.