forked from hashicorp/terraform-provider-azurerm
/
resource_arm_storage_share_migration.go
39 lines (31 loc) · 1.09 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
package azurerm
import (
"fmt"
"log"
"github.com/hashicorp/terraform/terraform"
)
func resourceStorageShareMigrateState(
v int, is *terraform.InstanceState, _ interface{}) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Println("[INFO] Found AzureRM Storage Share State v0; migrating to v1")
return migrateStorageShareStateV0toV1(is)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
}
func migrateStorageShareStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
if is.Empty() {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
log.Printf("[DEBUG] ARM Storage Share Attributes before Migration: %#v", is.Attributes)
name := is.Attributes["name"]
resourceGroupName := is.Attributes["resource_group_name"]
storageAccountName := is.Attributes["storage_account_name"]
newID := fmt.Sprintf("%s/%s/%s", name, resourceGroupName, storageAccountName)
is.Attributes["id"] = newID
is.ID = newID
log.Printf("[DEBUG] ARM Storage Share Attributes after State Migration: %#v", is.Attributes)
return is, nil
}