-
Notifications
You must be signed in to change notification settings - Fork 65
/
schema_azure_web_app_deployment_target.go
107 lines (83 loc) · 3.33 KB
/
schema_azure_web_app_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
package octopusdeploy
import (
"context"
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func expandAzureWebAppDeploymentTarget(d *schema.ResourceData) *octopusdeploy.DeploymentTarget {
endpoint := octopusdeploy.NewAzureWebAppEndpoint()
if v, ok := d.GetOk("account_id"); ok {
endpoint.AccountID = v.(string)
}
if v, ok := d.GetOk("resource_group_name"); ok {
endpoint.ResourceGroupName = v.(string)
}
if v, ok := d.GetOk("web_app_name"); ok {
endpoint.WebAppName = v.(string)
}
if v, ok := d.GetOk("web_app_slot_name"); ok {
endpoint.WebAppSlotName = v.(string)
}
deploymentTarget := expandDeploymentTarget(d)
deploymentTarget.Endpoint = endpoint
return deploymentTarget
}
func flattenAzureWebAppDeploymentTarget(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["resource_group_name"] = endpointResource.ResourceGroupName
flattenedDeploymentTarget["web_app_name"] = endpointResource.WebAppName
flattenedDeploymentTarget["web_app_slot_name"] = endpointResource.WebAppSlotName
return flattenedDeploymentTarget
}
func getAzureWebAppDeploymentTargetDataSchema() map[string]*schema.Schema {
dataSchema := getAzureWebAppDeploymentTargetSchema()
setDataSchema(&dataSchema)
deploymentTargetDataSchema := getDeploymentTargetDataSchema()
deploymentTargetDataSchema["azure_web_app_deployment_targets"] = &schema.Schema{
Computed: true,
Description: "A list of Azure web app 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 getAzureWebAppDeploymentTargetSchema() map[string]*schema.Schema {
azureWebAppDeploymentTargetSchema := getDeploymentTargetSchema()
azureWebAppDeploymentTargetSchema["account_id"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureWebAppDeploymentTargetSchema["resource_group_name"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureWebAppDeploymentTargetSchema["web_app_name"] = &schema.Schema{
Required: true,
Type: schema.TypeString,
}
azureWebAppDeploymentTargetSchema["web_app_slot_name"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}
return azureWebAppDeploymentTargetSchema
}
func setAzureWebAppDeploymentTarget(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("resource_group_name", endpointResource.ResourceGroupName)
d.Set("web_app_name", endpointResource.WebAppName)
d.Set("web_app_slot_name", endpointResource.WebAppSlotName)
return setDeploymentTarget(ctx, d, deploymentTarget)
}