forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/communication_service: adding a state migration to fix hashicorp#17532
- Loading branch information
1 parent
082f57e
commit b3f38fa
Showing
2 changed files
with
85 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
internal/services/communication/migration/service_v0_to_v1.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/communication/2020-08-20/communicationservice" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = ServiceV0ToV1{} | ||
|
||
type ServiceV0ToV1 struct{} | ||
|
||
func (ServiceV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"data_location": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Default: "United States", | ||
}, | ||
|
||
"tags": { | ||
Type: schema.TypeMap, | ||
Optional: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
|
||
"primary_connection_string": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"secondary_connection_string": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"primary_key": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"secondary_key": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
} | ||
} | ||
|
||
func (ServiceV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
oldId := rawState["id"].(string) | ||
parsedId, err := communicationservice.ParseCommunicationServiceIDInsensitively(oldId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
newId := parsedId.ID() | ||
log.Printf("[DEBUG] Updating ID from %q to %q..", oldId, newId) | ||
rawState["id"] = newId | ||
return rawState, nil | ||
} | ||
} |