Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Container Instance Tagging #724

Merged
merged 1 commit into from
Mar 2, 2019

Conversation

PettitWesley
Copy link
Contributor

This part is a bit thorny because it requires opt-in to the new long arn format.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@PettitWesley
Copy link
Contributor Author

Testing with long ARNs enabled:

$ ecs-cli up --region us-west-1 --force --tags madman=with-a-box --cluster tagging --instance-role ec2-admin-instance --aws-profile ec2-instance --keypair SFOPair
WARN[0000] Enabling container instance tagging because containerInstanceLongArnFormat is enabled for your identity, arn:aws:iam::REDACTED:role/ec2-admin-instance. If this is not your account default setting, your instances will fail to join your cluster.
INFO[0000] Defaulting instance type to t2.micro
INFO[0000] Using recommended Amazon Linux 2 AMI with ECS Agent 1.25.1 and Docker version 18.06.1-ce
INFO[0000] Created cluster                               cluster=tagging region=us-west-1
INFO[0001] Waiting for your CloudFormation stack resources to be deleted...
INFO[0001] Cloudformation stack status                   stackStatus=DELETE_IN_PROGRESS
INFO[0061] Cloudformation stack status                   stackStatus=DELETE_IN_PROGRESS
INFO[0123] Waiting for your cluster resources to be created...
INFO[0123] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
INFO[0184] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
INFO[0244] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
VPC created: vpc-04177599e30cddb83
Security Group created: sg-040f7a75f4b75681f
Subnet created: subnet-068c927f23ce3a796
Subnet created: subnet-0217d0aee8e7f4d20
Cluster creation succeeded.

Container instance is tagged:

$ aws resourcegroupstaggingapi get-resources --tag-filters Key=madman,Values=with-a-box --region us-west-1
{
    "ResourceTagMappingList": [
        {
            "ResourceARN": "arn:aws:ecs:us-west-1:REDACTED:container-instance/tagging/bc37c1e6f94a4d228390eba5ad8ba581",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "ECS Instance - amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:vpc/vpc-04177599e30cddb83",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "Vpc"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:route-table/rtb-06e6354f2077ce8d8",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "RouteViaIgw"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:instance/i-0d6d50cc3f1688215",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "ECS Instance - amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "aws:autoscaling:groupName",
                    "Value": "amazon-ecs-cli-setup-tagging-EcsInstanceAsg-AMHAQNDVQITU"
                },
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "EcsInstanceAsg"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/024ff8d0-2a70-11e9-8aeb-02071fa9c460"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe",
            "Tags": [
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:instance/i-09f0c46cf081095f8",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "ECS Instance - amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "aws:autoscaling:groupName",
                    "Value": "amazon-ecs-cli-setup-tagging-EcsInstanceAsg-JNDJHPLK5H16"
                },
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "EcsInstanceAsg"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:subnet/subnet-068c927f23ce3a796",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "PubSubnetAz1"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:security-group/sg-040f7a75f4b75681f",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "EcsSecurityGroup"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:internet-gateway/igw-03fcb70909a8b4309",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "InternetGateway"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-1:REDACTED:subnet/subnet-0217d0aee8e7f4d20",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "PubSubnetAz2"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-1:REDACTED:stack/amazon-ecs-cli-setup-tagging/efede5c0-2a70-11e9-bfa4-069d991bdebe"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "madman",
                    "Value": "with-a-box"
                }
            ]
        }
    ]
}

@PettitWesley
Copy link
Contributor Author

Testing with long ARNs disabled:

