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

Fix DependsOn in module extension #119

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cft/pkg/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ func addPolicy(ext *yaml.Node, name string, moduleExtension *yaml.Node, template

// Rename a resource defined in the module to add the template resource name
func rename(logicalId string, resourceName string) string {
return logicalId + resourceName
if resourceName == "ModuleExtension" {
return logicalId
} else {
return logicalId + resourceName
}
}

// Recursive function to find all refs in properties
Expand Down Expand Up @@ -228,11 +232,6 @@ func processModule(module *yaml.Node,
return false, errors.New("expected ModuleExtension.Metadata.Extends")
}

_, moduleProps := s11n.GetMapValue(moduleExtension, "Properties")
if moduleProps == nil {
return false, errors.New("expected ModuleExtension.Properties")
}

// Create a new node to contain the extended resource.
// This will be added to the template, and the original resource node will be removed
ext := &yaml.Node{}
Expand Down
5 changes: 5 additions & 0 deletions test/modules/bucket.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ Resources:
AdditionalResource2:
Type: AWS::S3::Bucket

DependsOnModuleExtension:
Type: AWS::S3::Bucket
DependsOn: ModuleExtension



5 changes: 5 additions & 0 deletions test/modules/expect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ Resources:
ModuleExampleAdditionalResource2:
Type: AWS::S3::Bucket

ModuleExampleDependsOnModuleExtension:
Type: AWS::S3::Bucket
DependsOn:
- ModuleExample

WithoutExtensionBucketA:
Type: AWS::S3::Bucket
Properties:
Expand Down
15 changes: 15 additions & 0 deletions test/modules/ext-ref.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Description: |
For testing Refs on the ModuleExtension itself

Resources:

ModuleExtension:
Metadata:
Extends: AWS::S3::Bucket

DependsOnModuleExtension:
Type: AWS::S3::Bucket
DependsOn: ModuleExtension



8 changes: 8 additions & 0 deletions test/templates/ext-ref-module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Resources:

ModuleExample:
Type: !Rain::Module "file://../../modules/ext-ref.yaml"
Properties:
BucketName: ezbeard-cep-test-module-bucket