-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_polling_tentacle_deployment_target.go
103 lines (79 loc) · 3.53 KB
/
schema_polling_tentacle_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
package octopusdeploy
import (
"context"
"fmt"
"net/url"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandPollingTentacleDeploymentTarget(d *schema.ResourceData) *octopusdeploy.DeploymentTarget {
tentacleURL, _ := url.Parse(d.Get("tentacle_url").(string))
thumbprint := d.Get("thumbprint").(string)
endpoint := octopusdeploy.NewPollingTentacleEndpoint(tentacleURL, thumbprint)
if v, ok := d.GetOk("certificate_signature_algorithm"); ok {
endpoint.CertificateSignatureAlgorithm = v.(string)
}
if v, ok := d.GetOk("tentacle_version_details"); ok {
endpoint.TentacleVersionDetails = expandTentacleVersionDetails(v)
}
deploymentTarget := expandDeploymentTarget(d)
deploymentTarget.Endpoint = endpoint
return deploymentTarget
}
func flattenPollingTentacleDeploymentTarget(deploymentTarget *octopusdeploy.DeploymentTarget) map[string]interface{} {
if deploymentTarget == nil {
return nil
}
flattenedDeploymentTarget := flattenDeploymentTarget(deploymentTarget)
endpointResource, _ := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
flattenedDeploymentTarget["certificate_signature_algorithm"] = endpointResource.CertificateSignatureAlgorithm
flattenedDeploymentTarget["tentacle_version_details"] = flattenTentacleVersionDetails(endpointResource.TentacleVersionDetails)
flattenedDeploymentTarget["tentacle_url"] = endpointResource.URI.String()
return flattenedDeploymentTarget
}
func getPollingTentacleDeploymentTargetDataSchema() map[string]*schema.Schema {
dataSchema := getPollingTentacleDeploymentTargetSchema()
setDataSchema(&dataSchema)
deploymentTargetDataSchema := getDeploymentTargetDataSchema()
deploymentTargetDataSchema["polling_tentacle_deployment_targets"] = &schema.Schema{
Computed: true,
Description: "A list of polling tentacle 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 getPollingTentacleDeploymentTargetSchema() map[string]*schema.Schema {
pollingTentacleDeploymentTargetSchema := getDeploymentTargetSchema()
pollingTentacleDeploymentTargetSchema["certificate_signature_algorithm"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
pollingTentacleDeploymentTargetSchema["tentacle_version_details"] = &schema.Schema{
Computed: true,
Elem: &schema.Resource{Schema: getTentacleVersionDetailsSchema()},
Optional: true,
Type: schema.TypeList,
}
pollingTentacleDeploymentTargetSchema["tentacle_url"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
return pollingTentacleDeploymentTargetSchema
}
func setPollingTentacleDeploymentTarget(ctx context.Context, d *schema.ResourceData, deploymentTarget *octopusdeploy.DeploymentTarget) error {
endpointResource, err := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
if err != nil {
return err
}
d.Set("certificate_signature_algorithm", endpointResource.CertificateSignatureAlgorithm)
if err := d.Set("tentacle_version_details", flattenTentacleVersionDetails(endpointResource.TentacleVersionDetails)); err != nil {
return fmt.Errorf("error setting tentacle_version_details: %s", err)
}
d.Set("tentacle_url", endpointResource.URI.String())
return setDeploymentTarget(ctx, d, deploymentTarget)
}