-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_azure_cloud_service_deployment_target.go
140 lines (110 loc) · 4.51 KB
/
schema_azure_cloud_service_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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package octopusdeploy
import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/machines"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandAzureCloudServiceDeploymentTarget(d *schema.ResourceData) *machines.DeploymentTarget {
endpoint := machines.NewAzureCloudServiceEndpoint()
if v, ok := d.GetOk("account_id"); ok {
endpoint.AccountID = v.(string)
}
if v, ok := d.GetOk("cloud_service_name"); ok {
endpoint.CloudServiceName = v.(string)
}
if v, ok := d.GetOk("default_worker_pool_id"); ok {
endpoint.DefaultWorkerPoolID = v.(string)
}
if v, ok := d.GetOk("slot"); ok {
endpoint.Slot = v.(string)
}
if v, ok := d.GetOk("storage_account_name"); ok {
endpoint.StorageAccountName = v.(string)
}
if v, ok := d.GetOk("swap_if_possible"); ok {
endpoint.SwapIfPossible = v.(bool)
}
if v, ok := d.GetOk("use_current_instance_count"); ok {
endpoint.UseCurrentInstanceCount = v.(bool)
}
deploymentTarget := expandDeploymentTarget(d)
deploymentTarget.Endpoint = endpoint
return deploymentTarget
}
func flattenAzureCloudServiceDeploymentTarget(deploymentTarget *machines.DeploymentTarget) map[string]interface{} {
if deploymentTarget == nil {
return nil
}
flattenedDeploymentTarget := flattenDeploymentTarget(deploymentTarget)
endpointResource, _ := machines.ToEndpointResource(deploymentTarget.Endpoint)
flattenedDeploymentTarget["account_id"] = endpointResource.AccountID
flattenedDeploymentTarget["cloud_service_name"] = endpointResource.CloudServiceName
flattenedDeploymentTarget["default_worker_pool_id"] = endpointResource.DefaultWorkerPoolID
flattenedDeploymentTarget["slot"] = endpointResource.Slot
flattenedDeploymentTarget["storage_account_name"] = endpointResource.StorageAccountName
flattenedDeploymentTarget["swap_if_possible"] = endpointResource.SwapIfPossible
flattenedDeploymentTarget["use_current_instance_count"] = endpointResource.UseCurrentInstanceCount
return flattenedDeploymentTarget
}
func getAzureCloudServiceDeploymentTargetDataSchema() map[string]*schema.Schema {
dataSchema := getAzureCloudServiceDeploymentTargetSchema()
setDataSchema(&dataSchema)
deploymentTargetDataSchema := getDeploymentTargetDataSchema()
deploymentTargetDataSchema["azure_cloud_service_deployment_targets"] = &schema.Schema{
Computed: true,
Description: "A list of Azure cloud service 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 getAzureCloudServiceDeploymentTargetSchema() map[string]*schema.Schema {
azureCloudServiceDeploymentTargetSchema := getDeploymentTargetSchema()
azureCloudServiceDeploymentTargetSchema["account_id"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureCloudServiceDeploymentTargetSchema["cloud_service_name"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureCloudServiceDeploymentTargetSchema["default_worker_pool_id"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
azureCloudServiceDeploymentTargetSchema["slot"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
azureCloudServiceDeploymentTargetSchema["storage_account_name"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureCloudServiceDeploymentTargetSchema["swap_if_possible"] = &schema.Schema{
Optional: true,
Type: schema.TypeBool,
}
azureCloudServiceDeploymentTargetSchema["use_current_instance_count"] = &schema.Schema{
Optional: true,
Type: schema.TypeBool,
}
return azureCloudServiceDeploymentTargetSchema
}
func setAzureCloudServiceDeploymentTarget(ctx context.Context, d *schema.ResourceData, deploymentTarget *machines.DeploymentTarget) error {
endpointResource, err := machines.ToEndpointResource(deploymentTarget.Endpoint)
if err != nil {
return err
}
d.Set("account_id", endpointResource.AccountID)
d.Set("cloud_service_name", endpointResource.CloudServiceName)
d.Set("default_worker_pool_id", endpointResource.DefaultWorkerPoolID)
d.Set("slot", endpointResource.Slot)
d.Set("storage_account_name", endpointResource.StorageAccountName)
d.Set("swap_if_possible", endpointResource.SwapIfPossible)
d.Set("use_current_instance_count", endpointResource.UseCurrentInstanceCount)
return setDeploymentTarget(ctx, d, deploymentTarget)
}