forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_arm_storage_container_migration.go
39 lines (30 loc) · 1.17 KB
/
resource_arm_storage_container_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 resourceStorageContainerMigrateState(v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Println("[INFO] Found AzureRM Storage Container State v0; migrating to v1")
return migrateStorageContainerStateV0toV1(is, meta)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
}
func migrateStorageContainerStateV0toV1(is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
if is.Empty() {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
log.Printf("[DEBUG] ARM Storage Container Attributes before Migration: %#v", is.Attributes)
environment := meta.(*ArmClient).environment
containerName := is.Attributes["name"]
storageAccountName := is.Attributes["storage_account_name"]
newID := fmt.Sprintf("https://%s.blob.%s/%s", storageAccountName, environment.StorageEndpointSuffix, containerName)
is.Attributes["id"] = newID
is.ID = newID
log.Printf("[DEBUG] ARM Storage Container Attributes after State Migration: %#v", is.Attributes)
return is, nil
}