@@ -24,7 +24,6 @@ import (
24
24
"text/tabwriter"
25
25
26
26
"github.com/aws/amazon-ec2-instance-selector/v2/pkg/instancetypes"
27
- "github.com/ghodss/yaml"
28
27
)
29
28
30
29
// SimpleInstanceTypeOutput is an OutputFn which outputs a slice of instance type names
@@ -49,109 +48,6 @@ func VerboseInstanceTypeOutput(instanceTypeInfoSlice []*instancetypes.Details) [
49
48
return []string {string (output )}
50
49
}
51
50
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
-
155
51
// TableOutputShort is an OutputFn which returns a CLI table for easy reading
156
52
func TableOutputShort (instanceTypeInfoSlice []* instancetypes.Details ) []string {
157
53
if len (instanceTypeInfoSlice ) == 0 {
0 commit comments