-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
resource_arm_storage_table_migration.go
94 lines (85 loc) · 2.93 KB
/
resource_arm_storage_table_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package storage
import (
"fmt"
"log"
"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/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
)
// the schema schema was used for both V0 and V1
func ResourceStorageTableStateResourceV0V1() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidateArmStorageTableName,
},
"storage_account_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: ValidateArmStorageAccountName,
},
"resource_group_name": azure.SchemaResourceGroupNameDeprecated(),
"acl": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringLenBetween(1, 64),
},
"access_policy": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"start": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"expiry": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"permissions": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
},
},
},
},
}
}
func ResourceStorageTableStateUpgradeV0ToV1(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
tableName := rawState["name"].(string)
accountName := rawState["storage_account_name"].(string)
environment := meta.(*clients.Client).Account.Environment
id := rawState["id"].(string)
newResourceID := fmt.Sprintf("https://%s.table.%s/%s", accountName, environment.StorageEndpointSuffix, tableName)
log.Printf("[DEBUG] Updating ID from %q to %q", id, newResourceID)
rawState["id"] = newResourceID
return rawState, nil
}
func ResourceStorageTableStateUpgradeV1ToV2(rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) {
tableName := rawState["name"].(string)
accountName := rawState["storage_account_name"].(string)
environment := meta.(*clients.Client).Account.Environment
id := rawState["id"].(string)
newResourceID := fmt.Sprintf("https://%s.table.%s/Tables('%s')", accountName, environment.StorageEndpointSuffix, tableName)
log.Printf("[DEBUG] Updating ID from %q to %q", id, newResourceID)
rawState["id"] = newResourceID
return rawState, nil
}