aws-cloudformation / cloudformation-cli

The CloudFormation Provider Development Toolkit allows you to author your own resource providers and modules that can be used by CloudFormation.
Apache License 2.0
318 stars 161 forks source link

Unhandled exception with "import_path" in latest cloudformation-cli and go-plugin versions #1054

Closed maastha closed 8 months ago

maastha commented 8 months ago

When running make command for submitting certain resources, we recently started running into errors related to import_path.

These errors don't occur for older versions below: cloudformation-cli==0.2.33 cloudformation-cli-go-plugin==2.0.4

The issue occurs if the latest versions of the CLI are used i.e. cloudformation-cli v0.2.34 and v0.2.35 and cloudformation-cli-go-plugin v2.2.0

Also, note that we run into this only for certain resources. For reference below is rpdk-config for one such resource:

{
    "artifact_type": "RESOURCE",
    "typeName": "MongoDB::Atlas::NetworkContainer",
    "language": "go",
    "runtime": "go1.x",
    "entrypoint": "handler",
    "testEntrypoint": "handler",
    "settings": {
        "importpath": "github.com/mongodb/mongodbatlas-cloudformation-resources/network-container",
        "protocolVersion": "2.0.0",
        "pluginVersion": "2.0.4"
    }
}
➜  make
cfn generate
Resource schema is valid.
=== Unhandled exception ===
Please report this issue to the team.
Issue tracker: github.com/aws-cloudformation/cloudformation-cli/issues
Please include the log file 'rpdk.log'
make: *** [build] Error 127

rpdk.log:

[2024-01-17T13:59:04Z] DEBUG    - Logging set up successfully
[2024-01-17T13:59:04Z] DEBUG    - Running generate: Namespace(version=False, subparser_name='generate', command=<function generate at 0x115d1d620>, verbose=0, endpoint_url=None, region=None, local_only=False, target_schemas=[], profile=None)
[2024-01-17T13:59:04Z] DEBUG    - Root directory: /Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container
[2024-01-17T13:59:04Z] DEBUG    - Loading project file '/Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/.rpdk-config'
[2024-01-17T13:59:04Z] INFO     - Validating your resource specification...
[2024-01-17T13:59:04Z] DEBUG    - Rewriting refs in '<BASE>' (file:///Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/mongodb-atlas-networkcontainer.json)
[2024-01-17T13:59:04Z] WARNING  - Resource schema is valid.
[2024-01-17T13:59:04Z] INFO     - Validating your resource schema...
[2024-01-17T13:59:04Z] DEBUG    - Writing Execution Role CloudFormation template: /Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/resource-role.yaml
[2024-01-17T13:59:04Z] DEBUG    - Overwriting '/Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/resource-role.yaml'
[2024-01-17T13:59:04Z] DEBUG    - Generate started
[2024-01-17T13:59:04Z] DEBUG    - Writing Types
[2024-01-17T13:59:04Z] DEBUG    - Overwriting '/Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/cmd/resource/config.go'
[2024-01-17T13:59:04Z] DEBUG    - Overwriting '/Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/cmd/resource/model.go'
[2024-01-17T13:59:04Z] DEBUG    - Writing project: /Users/aastha.mahendru/mongodbatlas-cloudformation-resources/cfn-resources/network-container/cmd/main.go
[2024-01-17T13:59:04Z] DEBUG    - Unhandled exception
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/rpdk/core/cli.py", line 105, in main
    args.command(args)
  File "/opt/homebrew/lib/python3.11/site-packages/rpdk/core/generate.py", line 15, in generate
    project.generate(
  File "/opt/homebrew/lib/python3.11/site-packages/rpdk/core/project.py", line 547, in generate
    self._plugin.generate(self)
  File "/opt/homebrew/lib/python3.11/site-packages/rpdk/go/codegen.py", line 200, in generate
    importpath = Path(project.settings["import_path"])
                      ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'import_path'
kddejong commented 8 months ago

Because of this change: https://github.com/aws-cloudformation/cloudformation-cli-go-plugin/pull/168

You will need to adjust your settings appropriately:

"settings": {
        "import_path": "github.com/mongodb/mongodbatlas-cloudformation-resources/network-container",
        "protocolVersion": "2.0.0",
        "pluginVersion": "2.0.4"
    }
kddejong commented 8 months ago

Also see issue https://github.com/aws-cloudformation/cloudformation-cli-go-plugin/issues/177