-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_offline_package_drop_deployment_target.go
104 lines (80 loc) · 3.44 KB
/
schema_offline_package_drop_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
package octopusdeploy
import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandOfflinePackageDropDeploymentTarget(d *schema.ResourceData) *octopusdeploy.DeploymentTarget {
endpoint := octopusdeploy.NewOfflinePackageDropEndpoint()
if v, ok := d.GetOk("applications_directory"); ok {
endpoint.ApplicationsDirectory = v.(string)
}
if v, ok := d.GetOk("destination"); ok {
endpoint.Destination = expandOfflinePackageDropDestination(v)
}
if v, ok := d.GetOk("working_directory"); ok {
endpoint.WorkingDirectory = v.(string)
}
deploymentTarget := expandDeploymentTarget(d)
deploymentTarget.Endpoint = endpoint
return deploymentTarget
}
func flattenOfflinePackageDropDeploymentTarget(deploymentTarget *octopusdeploy.DeploymentTarget) map[string]interface{} {
if deploymentTarget == nil {
return nil
}
flattenedDeploymentTarget := flattenDeploymentTarget(deploymentTarget)
endpointResource, _ := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
flattenedDeploymentTarget["applications_directory"] = endpointResource.ApplicationsDirectory
flattenedDeploymentTarget["destination"] = flattenOfflinePackageDropDestination(endpointResource.Destination)
flattenedDeploymentTarget["working_directory"] = endpointResource.WorkingDirectory
return flattenedDeploymentTarget
}
func getOfflinePackageDropDeploymentTargetDataSchema() map[string]*schema.Schema {
dataSchema := getOfflinePackageDropDeploymentTargetSchema()
setDataSchema(&dataSchema)
deploymentTargetDataSchema := getDeploymentTargetDataSchema()
deploymentTargetDataSchema["offline_package_drop_deployment_targets"] = &schema.Schema{
Computed: true,
Description: "A list of offline package drop 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 getOfflinePackageDropDeploymentTargetSchema() map[string]*schema.Schema {
offlinePackageDropDeploymentTargetSchema := getDeploymentTargetSchema()
offlinePackageDropDeploymentTargetSchema["applications_directory"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
offlinePackageDropDeploymentTargetSchema["destination"] = &schema.Schema{
Computed: true,
Elem: &schema.Resource{Schema: getOfflinePackageDropDestinationSchema()},
Optional: true,
MaxItems: 1,
Type: schema.TypeList,
}
offlinePackageDropDeploymentTargetSchema["working_directory"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
return offlinePackageDropDeploymentTargetSchema
}
func setOfflinePackageDropDeploymentTarget(ctx context.Context, d *schema.ResourceData, deploymentTarget *octopusdeploy.DeploymentTarget) error {
endpointResource, err := octopusdeploy.ToEndpointResource(deploymentTarget.Endpoint)
if err != nil {
return err
}
d.Set("applications_directory", endpointResource.ApplicationsDirectory)
if err := d.Set("destination", flattenOfflinePackageDropDestination(endpointResource.Destination)); err != nil {
return fmt.Errorf("error setting destination: %s", err)
}
d.Set("working_directory", endpointResource.WorkingDirectory)
return setDeploymentTarget(ctx, d, deploymentTarget)
}