1
votes

For the below cloudformation template:

{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Some Stack",
    "Parameters":{
        "VpcId":{
            "Type": "AWS::EC2::VPC::Id",
            "Description": "The target VPC Id"
        },
        "SubnetId":{
            "Type": "AWS::EC2::Subnet::Id",
            "Description": "The target subnet Id"
        },
        "KeyName": {
            "Type": "String",
            "Description": "The key pair that is allowed SSH access"
        }
    },
    "Resources":{
        "EcsCluster":{
            "Type": "AWS::ECS::Cluster",
            "Tags": [ 
                        {
                            "Key": "Name",
                            "Value": { "Fn::Join": ["", [ { "Ref": "AWS::StackName" }, "-ecs-cluster" ] ] }     
                        },
                        {
                            "Key": "workenv",
                            "Value": "dev"
                        },
                        {
                            "Key": "abc",
                            "Value": "some_value"
                        },
                        {
                            "Key": "function",
                            "Value": "someapp"
                        },
                        {
                            "Key": "owner",
                            "Value": "[email protected]"
                        }
            ]
        }
    },
    "Outputs":{
        "ElbDomainName":{
            "Description": "Public DNS name of Elastic Load Balancer",
            "Value": {
                "Fn::GetAtt": [
                    "ElasticLoadBalancer",
                    "DNSName"
                ]
            }
        }
    }
}

Below is the error:

   Invalid template resource property 'Tags'

Am following the below documentation to add tags:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html


Why CloudFormation service does not accept Tags defined on every resource? something to do with indentation?

2

2 Answers

3
votes

It is because the Tags are not defined correctly for EcsCluster resource. The Tags property should be defined inside the Properties section as how you defined Tags for other resources.

"EcsCluster": {
  "Type": "AWS::ECS::Cluster",
  "Properties": {
    "Tags": []
  }
}

Hope this helps.

1
votes

Not all resource types support tags. Check the documentation for each resource type.