-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Terraform workaround for adding tags (when spot). Close #1
- Loading branch information
Showing
1 changed file
with
10 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
#!/bin/bash | ||
|
||
export AWS_DEFAULT_REGION="{{ cookiecutter.region }}" | ||
|
||
# Update the apt package index: | ||
sudo apt-get update | ||
|
||
## Install Ansible requirements | ||
sudo apt-get install -y python-minimal python-pip vim awscli | ||
sudo apt-get install -y cloud-utils jq | ||
sudo pip install docker | ||
|
||
{%- if cookiecutter.use_spot_instance != 'n' %} | ||
## Apply tags when spot | ||
INSTANCEID=$(ec2metadata --instance-id) | ||
VOLUMES=$(aws ec2 describe-volumes --filters "Name=attachment.instance-id,Values=$INSTANCEID" | jq '.Volumes[].VolumeId' | tr -d '"') | ||
aws ec2 create-tags --resources $INSTANCEID $VOLUMES --tags "Key=Name,Value={{ cookiecutter.project_name }} Key=Product,Value={{ cookiecutter.tag_product }} Key=Owner,Value={{ cookiecutter.tag_owner }} Key=Environment,Value={{ cookiecutter.tag_environment }} Key=Client,Value={{ cookiecutter.tag_client }}" | ||
{%- endif %} |
297ab48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@huogerac this solution will tag only the ec2 instance it self, you can use the workaround proposed in this comment to tag the volumes too.