-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
resource_arm_storage_share_migration.go
78 lines (65 loc) · 2.23 KB
/
resource_arm_storage_share_migration.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
package azurerm
import (
"fmt"
"log"
"strings"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/tombuildsstuff/giovanni/storage/2018-11-09/file/shares"
)
// the schema schema was used for both V0 and V1
func resourceStorageShareStateResourceV0V1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateArmStorageShareName,
},
"resource_group_name": azure.SchemaResourceGroupName(),
"storage_account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"quota": {
Type: schema.TypeInt,
Optional: true,
Default: 5120,
ValidateFunc: validation.IntBetween(1, 5120),
},
"url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func resourceStorageShareStateUpgradeV0ToV1(rawState map[string]interface{}, _ interface{}) (map[string]interface{}, error) {
shareName := rawState["name"].(string)
resourceGroup := rawState["resource_group_name"].(string)
accountName := rawState["storage_account_name"].(string)
id := rawState["id"].(string)
newResourceID := fmt.Sprintf("%s/%s/%s", shareName, resourceGroup, accountName)
log.Printf("[DEBUG] Updating ID from %q to %q", id, newResourceID)
rawState["id"] = newResourceID
return rawState, nil
}
func resourceStorageShareStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
id := rawState["id"].(string)
// name/resourceGroup/accountName
parsedId := strings.Split(id, "/")
if len(parsedId) != 3 {
return rawState, fmt.Errorf("Expected 3 segments in the ID but got %d", len(parsedId))
}
shareName := parsedId[0]
accountName := parsedId[2]
environment := meta.(*ArmClient).environment
client := shares.NewWithEnvironment(environment)
newResourceId := client.GetResourceID(accountName, shareName)
log.Printf("[DEBUG] Updating Resource ID from %q to %q", id, newResourceId)
rawState["id"] = newResourceId
return rawState, nil
}