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

--override-spec not adding custom resource types #3889

Open
manueljimenezs opened this issue Dec 29, 2024 · 2 comments
Open

--override-spec not adding custom resource types #3889

manueljimenezs opened this issue Dec 29, 2024 · 2 comments

Comments

@manueljimenezs
Copy link

manueljimenezs commented Dec 29, 2024

CloudFormation Lint Version

1.22.2

What operating system are you using?

Mac

Describe the bug

I'm trying to upgrade from cfn-lint 0.87.x to 1.x

For adding compatibility with custom macro resources I'm trying to provide custom specs for rules like E3006 via the --override-spec command. This is really useful as we use custom resources via macro and we currently integrate cfn-lint 0.x with our CI pipelines successfully as of today.

Here's a simple spec file for cfn-lint to recognize a custom OK::StandaloneTask resource, following the same syntax as StatefulResources.json. The docs say that specs should merge with the region-specific ones.

{
    "ResourceTypes": {
        "OK::StandaloneTask": {
            "Properties": {
              "ServiceName": {
                "Required": true,
                "PrimitiveType": "String"
              }
            }
          }
    }
}

In cfn-lint 0.87.11 the spec file was read and no errors were given, the template was successfully validated:

$ cfn-lint customresources.yaml --override-spec customspec.json && echo "$?"
0

However, in cfn-lint 1.22.2 the same command gives the following error

$ cfn-lint customresources.yaml --override-spec customspec.json
E3006 Resource type 'OK::StandaloneTask' does not exist in 'us-east-1'
customresources.yaml:9:5

This leads me to think there is a syntax change in spec definitions between 0.x and 1.x versions that I am not aware of?

Expected behavior

When passing an overriden spec, those specs should be used by cfn-lint.

Reproduction template

AWSTemplateFormatVersion: 2010-09-09
Description: mydescription

Transform: OKMacros

Resources:

  MyStandaloneTask:
    Type: OK::StandaloneTask
    Properties:
      ServiceName: "mystandalonetask"

Spec file:

{
    "ResourceTypes": {
        "OK::StandaloneTask": {
            "Properties": {
              "ServiceName": {
                "Required": true,
                "PrimitiveType": "String"
              }
            }
          }
    }
}
@kddejong
Copy link
Contributor

Looking into this. The way that override spec was written is that it allowed you to patch existing resources without changing the specs/schemas. Since you are adding a resource type you could use the --registry-schemas parameter. Just need to define a schema that will work for this.

Schema file:

{
    "typeName": "OK::StandaloneTask",
    "properties": {
        "ServiceName": {
            "type": "string"
        }
    },
    "required": [
        "ServiceName"
    ],
    "type": "object",
    "additionalProperties": false
}

Then

➜  cfn-lint --registry-schemas local/issue/3889/schemas -- local/issue/3889/3889.yaml
➜  echo $?
0

The schemas parameter will look for files inside a folder so just created a folder with the schema file in it.

@manueljimenezs
Copy link
Author

Thank you for your response, that approach works good for creating new resource types, would there be any way to define additional resources that are implicitly created with that custom resource? (maybe at this point it's easier to work with the processed template, although it would lose traceability of original line numbers for example)

for example

AWSTemplateFormatVersion: 2010-09-09

Transform: OKMacros

Resources:
  MyStandaloneTask:
    Type: OK::StandaloneTask
    Properties:
      ServiceName: "mystandalonetask"

Outputs:
  # When transforming the template MyStandaloneTask also creates a RoleMyStandaloneTask resource
  # that is of type AWS::IAM::Role
  MyStandaloneTaskRoleArn:
    Value: !Ref RoleMyStandaloneTask 

This gives the following output:

$ cfn-lint customresources.yaml --registry-schemas schemas
E6101 'RoleMyStandaloneTask' is not one of ['MyStandaloneTask', 'AWS::AccountId', 'AWS::NoValue', 'AWS::NotificationARNs', 'AWS::Partition', 'AWS::Region', 'AWS::StackId', 'AWS::StackName', 'AWS::URLSuffix']

This is the simplified transformed template

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Outputs": {
    "MyStandaloneTaskRoleArn": {
      "Value": {
        "Ref": "RoleMyStandaloneTask"
      }
    }
  },
  "Resources": {
    "RoleMyStandaloneTask": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {},
        "RoleName": {},
        "Policies": [],
        "Tags": []
      }
    }
  }
}

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

No branches or pull requests

2 participants