Skip to content

Commit a52d98e

Browse files
authored
remove infra generation output option (#127)
1 parent 44f699a commit a52d98e

File tree

6 files changed

+0
-227
lines changed

6 files changed

+0
-227
lines changed

cmd/main.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ const (
4242
awsConfigFile = "~/.aws/config"
4343
spotPricingDaysBack = 30
4444

45-
// cfnJSON is an output type
46-
cfnJSON = "cfn-json"
47-
// cfnYAML is an output type
48-
cfnYAML = "cfn-yaml"
49-
terraformHCL = "terraform-hcl"
5045
tableOutput = "table"
5146
tableWideOutput = "table-wide"
5247
oneLine = "one-line"
@@ -384,12 +379,6 @@ func getOutputFn(outputFlag *string, currentFn selector.InstanceTypesOutputFn) s
384379
outputFn := selector.InstanceTypesOutputFn(currentFn)
385380
if outputFlag != nil {
386381
switch *outputFlag {
387-
case cfnJSON:
388-
return selector.InstanceTypesOutputFn(outputs.CloudFormationSpotMixedInstancesPolicyJSONOutput)
389-
case cfnYAML:
390-
return selector.InstanceTypesOutputFn(outputs.CloudFormationSpotMixedInstancesPolicyYAMLOutput)
391-
case terraformHCL:
392-
return selector.InstanceTypesOutputFn(outputs.TerraformSpotMixedInstancesPolicyHCLOutput)
393382
case tableWideOutput:
394383
return selector.InstanceTypesOutputFn(outputs.TableOutputWide)
395384
case tableOutput:

go.mod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ go 1.17
55
require (
66
github.com/aws/aws-sdk-go v1.43.31
77
github.com/blang/semver/v4 v4.0.0
8-
github.com/ghodss/yaml v1.0.0
9-
github.com/hashicorp/hcl v1.0.0
108
github.com/imdario/mergo v0.3.11
119
github.com/mitchellh/go-homedir v1.1.0
1210
github.com/patrickmn/go-cache v2.1.0+incompatible
@@ -21,5 +19,4 @@ require (
2119
github.com/jmespath/go-jmespath v0.4.0 // indirect
2220
github.com/smartystreets/goconvey v1.6.4 // indirect
2321
go.uber.org/atomic v1.4.0 // indirect
24-
gopkg.in/yaml.v2 v2.3.0 // indirect
2522
)

go.sum

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
2424
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
2525
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
2626
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
27-
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
2827
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
2928
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
3029
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
@@ -45,7 +44,6 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
4544
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
4645
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
4746
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
48-
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
4947
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
5048
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
5149
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
@@ -63,10 +61,8 @@ github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvW
6361
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
6462
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
6563
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
66-
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
6764
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
6865
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
69-
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
7066
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
7167
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
7268
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
@@ -159,7 +155,6 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi
159155
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
160156
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
161157
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
162-
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
163158
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
164159
gopkg.in/ini.v1 v1.57.0 h1:9unxIsFcTt4I55uWluz+UmL95q4kdJ0buvQ1ZIqVQww=
165160
gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

pkg/selector/outputs/outputs.go

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"text/tabwriter"
2525

2626
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/instancetypes"
27-
"github.com/ghodss/yaml"
2827
)
2928

3029
// SimpleInstanceTypeOutput is an OutputFn which outputs a slice of instance type names
@@ -49,109 +48,6 @@ func VerboseInstanceTypeOutput(instanceTypeInfoSlice []*instancetypes.Details) [
4948
return []string{string(output)}
5049
}
5150

52-
// TerraformSpotMixedInstancesPolicyHCLOutput is an OutputFn which returns an ASG MixedInstancePolicy in Terraform HCL syntax
53-
func TerraformSpotMixedInstancesPolicyHCLOutput(instanceTypeInfoSlice []*instancetypes.Details) []string {
54-
instanceTypeOverrides := instanceTypeInfoToOverrides(instanceTypeInfoSlice)
55-
overridesString := ""
56-
for _, override := range instanceTypeOverrides {
57-
overridesString = overridesString + fmt.Sprintf(`
58-
override {
59-
instance_type = "%s"
60-
}
61-
`, override.InstanceType)
62-
}
63-
asgResource := fmt.Sprintf(`resource "aws_autoscaling_group" "AutoScalingGroupMIG" {
64-
vpc_zone_identifier = [
65-
"REPLACE_WITH_SUBNET_ID"
66-
]
67-
68-
name = "AutoScalingGroupMIG"
69-
max_size = 0
70-
min_size = 0
71-
desired_capacity = 0
72-
73-
mixed_instances_policy {
74-
instances_distribution {
75-
on_demand_base_capacity = 0
76-
on_demand_percentage_above_base_capacity = 0
77-
spot_allocation_strategy = "capacity-optimized"
78-
}
79-
80-
launch_template {
81-
launch_template_specification {
82-
launch_template_id = "REPLACE_WITH_LAUNCH_TEMPLATE_ID"
83-
version = "$$Latest"
84-
}
85-
86-
%s
87-
}
88-
}
89-
}
90-
provider "aws" {
91-
region = "us-east-1"
92-
}
93-
`, overridesString)
94-
95-
return []string{asgResource}
96-
}
97-
98-
// CloudFormationSpotMixedInstancesPolicyYAMLOutput is an OutputFn which returns an ASG MixedInstancePolicy in CloudFormation YAML syntax
99-
func CloudFormationSpotMixedInstancesPolicyYAMLOutput(instanceTypeInfoSlice []*instancetypes.Details) []string {
100-
instanceTypeOverrides := instanceTypeInfoToOverrides(instanceTypeInfoSlice)
101-
cfnMig := getCfnMIGResources(instanceTypeOverrides)
102-
cfnMigYAML, err := yaml.Marshal(cfnMig)
103-
if err != nil {
104-
log.Printf("Unable to create CloudFormation YAML: %v\n", err)
105-
}
106-
return []string{string(cfnMigYAML)}
107-
}
108-
109-
// CloudFormationSpotMixedInstancesPolicyJSONOutput is an OutputFn which returns an MixedInstancePolicy in CloudFormation JSON syntax
110-
func CloudFormationSpotMixedInstancesPolicyJSONOutput(instanceTypeInfoSlice []*instancetypes.Details) []string {
111-
instanceTypeOverrides := instanceTypeInfoToOverrides(instanceTypeInfoSlice)
112-
cfnMig := getCfnMIGResources(instanceTypeOverrides)
113-
cfnJSONMig, err := json.MarshalIndent(cfnMig, "", " ")
114-
if err != nil {
115-
log.Printf("Unable to create CloudFormation JSON: %v\n", err)
116-
return []string{}
117-
}
118-
return []string{string(cfnJSONMig)}
119-
}
120-
121-
func getCfnMIGResources(instanceTypeOverrides []InstanceTypeOverride) Resources {
122-
resources := map[string]AutoScalingGroup{}
123-
resources["AutoScalingGroupMIG"] = AutoScalingGroup{
124-
Type: typeASG,
125-
Properties: AutoScalingGroupProperties{
126-
AutoScalingGroupName: "REPLACE_WITH_NAME",
127-
VPCZoneIdentifier: []string{"replace-with-subnet-ids"},
128-
MixedInstancesPolicy: MixedInstancesPolicy{
129-
InstancesDistribution: InstancesDistribution{
130-
OnDemandBaseCapacity: 0,
131-
OnDemandPercentageAboveBaseCapacity: 0,
132-
SpotAllocationStrategy: capacityOptimized,
133-
},
134-
LaunchTemplate: LaunchTemplate{
135-
LaunchTemplateSpecification: LaunchTemplateSpecification{
136-
LaunchTemplateID: "REPLACE_WITH_LAUNCH_TEMPLATE_ID",
137-
Version: "REPLACE_WITH_VERSION",
138-
},
139-
Overrides: instanceTypeOverrides,
140-
},
141-
},
142-
},
143-
}
144-
return Resources{Resources: resources}
145-
}
146-
147-
func instanceTypeInfoToOverrides(instanceTypeInfoSlice []*instancetypes.Details) []InstanceTypeOverride {
148-
instanceTypeOverrides := []InstanceTypeOverride{}
149-
for _, instanceTypeInfo := range instanceTypeInfoSlice {
150-
instanceTypeOverrides = append(instanceTypeOverrides, InstanceTypeOverride{InstanceType: *instanceTypeInfo.InstanceType})
151-
}
152-
return instanceTypeOverrides
153-
}
154-
15551
// TableOutputShort is an OutputFn which returns a CLI table for easy reading
15652
func TableOutputShort(instanceTypeInfoSlice []*instancetypes.Details) []string {
15753
if len(instanceTypeInfoSlice) == 0 {

pkg/selector/outputs/outputs_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/selector/outputs"
2525
h "github.com/aws/amazon-ec2-instance-selector/v2/pkg/test"
2626
"github.com/aws/aws-sdk-go/service/ec2"
27-
"github.com/ghodss/yaml"
28-
"github.com/hashicorp/hcl"
2927
)
3028

3129
const (
@@ -77,33 +75,6 @@ func TestVerboseInstanceTypeOutput(t *testing.T) {
7775
h.Assert(t, len(instanceTypeOut) == 0, "Should return 0 instance types when passed nil")
7876
}
7977

80-
func TestTerraformSpotMixedInstancesPolicyHCLOutput(t *testing.T) {
81-
instanceTypes := getInstanceTypes(t, "t3_micro.json")
82-
instanceTypeOut := outputs.TerraformSpotMixedInstancesPolicyHCLOutput(instanceTypes)
83-
outputStr := strings.Join(instanceTypeOut, "")
84-
_, err := hcl.ParseString(outputStr)
85-
h.Ok(t, err)
86-
h.Assert(t, strings.Contains(outputStr, `instance_type = "t3.micro"`), "HCL should include a t3.micro instanceType override")
87-
}
88-
89-
func TestCloudFormationSpotMixedInstancesPolicyYAMLOutput(t *testing.T) {
90-
instanceTypes := getInstanceTypes(t, "t3_micro.json")
91-
instanceTypeOut := outputs.CloudFormationSpotMixedInstancesPolicyYAMLOutput(instanceTypes)
92-
outputStr := strings.Join(instanceTypeOut, "")
93-
_, err := yaml.YAMLToJSON([]byte(outputStr))
94-
h.Ok(t, err)
95-
h.Assert(t, strings.Contains(outputStr, `InstanceType: t3.micro`), "CFN Yaml should include a t3.micro InstanceType override")
96-
}
97-
98-
func TestCloudFormationSpotMixedInstancesPolicyJSONOutput(t *testing.T) {
99-
instanceTypes := getInstanceTypes(t, "t3_micro.json")
100-
instanceTypeOut := outputs.CloudFormationSpotMixedInstancesPolicyJSONOutput(instanceTypes)
101-
outputStr := strings.Join(instanceTypeOut, "")
102-
_, err := yaml.JSONToYAML([]byte(outputStr))
103-
h.Ok(t, err)
104-
h.Assert(t, strings.Contains(outputStr, `"InstanceType": "t3.micro"`), "CFN JSON should include a t3.micro InstanceType override")
105-
}
106-
10778
func TestTableOutputShort(t *testing.T) {
10879
instanceTypes := getInstanceTypes(t, "t3_micro.json")
10980
instanceTypeOut := outputs.TableOutputShort(instanceTypes)

pkg/selector/outputs/types.go

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)