-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathschema_ssh_connection_deployment_target.go
122 lines (96 loc) · 3.77 KB
/
schema_ssh_connection_deployment_target.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
package octopusdeploy
import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandSSHConnectionDeploymentTarget(d *schema.ResourceData) *octopusdeploy.DeploymentTarget {
host := d.Get("host").(string)
port := d.Get("port").(int)
fingerprint := d.Get("fingerprint").(string)
endpoint := octopusdeploy.NewSSHEndpoint(host, port, fingerprint)
if v, ok := d.GetOk("account_id"); ok {
endpoint.AccountID = v.(string)
}
if v, ok := d.GetOk("dot_net_core_platform"); ok {
endpoint.DotNetCorePlatform = v.(string)
}
if v, ok := d.GetOk("proxy_id"); ok {
endpoint.ProxyID = v.(string)
}
deploymentTarget := expandDeploymentTarget(d)
deploymentTarget.Endpoint = endpoint
return deploymentTarget
}
func flattenSSHConnectionDeploymentTarget(deploymentTarget *octopusdeploy.DeploymentTarget) map[string]interface{} {
if deploymentTarget == nil {
return nil
}
flattenedDeploymentTarget := flattenDeploymentTarget(deploymentTarget)
endpointResource, _ := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
flattenedDeploymentTarget["account_id"] = endpointResource.AccountID
flattenedDeploymentTarget["dot_net_core_platform"] = endpointResource.DotNetCorePlatform
flattenedDeploymentTarget["fingerprint"] = endpointResource.Fingerprint
flattenedDeploymentTarget["host"] = endpointResource.Host
flattenedDeploymentTarget["proxy_id"] = endpointResource.ProxyID
flattenedDeploymentTarget["port"] = endpointResource.Port
return flattenedDeploymentTarget
}
func getSSHConnectionDeploymentTargetDataSchema() map[string]*schema.Schema {
dataSchema := getSSHConnectionDeploymentTargetSchema()
setDataSchema(&dataSchema)
deploymentTargetDataSchema := getDeploymentTargetDataSchema()
deploymentTargetDataSchema["ssh_connection_deployment_targets"] = &schema.Schema{
Computed: true,
Description: "A list of SSH connection deployment targets that match the filter(s).",
Elem: &schema.Resource{Schema: dataSchema},
Optional: true,
Type: schema.TypeList,
}
delete(deploymentTargetDataSchema, "communication_styles")
delete(deploymentTargetDataSchema, "deployment_targets")
deploymentTargetDataSchema["id"] = getDataSchemaID()
return deploymentTargetDataSchema
}
func getSSHConnectionDeploymentTargetSchema() map[string]*schema.Schema {
sshConnectionDeploymentTargetSchema := getDeploymentTargetSchema()
sshConnectionDeploymentTargetSchema["account_id"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
sshConnectionDeploymentTargetSchema["dot_net_core_platform"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
sshConnectionDeploymentTargetSchema["fingerprint"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
sshConnectionDeploymentTargetSchema["host"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
sshConnectionDeploymentTargetSchema["port"] = &schema.Schema{
Default: 22,
Optional: true,
Type: schema.TypeInt,
}
sshConnectionDeploymentTargetSchema["proxy_id"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
return sshConnectionDeploymentTargetSchema
}
func setSSHConnectionDeploymentTarget(ctx context.Context, d *schema.ResourceData, deploymentTarget *octopusdeploy.DeploymentTarget) error {
endpointResource, err := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
if err != nil {
return err
}
d.Set("account_id", endpointResource.AccountID)
d.Set("dot_net_core_platform", endpointResource.DotNetCorePlatform)
d.Set("fingerprint", endpointResource.Fingerprint)
d.Set("host", endpointResource.Host)
d.Set("port", endpointResource.Port)
d.Set("proxy_id", endpointResource.ProxyID)
return setDeploymentTarget(ctx, d, deploymentTarget)
}