test-kitchen/kitchen-ec2

EC2 tags

ckajrolkar opened this issue · 3 comments

Hello, We have observed that due when perform kitchen create using ec2 its not taking tags that we define in yml file .
what should be formate set addtiona tags as we have setting up tag policy in aws

@ckajrolkar can you share an example kitchen.yml file? without it, kinda impossible to help trouble shoot.

for example the following example launches an instance with both the created-by tag and the Name tag

driver:
  name: ec2
  instance_type: t3.medium
  region: us-east-2
  interface: id
  user_data: |
    #!/bin/bash
    echo "hello userdata"
  image_search:
    owner-id: "099720109477" #canonical account id
    name: "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
  tags:
     created-by: test-kitchen

transport:
  username: ubuntu

platforms:
  - name: platform-1

provisioner:
  name: shell

verifier:
  name: shell
  command: |
    echo 'hello verifier'
    exit 0

suites:
  - name: default
    provisioner:
      name: shell
      command: echo "hello default  suite provisioner"
    driver:
      name: ec2
      tags:
        Name: test-kitchen-example-instance

Steps

create the instance

# create the instance
$ kitchen create

verify tags are created using the aws-cli

$ aws ec2 describe-instances --instance-id <instance id show in logs from previous step> --query 'Reservations[*].Instances[].Tags[]'
[
    {
        "Key": "Name",
        "Value": "test-kitchen-example-instance"
    },
    {
        "Key": "created-by",
        "Value": "test-kitchen"
    }
]

To specify multiple tags within the kitchen.yml you can specify the following:

tags:
  created-by: 'test-kitchen'
  reason: 'Only used for testing can be deleted'

image

tas50 commented

Shipped in 3.12.0