forked from goAWS/cloudformationresources
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify new resource creation * Embed custom type in `ResourceProperties` to work around crewjam/go-cloudformation#9 * Support CloudFormation _ResponseURL_ signaling iff defined * Add test case to directly invoke resource `create` method TODO: * Lift op handler into retry loop
- Loading branch information
Showing
4 changed files
with
217 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
# CloudFormationResources | ||
Catalog of golang-based CloudFormation CustomResources | ||
|
||
|
||
## Adding a New Resource | ||
|
||
1. Create a new struct that implements `CustomResourceCommand` | ||
- This struct **MUST** embed `gocf.CloudFormationCustomResource` as in: | ||
|
||
1. Create a new struct that embeds `CustomResourceCommand` | ||
- This struct **MUST** embed `GoAWSCustomResource` as in: | ||
``` | ||
type HelloWorldResource struct { | ||
gocf.CloudFormationCustomResource | ||
GoAWSCustomResource | ||
Message string | ||
} | ||
``` | ||
2. Add a const representing the resource type to the _CustomResourceType_ enum eg, `HelloWorld` | ||
- The literal **MUST** start with [Custom::goAWS](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html) | ||
3. Add the new type to the `customResources` map in the `init` function in <i>cloud_formation_resources.go</i> | ||
4. Add a new case to the `switch/case` in `Process()` that initializes the custom resource and assigns the new value to the `commandInstance` as in: | ||
``` | ||
case HelloWorld: | ||
customCommand := HelloWorldResource{} | ||
if err := json.Unmarshal([]byte(string(marshaledProperties)), &customCommand); nil != err { | ||
return nil, fmt.Errorf("Failed to unmarshal ResourceProperties for %s", request.ResourceType) | ||
} | ||
commandInstance = customCommand | ||
``` | ||
2. Add a package level _var_ denoting the resource type | ||
- The value **MUST** be generated by `cloudFormationResourceType(...)` to include the proper custom resource [prefix](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html). Example: | ||
``` | ||
HelloWorld = cloudFormationResourceType("HelloWorldResource") | ||
``` | ||
3. Add a `case` label in `customCommandForTypeName` for the custom resource type added in step 2. | ||
- This block is responsible for creating a new command instance and unmarshalling the _properties_ into the type-specific values. | ||
- Assign the new command to the _customCommand_ interface. Example: | ||
``` | ||
case HelloWorld: | ||
command := HelloWorldResource{ | ||
GoAWSCustomResource: GoAWSCustomResource{ | ||
GoAWSType: resourceTypeName, | ||
}, | ||
} | ||
if nil != properties { | ||
unmarshalError = json.Unmarshal([]byte(string(*properties)), &command) | ||
} | ||
customCommand = &command | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.