generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 40
/
infra_aws_winrm.go
132 lines (111 loc) · 3.89 KB
/
infra_aws_winrm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package environment
import (
"fmt"
"strings"
"github.com/harness/harness-go-sdk/harness/cd/cac"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func infraDetailsAwsWinRM() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"autoscaling_group_name": {
Description: "The name of the autoscaling group.",
Type: schema.TypeString,
Required: true,
},
"cloud_provider_name": {
Description: "The name of the cloud provider to connect with.",
Type: schema.TypeString,
Required: true,
},
"desired_capacity": {
Description: "The desired capacity of the autoscaling group.",
Type: schema.TypeInt,
Optional: true,
},
"host_connection_attrs_name": {
Description: "The name of the host connection attributes to use.",
Type: schema.TypeString,
Required: true,
},
"host_connection_type": {
Description: fmt.Sprintf("The type of host connection to use. Valid options are %s", strings.Join(cac.HostConnectionTypesSlice, ", ")),
Type: schema.TypeString,
Required: true,
},
"hostname_convention": {
Description: fmt.Sprintf("The naming convention to use for the hostname. Defaults to %s", DefaultHostnameConvention),
Type: schema.TypeString,
Optional: true,
Default: DefaultHostnameConvention,
},
"loadbalancer_name": {
Description: "The name of the load balancer to use.",
Type: schema.TypeString,
Optional: true,
},
"region": {
Description: "The region to deploy to.",
Type: schema.TypeString,
Required: true,
},
},
}
}
func expandAwsWinRMConfiguration(d []interface{}, infraDef *cac.InfrastructureDefinition) {
if len(d) == 0 {
return
}
config := d[0].(map[string]interface{})
details := &cac.InfrastructureAwsWinRM{}
if attr := config["autoscaling_group_name"]; attr != nil {
details.AutoscalingGroupName = attr.(string)
details.UseAutoScalingGroup = true
}
if attr := config["cloud_provider_name"]; attr != "" {
details.CloudProviderName = attr.(string)
}
if attr := config["desired_capacity"]; attr != "" {
details.DesiredCapacity = attr.(int)
if details.DesiredCapacity > 0 {
details.SetDesiredCapacity = true
}
}
if attr := config["host_connection_attrs_name"]; attr != "" {
details.HostConnectionAttrsName = attr.(string)
}
if attr := config["host_connection_type"]; attr != "" {
details.HostConnectionType = cac.HostConnectionType(attr.(string))
}
if attr := config["hostname_convention"]; attr != "" {
details.HostNameConvention = attr.(string)
}
if attr := config["loadbalancer_name"]; attr != "" {
details.LoadBalancerName = attr.(string)
}
if attr := config["region"]; attr != "" {
details.Region = attr.(string)
}
infraDef.InfrastructureDetail = details.ToInfrastructureDetail()
}
func flattenAwsWinRMConfiguration(d *schema.ResourceData, infraDef *cac.InfrastructureDefinition) []interface{} {
results := []interface{}{}
if len(infraDef.InfrastructureDetail) == 0 {
return results
}
detail := infraDef.InfrastructureDetail[0]
if detail.Type == cac.InfrastructureTypes.AwsSSH && infraDef.DeploymentType == cac.DeploymentTypes.WinRM {
detailConfig := map[string]interface{}{}
infraDetail := detail.ToAwsWinRm()
detailConfig["autoscaling_group_name"] = infraDetail.AutoscalingGroupName
detailConfig["cloud_provider_name"] = infraDetail.CloudProviderName
detailConfig["desired_capacity"] = infraDetail.DesiredCapacity
detailConfig["host_connection_attrs_name"] = infraDetail.HostConnectionAttrsName
detailConfig["host_connection_type"] = infraDetail.HostConnectionType
detailConfig["hostname_convention"] = infraDetail.HostNameConvention
detailConfig["loadbalancer_name"] = infraDetail.LoadBalancerName
detailConfig["region"] = infraDetail.Region
results = append(results, detailConfig)
}
return results
}