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

[aws-resourcegroups] aws-resourcegroups requires an array for tags property but fails CFN stack creation with internal error #9040

Closed
p3nda opened this issue Jul 13, 2020 · 6 comments
Labels
@aws-cdk/aws-resourcegroups Related to AWS Resource Groups bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p1

Comments

@p3nda
Copy link

p3nda commented Jul 13, 2020

description of the bug:

When adding tags to resource groups I am getting this error:

Error: Invalid tag input expected map of {key: value} have [{"Key":"TagKey","Value":"TagValue"}]
    at MapFormatter.parseTags (/Users/amawalte/Downloads/cdk/EBS-SSMMaintenanceWindows/node_modules/@aws-cdk/core/lib/tag-manager.js:81:19)

because the error keeps saying expects map of {key: value} I passed the tags like this:

const rgTags = 
            {
                "Key": "Key",
                "Value": "Value"
            }

This allowed me to get passed the CDK error, and it started creating the stack, however it failed with the internal error:

✗ sudo cdk deploy --app ssm_maintenance_windows.js EBS-resource-groups-stack
EBS-resource-groups-stack: deploying...
EBS-resource-groups-stack: creating CloudFormation changeset...
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::ResourceGroups::Group | RDS-SIT (RDSSIT)
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::CDK::Metadata         | CDKMetadata
 0/4 | 12:41:01 PM | CREATE_IN_PROGRESS   | AWS::ResourceGroups::Group | EC2-SIT (EC2SIT)
 1/4 | 12:41:02 PM | CREATE_FAILED        | AWS::ResourceGroups::Group | RDS-SIT (RDSSIT) Internal Failure
    ResourceGroupStack.createResourceGroup (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:18:16)
    \_ /Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:14:43
    \_ Array.forEach (<anonymous>)
    \_ new ResourceGroupStack (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/lib/resource_groups_stack.js:13:27)
    \_ Object.<anonymous> (/Users/Amanda/Downloads/cdk/EBS-SSMMaintenanceWindows/bin/ssm_maintenance_windows.js:10:28)
    \_ Module._compile (internal/modules/cjs/loader.js:1200:30)
    \_ Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    \_ Module.load (internal/modules/cjs/loader.js:1049:32)
    \_ Function.Module._load (internal/modules/cjs/loader.js:937:14)
    \_ Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    \_ internal/main/run_main_module.js:17:47
 2/4 | 12:41:02 PM | CREATE_FAILED        | AWS::ResourceGroups::Group | EC2-SIT (EC2SIT) Internal Failure

So I opened the cloudformation stack in designer and changed from:

This:

"Tags": {
                    "Key": "Key",
                    "Value": "Value"
                }

To This:

"Tags": [
                    {
                        "Key": "Key",
                        "Value": "Value"
                    }
                ]

And it created successfully. So, to double check, I went back to the cdk app and changed the code to match what was successful in cloudformation:

