dougmoscrop / serverless-plugin-split-stacks

A plugin to generate nested stacks to get around CloudFormation resource/parameter/output limits
299 stars 71 forks source link

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ServerlessDeploymentBucket] in the Resources block of the template #82

Open triptec opened 5 years ago

triptec commented 5 years ago

The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ServerlessDeploymentBucket] in the Resources block of the template

I'm getting above error trying to use this plugin but I can't figure out why,

other plugins:

plugins:
  - serverless-webpack
  - serverless-dynamodb-local
  - serverless-offline
  - serverless-domain-manager
  - serverless-plugin-warmup
  - serverless-es-logs
  - serverless-pseudo-parameters
  - serverless-plugin-split-stacks

split stacks config:

  splitStacks:
    perFunction: false
    perType: true
    perGroupFunction: false

and this stacks-map.js:

module.exports = (resourceObj, logicalId) => {
  resourceType = resourceObj.Type;
  if (resourceType.startsWith("AWS::ApiGateway::Method")) return { destination: 'AWSApiGatewayMethod', force: true };
  if (resourceType.startsWith("AWS::ApiGateway::Resource")) return { destination: 'AWSApiGatewayResource', force: true };
  if (resourceType.startsWith("AWS::Lambda::Function")) return { destination: 'AWSLambdaFunction', force: true };
  if (resourceType.startsWith("AWS::Lambda::Permission")) return { destination: 'AWSLambdaPermission', force: true };
  if (resourceType.startsWith("AWS::Logs::LogGroup")) return { destination: 'AWSLogsLogGroup', force: true };
  if (resourceType.startsWith("AWS::Logs::SubscriptionFilter")) return { destination: 'AWSLogsSubscriptionFilter', force: true };

  if (resourceType.startsWith("AWS::ApiGateway::Authorizer")) return { destination: 'Misc', force: true };
  if (resourceType.startsWith("AWS::ApiGateway::GatewayResponse")) return { destination: 'Misc', force: true };
  if (resourceType.startsWith("AWS::Events::Rule")) return { destination: 'Misc', force: true };
  if (resourceType.startsWith("AWS::IAM::Role")) return { destination: 'Misc', force: true };
  if (resourceType.startsWith("AWS::S3::Bucket")) return { destination: 'Misc', force: true };

  if (resourceType.startsWith("AWS::ApiGateway::RestApi")) return false;
  if (resourceType.startsWith("AWS::ApiGateway::BasePathMapping")) return false;
  if (resourceType.startsWith("AWS::ApiGateway::Deployment")) return false;
  return false;
};
chemalopezp commented 4 years ago

@triptec did you finally figure out a solution? I'm having a similar problem (also using serverless-domain-manager). Do you think it could be related to https://github.com/dougmoscrop/serverless-plugin-split-stacks/issues/106?

triptec commented 4 years ago

@chemalopezp I honestly don’t remember and I haven’t got access to the git logs or source but I’ll see if I can ask someone

carlcheel-sage commented 4 years ago

I hit this same issue. It was introduced in commit 8273717... @jormaechea

Before commit 827371789a07144977d59de4690b73a3fb777dfb (works fine):

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "PoliciesNestedStack nested stack",
  "Parameters": {
    "ServerlessDeploymentBucketParameter": {
      "Type": "String"
    }
  },
  "Resources": {
    "ServerlessDeploymentBucketPolicy": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "ServerlessDeploymentBucketParameter"
        },
        "PolicyDocument": {
          "Statement": [
            {
              "Action": "s3:*",
              "Effect": "Deny",
              "Principal": "*",
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":s3:::",
                      {
                        "Ref": "ServerlessDeploymentBucketParameter"
                      },
                      "/*"
                    ]
                  ]
                }
              ],
              "Condition": {
                "Bool": {
                  "aws:SecureTransport": false
                }
              }
            }
          ]
        }
      },
      "DependsOn": []
    }
  },
  "Outputs": {}
}

After (broken due to incorrect Ref):

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "PoliciesNestedStack nested stack",
  "Parameters": {
    "ServerlessDeploymentBucketParameter": {
      "Type": "String"
    }
  },
  "Resources": {
    "ServerlessDeploymentBucketPolicy": {
      "Type": "AWS::S3::BucketPolicy",
      "Properties": {
        "Bucket": {
          "Ref": "ServerlessDeploymentBucket"
        },
        "PolicyDocument": {
          "Statement": [
            {
              "Action": "s3:*",
              "Effect": "Deny",
              "Principal": "*",
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn:",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":s3:::",
                      {
                        "Ref": "ServerlessDeploymentBucket"
                      },
                      "/*"
                    ]
                  ]
                }
              ],
              "Condition": {
                "Bool": {
                  "aws:SecureTransport": false
                }
              }
            }
          ]
        }
      },
      "DependsOn": []
    }
  },
  "Outputs": {}
}

Confirmed the issue is caused by _cloneDeep on Line 234 and Line 239. Removing this fixes the issue.

petergaultney commented 4 years ago

I'm running into this as well, in my first usage of the plugin.

What are the chances that removing cloneDeep will cause other issues?

kferrone commented 1 month ago

Wow, 4yrs and still open. This project is dead isn't it?