Skip to content

Instantly share code, notes, and snippets.

@tylergohl
Created September 26, 2018 14:58
Show Gist options
  • Save tylergohl/9c6159fcdf42be286cfc46a5eb39a8d1 to your computer and use it in GitHub Desktop.
Save tylergohl/9c6159fcdf42be286cfc46a5eb39a8d1 to your computer and use it in GitHub Desktop.
Sometimes you gotta break all your AWS tags
# Change up $role / $product as needed
$MajorEnv = 'int'
$EnvNumber = '01'
$Env = "$MajorEnv$EnvNumber"
$Role = 'es-master'
$values = "$Env-$Role*"
$Product = 'los'
# Get empty web server tags
$Instances = (get-ec2instance -Filter @( @{name='tag:aws:cloudformation:stack-name'; values=$values}) | Select-Object -ExpandProperty instances).instanceid
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "Name"
$tag.Value = "$MajorEnv$EnvNumber-$Role"
$instances | New-EC2Tag -Tag $tag -Force
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "Patch Group"
$tag.Value = "$MajorEnv-$Role"
$instances | New-EC2Tag -Tag $tag -Force
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "role"
$tag.Value = $Role
$instances | New-EC2Tag -Tag $tag -Force
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "product"
$tag.Value = $Product
$instances | New-EC2Tag -Tag $tag -Force
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "environment"
$tag.Value = $Env
$instances | New-EC2Tag -Tag $tag -Force
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "major environment"
$tag.Value = $MajorEnv
$instances | New-EC2Tag -Tag $tag -Force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment