Why do certain tag values automatically change to true or false in CloudFormation YAML templates?

Why do certain tag values automatically change to true or false in CloudFormation YAML templates?

Clock Icon2025.05.13

日本語版はこちら

The issue

I created a resource with a specific tag in a CloudFormation YAML template.
When I checked the tags of the resource to which I had assigned a tag value of "yes", it had automatically changed to "true".

Why do certain tag values automatically change to true or false in CloudFormation YAML templates?

The solution

The automatic change of certain tag values to true or false in CloudFormation YAML templates is a specification of YAML version 1.1.
Boolean Language-Independent Type for YAML™ Version 1.1

A Boolean represents a true/false value. Booleans are formatted as English words (“true”/“false”, “yes”/“no” or “on”/“off”) for readability and may be abbreviated as a single character “y”/“n” or “Y”/“N”.

Because CloudFormation supports the YAML version 1.1 specification, with a few exceptions, when using YAML templates in CloudFormation, the following values automatically change to true or false:

  • yes/no
  • on/off

CloudFormation template format - AWS CloudFormation

CloudFormation supports the YAML Version 1.1 specification with a few exceptions.

There are the following workarounds:

  • Enclose the values in double quotes
    • Such as "yes", "off", "on", "off"
  • Use JSON templates instead

I tried it

I actually tried the following three patterns:

  1. Setting a tag value of yes in a YAML template without using double quotes
  2. Setting a tag value of "yes" in a YAML template using double quotes
  3. Setting a tag value of "yes" in a JSON template

1. Setting a tag value of yes in a YAML template without using double quotes

I will create a VPC using the following YAML template:

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      Tags:
        - Key: Name
          Value: yes

I created a stack in CloudFormation using the above template, and when I checked the value of the Name tag in the VPC console, it had changed to true.

2025-05-13_11h28_21

2. Setting a tag value of "yes" in a YAML template using double quotes

I will enclose the values in the previous YAML template with double quotes.

AWSTemplateFormatVersion: "2010-09-09"
Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 10.0.0.0/16
      Tags:
        - Key: Name
          Value: "yes"

After updating the CloudFormation stack with the above template and checking the value of the Name tag for the VPC, it had changed to yes, which is the value as specified in the template.

2025-05-13_11h31_04

3. Setting a tag value of "yes" in a JSON template

Now I will try with a JSON template.

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "VPC": {
      "Type": "AWS::EC2::VPC",
      "Properties": {
        "CidrBlock": "10.0.0.0/16",
        "Tags": [
          {
            "Key": "Name",
            "Value": "yes"
          }
        ]
      }
    }
  }
}

I created a stack in CloudFormation using the above template, and when I checked the value of the Name tag in the VPC console, it was set to yes as specified in the template.

2025-05-13_11h33_31

References

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.