forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_https_configuration.go
118 lines (101 loc) · 3.06 KB
/
custom_https_configuration.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
package migration
import (
"context"
"fmt"
"log"
"strings"
"github.com/kevinklinger/terraform-provider-azurerm/v2/helpers/azure"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/frontdoor/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
)
var _ pluginsdk.StateUpgrade = CustomHttpsConfigurationV0ToV1{}
type CustomHttpsConfigurationV0ToV1 struct{}
func (CustomHttpsConfigurationV0ToV1) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"frontend_endpoint_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"custom_https_provisioning_enabled": {
Type: pluginsdk.TypeBool,
Required: true,
},
//lintignore:XS003
"custom_https_configuration": {
Type: pluginsdk.TypeList,
Optional: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"certificate_source": {
Type: pluginsdk.TypeString,
Optional: true,
},
"azure_key_vault_certificate_secret_name": {
Type: pluginsdk.TypeString,
Optional: true,
},
"azure_key_vault_certificate_secret_version": {
Type: pluginsdk.TypeString,
Optional: true,
},
"azure_key_vault_certificate_vault_id": {
Type: pluginsdk.TypeString,
Optional: true,
},
"minimum_tls_version": {
Type: pluginsdk.TypeString,
Computed: true,
},
"provisioning_state": {
Type: pluginsdk.TypeString,
Computed: true,
},
"provisioning_substate": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
"resource_group_name": {
Type: pluginsdk.TypeString,
Required: true,
},
}
}
func (CustomHttpsConfigurationV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
// this was: fmt.Sprintf("%s/customHttpsConfiguration/%s", frontEndEndpointId, frontendEndpointName
oldId := rawState["id"].(string)
oldParsedId, err := azure.ParseAzureResourceID(oldId)
if err != nil {
return rawState, err
}
resourceGroup := oldParsedId.ResourceGroup
frontdoorName := ""
frontendEndpointName := ""
for key, value := range oldParsedId.Path {
if strings.EqualFold(key, "frontdoors") {
frontdoorName = value
continue
}
if strings.EqualFold(key, "frontendEndpoints") {
frontendEndpointName = value
continue
}
}
if frontdoorName == "" {
return rawState, fmt.Errorf("couldn't find the `frontdoors` segment in the old resource id %q", oldId)
}
if frontendEndpointName == "" {
return rawState, fmt.Errorf("couldn't find the `frontendEndpoints` segment in the old resource id %q", oldId)
}
newId := parse.NewFrontendEndpointID(oldParsedId.SubscriptionID, resourceGroup, frontdoorName, frontendEndpointName)
newIdStr := newId.ID()
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newIdStr)
rawState["id"] = newIdStr
return rawState, nil
}
}