$ ecs-cli up --region us-west-2 --force --tags doctor=11th,fishsticks=andcustard --cluster tagging --aws-profile pettiw --capability-iam
WARN[0000] You will not be able to SSH into your EC2 instances without a key pair.
WARN[0000] Disabling container instance tagging because containerInstanceLongArnFormat is not enabled for your identity, arn:aws:iam::REDACTED:root
INFO[0000] Defaulting instance type to t2.micro
INFO[0000] Using recommended Amazon Linux 2 AMI with ECS Agent 1.25.1 and Docker version 18.06.1-ce
INFO[0000] Created cluster                               cluster=tagging region=us-west-2
INFO[0000] Waiting for your CloudFormation stack resources to be deleted...
INFO[0000] Cloudformation stack status                   stackStatus=DELETE_IN_PROGRESS
INFO[0031] Waiting for your cluster resources to be created...
INFO[0031] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
INFO[0091] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
INFO[0152] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
VPC created: vpc-0b5466f05f4f6d380
Security Group created: sg-0d0ed1ec255adf369
Subnet created: subnet-06aedd3d18c8a467f
Subnet created: subnet-09c3c295e99a67865
Cluster creation succeeded.

$ aws resourcegroupstaggingapi get-resources --tag-filters Key=doctor,Values=11th --region us-west-2 --profile pettiw
{
    "ResourceTagMappingList": [
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:subnet/subnet-06aedd3d18c8a467f",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "PubSubnetAz1"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:subnet/subnet-09c3c295e99a67865",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "PubSubnetAz2"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:vpc/vpc-0b5466f05f4f6d380",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "Vpc"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066",
            "Tags": [
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:instance/i-0569a68559b2f14b2",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "ECS Instance - amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "aws:autoscaling:groupName",
                    "Value": "amazon-ecs-cli-setup-tagging-EcsInstanceAsg-SO7WUA76N6VS"
                },
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "EcsInstanceAsg"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:security-group/sg-0d0ed1ec255adf369",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "EcsSecurityGroup"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:internet-gateway/igw-06faf09b441c61a6e",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "InternetGateway"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        },
        {
            "ResourceARN": "arn:aws:ec2:us-west-2:REDACTED:route-table/rtb-01244eee272f7f4d7",
            "Tags": [
                {
                    "Key": "aws:cloudformation:logical-id",
                    "Value": "RouteViaIgw"
                },
                {
                    "Key": "aws:cloudformation:stack-id",
                    "Value": "arn:aws:cloudformation:us-west-2:REDACTED:stack/amazon-ecs-cli-setup-tagging/24bbc850-2a74-11e9-8473-0ad6ed005066"
                },
                {
                    "Key": "aws:cloudformation:stack-name",
                    "Value": "amazon-ecs-cli-setup-tagging"
                },
                {
                    "Key": "doctor",
                    "Value": "11th"
                },
                {
                    "Key": "fishsticks",
                    "Value": "andcustard"
                }
            ]
        }
    ]
}

@PettitWesley PettitWesley mentioned this pull request Feb 13, 2019
PettitWesley added a commit to PettitWesley/amazon-ecs-cli that referenced this pull request Feb 25, 2019
ecs-cli/modules/cli/cluster/cluster_app.go Outdated Show resolved Hide resolved
ecs-cli/modules/cli/cluster/userdata/user_data.go Outdated Show resolved Hide resolved
ecs-cli/modules/cli/cluster/cluster_app.go Outdated Show resolved Hide resolved
ecs-cli/modules/cli/cluster/cluster_app.go Outdated Show resolved Hide resolved
ecs-cli/modules/cli/cluster/cluster_app.go Outdated Show resolved Hide resolved
@PettitWesley PettitWesley force-pushed the tag-container-instances branch from 047beb3 to 30fe736 Compare February 27, 2019 19:46
}

// RegisterTaskDefinition mocks base method
func (m *MockECSClient) RegisterTaskDefinition(arg0 *ecs0.RegisterTaskDefinitionInput) (*ecs0.TaskDefinition, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why this was added to the mocks? I don't see changes to this func in the client

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's probably because I screwed up a rebase at some point. I'll regenerate them.

@PettitWesley PettitWesley force-pushed the tag-container-instances branch from 11dce09 to e53073d Compare March 1, 2019 23:12
@PettitWesley PettitWesley force-pushed the tag-container-instances branch from e53073d to 6a34ccd Compare March 1, 2019 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants