crewjam / go-cloudformation Goto Github PK
View Code? Open in Web Editor NEWA golang library for reading and producing CloudFormation templates
License: BSD 2-Clause "Simplified" License
A golang library for reading and producing CloudFormation templates
License: BSD 2-Clause "Simplified" License
Hi
I have the following while spinning up a cloudformation stack
func makeTemplate() *cf.Template {
t := cf.NewTemplate()
t.Description = "example production infrastructure"
t.Parameters["Name"] = &cf.Parameter{
Description: "This is a test",
Type: "String",
Default: "live long and prosper",
}
t.Outputs["myoutput1"] = &cf.Output{
Description: "test output 1",
Value: "warp",
}
t.AddResource("ec2_vol", cf.EC2Volume{
AutoEnableIO: cf.Bool(false),
AvailabilityZone: cf.String("us-east-1b"),
Encrypted: cf.Bool(false),
Size: cf.String("1"),
Tags: &cf.ResourceTag{
Key: cf.String("Name"),
Value: cf.String("my-vol"),
},
})
etc etc
The Tags are giving an error:
cannot use cloudformation.ResourceTag literal (type *cloudformation.ResourceTag) as type []cloudformation.ResourceTag in field value
Any advice here, please ?
Newbie in Go. So far this package was very useful in the project I'm working. I'm using this to generate CFN template. I noticed one feature is missing that is support for Parameter Groups using AWS::CloudFormation::Interface which is used by the AWS console to display relevant parameters in groups.
This requires Template struct to include Metadata field.
I see the schema.go includes various type (CloudFormationInterface, ParameterGroupsList etc etc) as resource types and wasn't sure how to use them to implement the Metadata field in Template struct.
I have come up with an alternate approach (patch attached) which works but probably not a good approach (again I'm newbie and in very early stage of my learning GO). Appreciate some suggestion and guidance.
metadata.txt
IAMRole.AssumeRolePolicyDocument is an interface{}
Hi Russ,
In adding an ElasticBeanstalkApplicationVersion ref, it seems like the codegen didn't pickup the associated properties.
What's the best way for me to address & verify s.t. I can submit a PR? Thanks.
Hi @crewjam ,
I need to be able to set provider specific CustomResource properties, but it doesn't look as though CloudFormationCustomResource supports that.
Is this something on your backlog? I'd be happy to work on a PR to add this if you can give me some pointers on where to start. Thanks.
The Sub
intrinsic function is missing.
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html
The GroupName
property does not exist. It is not a problem because Cloud Formation will create one, which is arguably better since if you specify a name, you cannot perform updates that require replacement of the resource.
https://godoc.org/github.com/crewjam/go-cloudformation#EC2SecurityGroup
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group.html
That would very nice if you could have information if a property is required. This would a way road for linters based on your library.
If I am not mistaken, *Expr types can be extended with a bool field.
I discovered that S3NotificationConfiguration has properties like LambdaConfigurations
that are clearly from context supposded to be []SimpleStorageServiceNotificationConfigurationLambdaConfigurations
but are actually SimpleStorageServiceNotificationConfigurationLambdaConfigurations
.
The heuristic we use to determine when something is a list failed for this item. I generated a list of other possible similar errors which appears below with the following code:
for _, resource := range tr.Resources {
for _, property := range resource.Properties {
if n := property.GoName(); !strings.HasSuffix(n, "s") {
continue
}
if t := property.GoType(&tr); strings.Contains(t, "List") {
continue
}
if t := property.GoType(&tr); strings.Contains(t, "[]") {
continue
}
if t := property.GoType(&tr); strings.Contains(t, "interface{}") {
continue
}
fmt.Fprintf(os.Stderr, "* in "+
"[%s](https://godoc.org/github.com/crewjam/go-cloudformation#%s) "+
"property `%s` has type `%s` but should maybe be a list type. [ref](%s)\n",
resource.GoName(), resource.GoName(),
property.GoName(),
property.GoType(&tr),
rootURL+resource.Href)
}
}
This list:
AssociatePublicIpAddress
has type *BoolExpr
but should maybe be a list type. refParameters
has type *CloudFormationStackParameters
but should maybe be a list type. refTimeoutInMinutes
has type *StringExpr
but should maybe be a list type. refIncludeGlobalServiceEvents
has type *BoolExpr
but should maybe be a list type. refEvaluationPeriods
has type *StringExpr
but should maybe be a list type. refMinimumHealthyHosts
has type *CodeDeployDeploymentConfigMinimumHealthyHosts
but should maybe be a list type. refEc2TagFilters
has type *CodeDeployDeploymentGroupEc2TagFilters
but should maybe be a list type. refOnPremisesInstanceTagFilters
has type *CodeDeployDeploymentGroupOnPremisesInstanceTagFilters
but should maybe be a list type. refInputArtifactDetails
has type *CodePipelineCustomActionTypeArtifactDetails
but should maybe be a list type. refOutputArtifactDetails
has type *CodePipelineCustomActionTypeArtifactDetails
but should maybe be a list type. refSettings
has type *CodePipelineCustomActionTypeSettings
but should maybe be a list type. refStages
has type *CodePipelinePipelineStages
but should maybe be a list type. refConfigSnapshotDeliveryProperties
has type *ConfigDeliveryChannelConfigSnapshotDeliveryProperties
but should maybe be a list type. refParameterObjects
has type *DataPipelinePipelineParameterObjects
but should maybe be a list type. refParameterValues
has type *DataPipelinePipelineParameterValues
but should maybe be a list type. refCreateAlias
has type *BoolExpr
but should maybe be a list type. refVpcSettings
has type *DirectoryServiceMicrosoftADVpcSettings
but should maybe be a list type. refCreateAlias
has type *BoolExpr
but should maybe be a list type. refVpcSettings
has type *DirectoryServiceSimpleADVpcSettings
but should maybe be a list type. refGlobalSecondaryIndexes
has type *DynamoDBGlobalSecondaryIndexes
but should maybe be a list type. refLocalSecondaryIndexes
has type *DynamoDBLocalSecondaryIndexes
but should maybe be a list type. refIpAddress
has type *StringExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refEgress
has type *BoolExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refEnableDnsHostnames
has type *BoolExpr
but should maybe be a list type. refFileSystemTags
has type *ElasticFileSystemFileSystemFileSystemTags
but should maybe be a list type. refIpAddress
has type *StringExpr
but should maybe be a list type. refNumCacheNodes
has type *StringExpr
but should maybe be a list type. refNumCacheClusters
has type *IntegerExpr
but should maybe be a list type. refConnectionSettings
has type *ElasticLoadBalancingConnectionSettings
but should maybe be a list type. refStatus
has type *StringExpr
but should maybe be a list type. refRetentionInDays
has type *IntegerExpr
but should maybe be a list type. refOs
has type *StringExpr
but should maybe be a list type. refAutoAssignElasticIps
has type *BoolExpr
but should maybe be a list type. refAutoAssignPublicIps
has type *BoolExpr
but should maybe be a list type. refCustomRecipes
has type *OpsWorksRecipes
but should maybe be a list type. refDefaultOs
has type *StringExpr
but should maybe be a list type. refUseCustomCookbooks
has type *BoolExpr
but should maybe be a list type. refUseOpsworksSecurityGroups
has type *BoolExpr
but should maybe be a list type. refAvailabilityZones
has type *StringExpr
but should maybe be a list type. refDBInstanceClass
has type *StringExpr
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refOptionConfigurations
has type *RDSOptionGroupOptionConfigurations
but should maybe be a list type. refNumberOfNodes
has type *IntegerExpr
but should maybe be a list type. refDelaySeconds
has type *IntegerExpr
but should maybe be a list type. refReceiveMessageWaitTimeSeconds
has type *IntegerExpr
but should maybe be a list type. refEbs
has type *AutoScalingEBSBlockDevice
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refCustomErrorResponses
has type *CloudFrontDistributionConfigCustomErrorResponse
but should maybe be a list type. refPriceClass
has type *StringExpr
but should maybe be a list type. refRestrictions
has type *CloudFrontDistributionConfigurationRestrictions
but should maybe be a list type. refForwardedValues
has type *CloudFrontForwardedValues
but should maybe be a list type. refForwardedValues
has type *CloudFrontForwardedValues
but should maybe be a list type. refIncludeCookies
has type *BoolExpr
but should maybe be a list type. refCookies
has type *CloudFrontForwardedValuesCookies
but should maybe be a list type. refIgnoreApplicationStopFailures
has type *BoolExpr
but should maybe be a list type. refSourceDetails
has type *ConfigConfigRuleSourceSourceDetails
but should maybe be a list type. refAttributes
has type *DataPipelineParameterObjectsAttributes
but should maybe be a list type. refFields
has type *DataPipelineDataPipelineObjectFields
but should maybe be a list type. refEbs
has type *ElasticBlockStoreBlockDeviceProperty
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refAssociatePublicIpAddress
has type *BoolExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refEbs
has type *ElasticComputeCloudSpotFleetSpotFleetRequestConfigDataLaunchSpecificationsBlockDeviceMappingsEbs
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refAssociatePublicIpAddress
has type *BoolExpr
but should maybe be a list type. refPrivateIpAddress
has type *StringExpr
but should maybe be a list type. refIops
has type *IntegerExpr
but should maybe be a list type. refNumberOfDisks
has type *IntegerExpr
but should maybe be a list type. refOptionSettings
has type *RDSOptionGroupOptionConfigurationsOptionSettings
but should maybe be a list type. refIPAddress
has type *StringExpr
but should maybe be a list type. refCorsRules
has type *S3CorsConfigurationRule
but should maybe be a list type. refRules
has type *S3LifecycleRule
but should maybe be a list type. refExpirationInDays
has type *IntegerExpr
but should maybe be a list type. refNoncurrentVersionExpirationInDays
has type *IntegerExpr
but should maybe be a list type. refStatus
has type *StringExpr
but should maybe be a list type. refStorageClass
has type *StringExpr
but should maybe be a list type. refTransitionInDays
has type *IntegerExpr
but should maybe be a list type. refStorageClass
has type *StringExpr
but should maybe be a list type. refTransitionInDays
has type *IntegerExpr
but should maybe be a list type. refStatus
has type *StringExpr
but should maybe be a list type. refStorageClass
has type *StringExpr
but should maybe be a list type. refStatus
has type *StringExpr
but should maybe be a list type. refHttpErrorCodeReturnedEquals
has type *StringExpr
but should maybe be a list type. refKeyPrefixEquals
has type *StringExpr
but should maybe be a list type. refThe examples no longer compile with the breaking change introduced by #23. See https://travis-ci.org/crewjam/go-cloudformation/jobs/388076677 for more info.
CloudFormation has released some new properties recently. Is it possible to regenerate the schema?
Also, thinking out loud, thoughts on running the schema generation code as a Lambda function with a cron-style trigger? Maybe post the generated code to public S3? Might be an interesting case study for serverless.
schema.go L7269-7273 contains:
// EC2PortRange represents EC2 PortRange Property Type
//
// see http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-port-range.html
type EC2PortRange struct {
}
struct should be:
type EC2PortRange struct {
From *IntegerExpr
To *IntegerExpr
}
https://github.com/crewjam/etcd-aws/blob/master/aws/iam.go
type PolicyDocument struct {
Version string `json:",omitempty"`
Statement []Policy
}
type Policy struct {
Sid string `json:",omitempty"`
Effect string `json:",omitempty"`
Principal *Principal `json:",omitempty"`
Action *cfn.StringListExpr `json:",omitempty"`
Resource *cfn.StringListExpr `json:",omitempty"`
ConditionBlock interface{} `json:",omitempty"`
}
type Principal struct {
Service *cfn.StringListExpr `json:",omitempty"`
}
Would you like to add license notation ?
When creating an ingress/egress rule using a security group ID, this creates incorrect JSON. For example, the following:
EC2SecurityGroupRule{
SourceSecurityGroupIdXXSecurityGroupIngressXOnlyX: Ref(s.elbSecurityGroupLogicalName()).String(),
IpProtocol: String(tcpProtocol),
FromPort: Integer(httpsPort),
ToPort: Integer(httpsPort),
},
Generates the JSON:
{
"FromPort": 443,
"IpProtocol": "tcp",
"SourceSecurityGroupId (SecurityGroupIngress only)": {
"Ref": "LBSecurityGroupGamma"
},
"ToPort": 443
}
The expected output is:
{
"FromPort": 443,
"IpProtocol": "tcp",
"SourceSecurityGroupId": {
"Ref": "LBSecurityGroupGamma"
},
"ToPort": 443
}
This is probably due to how the scraper is scraping the AWS website, causing it to include the (SecurityGroupIngress only)
as seen here:
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-rule.html#cfn-ec2-security-group-rule-sourcesecuritygroupid
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.