forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.go
97 lines (89 loc) · 2.25 KB
/
blob.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
package migration
import (
"context"
"fmt"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/clients"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
)
var _ pluginsdk.StateUpgrade = BlobV0ToV1{}
type BlobV0ToV1 struct{}
func (BlobV0ToV1) Schema() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"resource_group_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"storage_account_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"storage_container_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
},
"type": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
},
"size": {
Type: pluginsdk.TypeInt,
Optional: true,
ForceNew: true,
Default: 0,
},
"content_type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: "application/octet-stream",
ConflictsWith: []string{"source_uri"},
},
"source": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"source_uri"},
},
"source_uri": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"source"},
},
"url": {
Type: pluginsdk.TypeString,
Computed: true,
},
"parallelism": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 8,
ForceNew: true,
},
"attempts": {
Type: pluginsdk.TypeInt,
Optional: true,
Default: 1,
ForceNew: true,
},
}
}
func (BlobV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc {
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
environment := meta.(*clients.Client).Account.Environment
blobName := rawState["name"]
containerName := rawState["storage_container_name"]
storageAccountName := rawState["storage_account_name"]
newID := fmt.Sprintf("https://%s.blob.%s/%s/%s", storageAccountName, environment.StorageEndpointSuffix, containerName, blobName)
rawState["id"] = newID
return rawState, nil
}
}