forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_arm_servicebus_namespace_migration.go
41 lines (32 loc) · 1.15 KB
/
resource_arm_servicebus_namespace_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
package azurerm
import (
"fmt"
"log"
"strings"
"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
"github.com/hashicorp/terraform/terraform"
)
func resourceAzureRMServiceBusNamespaceMigrateState(
v int, is *terraform.InstanceState, meta interface{}) (*terraform.InstanceState, error) {
switch v {
case 0:
log.Println("[INFO] Found AzureRM ServiceBus Namespace State v0; migrating to v1")
return migrateAzureRMServiceBusNamespaceStateV0toV1(is)
default:
return is, fmt.Errorf("Unexpected schema version: %d", v)
}
}
func migrateAzureRMServiceBusNamespaceStateV0toV1(is *terraform.InstanceState) (*terraform.InstanceState, error) {
if is.Empty() {
log.Println("[DEBUG] Empty InstanceState; nothing to migrate.")
return is, nil
}
log.Printf("[DEBUG] ARM ServiceBus Namespace Attributes before Migration: %#v", is.Attributes)
skuName := strings.ToLower(is.Attributes["sku"])
premiumSku := strings.ToLower(string(servicebus.Premium))
if skuName != premiumSku {
delete(is.Attributes, "capacity")
}
log.Printf("[DEBUG] ARM ServiceBus Namespace Attributes after State Migration: %#v", is.Attributes)
return is, nil
}