-
Notifications
You must be signed in to change notification settings - Fork 196
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
WIP: Define Value interface #103
Conversation
So I guess there is one obvious thing here, we need more types and some kind of place-holder type. Besides that, in
First up, |
I have finished implementing all of what we need in eksctl-io/eksctl#132. It would be great to hear how we could go about changes akin to what's shown here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started messaging you back on Slack, but figured the feedback was probably better suited to discussion here.
- All this change in a single commit is pretty hard to grok.
-
Tests & Documentation for this are required
-
Agree with your comments on Slack that using an interface will be nicer
-
Can we rename StringIntrinsic to StringReference - intrinsic could mean anything from Fn::Join etc, where as we are specifically dealing with References here.
-
Rename
cloudformation.NewStringIntrinsic(string)
tocloudformation.NewStringReference(name)
, and I also think we should create acloudformation.Ref(name)
convenience method (to be used in documentation) as 99% of use cases will just be for a string.
@PaulMaddox I decided to rework this because my use-case already requires |
@PaulMaddox I've re-written this, please take a look at c0c0166. |
This is a lot cleaner - I like the approach. Do you have any thoughts about what the API would look like for setting Something like the |
Yes, it will be func addResources(globalCIDR *net.IPNet, subnets map[string]*net.IPNet) {
t.Resource["VPC"] = &cloudformation.AWSEC2VPC{
CidrBlock: cloudformation.String(globalCIDR.String()),
EnableDnsSupport: cloudformation.True,
EnableDnsHostnames: cloudformation.True,
}
refVPC := cloudformation.MakeRef("VPC")
t.Resource["InternetGateway"] = &cloudformation.AWSEC2InternetGateway{})
refIG := cloudformation.MakeRef("InternetGateway")
t.Resource["VPCGatewayAttachment"] = &cloudformation.AWSEC2VPCGatewayAttachment{
InternetGatewayId: refIG,
VpcId: refVPC,
}
t.Resources["RouteTable"] = &cloudformation.AWSEC2RouteTable{
VpcId: refVPC,
}
refRT := cloudformation.MakeRef("RouteTable")
t.Resources["PublicSubnetRoute"] = &cloudformation.AWSEC2Route{
RouteTableId: refRT,
DestinationCidrBlock: cloudformation.String("0.0.0.0/0"),
GatewayId: refIG,
}
subnetRefs := []cloudformation.Value{}
for az, subnet := range subnets {
alias := strings.ToUpper(strings.Join(strings.Split(az, "-"), ""))
t.Resources["Subnet"+alias] = &cloudformation.AWSEC2Subnet{
AvailabilityZone: cloudformation.String(az),
CidrBlock: cloudformation.String(subnet.String()),
VpcId: refVPC,
}
refSubnet := cloudformation.MakeRef("Subnet"+alias)
t.Resources["RouteTableAssociation"+alias] = &cloudformation.AWSEC2SubnetRouteTableAssociation{
SubnetId: refSubnet,
RouteTableId: refRT,
}
subnetRefs = append(subnetRefs, refSubnet)
}
t.Resources["ControlPlaneSecurityGroup"] = &cloudformation.AWSEC2SecurityGroup{
GroupDescription: cloudformation.String("Communication between the control plane and worker node groups"),
VpcId: refVPC,
})
t.Resources["ControlPlane"] = & cloudformation.AWSEKSCluster{
Name: cloudformation.String(c.spec.ClusterName),
RoleArn: cloudformation.MakeFnGetAtt("ServiceRole.Arn"),
Version: cloudformation.String(version),
ResourcesVpcConfig: & cloudformation.AWSEKSCluster_ResourcesVpcConfig{
SubnetIds: subnetRefs,
SecurityGroupIds: []cloudformation.Value{cloudformation.MakeRef("ControlPlaneSecurityGroup")},
},
}
} However, in func (r *resourceSet) newResource(name string, properties interface{}) cloudformation.Value This function adds the resource with so this t.Resource["VPC"] = &cloudformation.AWSEC2VPC{
CidrBlock: cloudformation.String(globalCIDR.String()),
EnableDnsSupport: cloudformation.True,
EnableDnsHostnames: cloudformation.True,
}
refVPC := cloudformation.MakeRef("VPC") becomes refVPC := r.newResource("VPC", &cloudformation.AWSEC2VPC{
CidrBlock: cloudformation.String(globalCIDR.String()),
EnableDnsSupport: cloudformation.True,
EnableDnsHostnames: cloudformation.True,
} If you are intertested, I'm happy to add this here. We have other syntactic sugar, but is a bit more specific to |
I'll go ahead and try to fix the tests, then see what new tests can be added also. |
d5b9bef
to
f8b0e66
Compare
f8b0e66
to
2fd1a77
Compare
@PaulMaddox please review commits separately, not checking generated code doesn't show that tests pass, so I had to do that. |
I have #114 in a good working state now, so am closing this PR in favour of that one |
This is to allow passing references and other intrinsics when constructing a template.
To keep things simple to start with, I've implemented this as a breaking change. We can settle on how it should be done once we have a clearer idea of the exact approach.
Replaces #95.