class ResourceGroupStack extends cdk.Stack {
    constructor(scope, id, resourceGroupList) {
        super(scope, id);
        this.resourceGroups = [];
        const rgTags = [
            {
                "Key": "TagKey",
                "Value": "TagValue"
            }
        ]

And it errored out again:

Error: Invalid tag input expected map of {key: value} have [{"Key":"TagKey","Value":"TagValue"}]
    at MapFormatter.parseTags (/Users/amawalte/Downloads/cdk/EBS-SSMMaintenanceWindows/node_modules/@aws-cdk/core/lib/tag-manager.js:81:19)

Based on the above tests, CDK will not take the array, even though that is the only acceptable format for aws::resourcegroups::group . To verify, I checked the cdk code:

class MapFormatter {
    parseTags(cfnPropertyTags, priority) {
        const tags = [];
        if (Array.isArray(cfnPropertyTags) || typeof (cfnPropertyTags) !== 'object') {
            throw new Error(`Invalid tag input expected map of {key: value} have ${JSON.stringify(cfnPropertyTags)}`);
        }
        for (const [key, value] of Object.entries(cfnPropertyTags)) {
            tags.push({
                key,
                value: `${value}`,
                priority
            });

The above seems to indicate if it it is an array to throw the above error. Ref: https://github.com/aws/aws-cdk/pull/1762/files MapFormatter is the funciton that throws the error based on the output .

Environment

  • CLI Version aws --version
    aws-cli/1.17.10 Python/2.7.16 Darwin/18.7.0 botocore/1.14.10 :
  • Framework Version: cdk --version
    1.42.0 (build 3b64241)
  • Node.js Version:
    ~ node -v
    v14.3.0
  • OS Mojave 10.14.6 :
  • Language (Version):

This is 🐛 Bug Report

@p3nda p3nda added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jul 13, 2020
@github-actions github-actions bot added the @aws-cdk/aws-resourcegroups Related to AWS Resource Groups label Jul 13, 2020
@eladb
Copy link
Contributor

eladb commented Jul 14, 2020

Until this is resolved, you can use addPropertyOverride to apply the tag to the CFN resource like so:

import * as cdk from '@aws-cdk/core';
import * as rg from '@aws-cdk/aws-resourcegroups';

export class Repro9040Stack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const group = new rg.CfnGroup(this, 'MyGroup', {
      name: 'mygroup'
    });

    group.addPropertyOverride('Tags', [
      {
        Key: 'Mykey',
        Value: 'MyValue'
      }
    ]);
  }
}

This will produce the following template:

{
  "Resources": {
    "MyGroup": {
      "Type": "AWS::ResourceGroups::Group",
      "Properties": {
        "Name": "mygroup",
        "Tags": [
          {
            "Key": "Mykey",
            "Value": "MyValue"
          }
        ]
      },
      "Metadata": {
        "aws:cdk:path": "Repro9040Stack/MyGroup"
      }
    }
  }
}

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jul 15, 2020
@MrArnoldPalmer MrArnoldPalmer added effort/medium Medium work item – several days of effort p1 labels Aug 17, 2020
@MrArnoldPalmer
Copy link
Contributor

@eladb do we see this issue anywhere else in L1s? I'm not sure why this is getting typed as any.

@thomasklinger1234
Copy link

Any news on this?

FYI, I have solved this with a CDK aspect:

// Fix for https://github.com/aws/aws-cdk/issues/9040
class ResourceGroupsTaggingFixAspect implements cdk.IAspect {
    public visit(node: cdk.IConstruct): void {
      if (node instanceof resourcegroups.CfnGroup) {
        const tagValues = node.tags.tagValues();
        node.addDeletionOverride("Tags");
        node.addPropertyOverride("Tags", Object.keys(tagValues).map(key => {
            return {
                Key: key,
                Value: tagValues[key]
            };
        }));
      }
    }
}

cdk.Aspects.of(app).add(new ResourceGroupsTaggingFixAspect())

@MrArnoldPalmer MrArnoldPalmer removed their assignment Jun 21, 2021
@ggaller
Copy link

ggaller commented Jul 30, 2021

Workaround for this bug in C#:

/// <summary>
/// Because of bug, we can't use CfnGroup directly
/// https://github.com/aws/aws-cdk/issues/9040
/// </summary>
public class CfnGroupTaggable : CfnGroup
{
    public CfnGroupTaggable(Construct scope, string id, ICfnGroupProps props)
        : base(scope, id, props) => Tags = new TagManager(TagType.KEY_VALUE, CFN_RESOURCE_TYPE_NAME);

    public override TagManager Tags { get; }
}

@ggaller
Copy link

ggaller commented Aug 1, 2021

I think that problem start since this commit. Tags property was changed in the schema and codegen begin resolved it as Map instead List.

@github-actions
Copy link

github-actions bot commented Aug 1, 2022

This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Aug 1, 2022
@github-actions github-actions bot closed this as completed Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-resourcegroups Related to AWS Resource Groups bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort p1
Projects
None yet
Development

No branches or pull requests

6 participants