-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing the Resource ID for
api_management_policy
when this was prov…
…isioned using version `2.92.0` of the Azure Provider (#15060)
- Loading branch information
Showing
3 changed files
with
78 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
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
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,61 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"html" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2021-08-01/apimanagement" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/services/apimanagement/parse" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = ApiManagementApiPolicyV0ToV1{} | ||
|
||
type ApiManagementApiPolicyV0ToV1 struct{} | ||
|
||
func (ApiManagementApiPolicyV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
apiMgmtId, err := parse.ApiManagementID(rawState["id"].(string)) | ||
if err != nil { | ||
return rawState, nil | ||
} | ||
id := parse.NewPolicyID(apiMgmtId.SubscriptionId, apiMgmtId.ResourceGroup, apiMgmtId.ServiceName, "policy") | ||
rawState["id"] = id.ID() | ||
|
||
client := meta.(*clients.Client).ApiManagement.PolicyClient | ||
resp, err := client.Get(ctx, id.ResourceGroup, id.ServiceName, apimanagement.PolicyExportFormatXML) | ||
if err != nil { | ||
return nil, fmt.Errorf("making Read request for API Management Policy (Resource Group %q / API Management Service %q / API %q): %+v", id.ResourceGroup, id.ServiceName, id.Name, err) | ||
} | ||
|
||
if properties := resp.PolicyContractProperties; properties != nil { | ||
// when you submit an `xml_link` to the API, the API downloads this link and stores it as `xml_content` | ||
// as such there is no way to set `xml_link` and we'll let Terraform handle it | ||
rawState["xml_content"] = html.UnescapeString(*properties.Value) | ||
} | ||
return rawState, nil | ||
} | ||
} | ||
|
||
func (ApiManagementApiPolicyV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"api_management_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"xml_content": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"xml_link": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
} | ||
} |