-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_api_management_api_policy
, azurerm_api_management_api_operation_policy
, azurerm_api_management_product_policy
: fix parsing resource id error
#23128
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = ApiManagementApiOperationPolicyV1ToV2{} | ||
|
||
type ApiManagementApiOperationPolicyV1ToV2 struct{} | ||
|
||
func (ApiManagementApiOperationPolicyV1ToV2) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
|
||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"api_management_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"api_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"operation_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"xml_content": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"xml_link": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
} | ||
} | ||
|
||
func (ApiManagementApiOperationPolicyV1ToV2) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
// old id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/instance1/apis/api1/operations/operation1/policies/policy | ||
// new id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/instance1/apis/api1/operations/operation1 | ||
oldId := rawState["id"].(string) | ||
|
||
// Prior to v3.70.0 of Terraform Provider, after importing resource, the id in state file ends with "/policies/policy", the id in state file ends with "/policies/xml" for creating resource by Terraform. | ||
// So after migrating pandora SDK (starting from v3.70.0), these two cases need to be migrated. | ||
// In ApiManagementApiPolicyV0ToV1, only the case where the ID ends with "/policies/xml" is processed, so the case where the ID ends with "/policies/policy" is processed here to solve the parse id error. | ||
newId := strings.TrimSuffix(oldId, "/policies/policy") | ||
|
||
log.Printf("[DEBUG] Updating ID from %q tmakeo %q", oldId, newId) | ||
rawState["id"] = newId | ||
|
||
return rawState, nil | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,65 @@ | ||||||||||||||||||||||||||||
package migration | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import ( | ||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||
"log" | ||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
var _ pluginsdk.StateUpgrade = ApiManagementApiPolicyV1ToV2{} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
type ApiManagementApiPolicyV1ToV2 struct{} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func (ApiManagementApiPolicyV1ToV2) Schema() map[string]*pluginsdk.Schema { | ||||||||||||||||||||||||||||
return map[string]*pluginsdk.Schema{ | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"resource_group_name": { | ||||||||||||||||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||
Required: true, | ||||||||||||||||||||||||||||
ForceNew: true, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"api_management_name": { | ||||||||||||||||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||
Required: true, | ||||||||||||||||||||||||||||
ForceNew: true, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"api_name": { | ||||||||||||||||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||
Required: true, | ||||||||||||||||||||||||||||
ForceNew: true, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"xml_content": { | ||||||||||||||||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||
Optional: true, | ||||||||||||||||||||||||||||
Computed: true, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
"xml_link": { | ||||||||||||||||||||||||||||
Type: pluginsdk.TypeString, | ||||||||||||||||||||||||||||
Optional: true, | ||||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
func (ApiManagementApiPolicyV1ToV2) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||||||||||||||||||||||||||||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||||||||||||||||||||||||||||
// old id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/apis/exampleId/policies/policy | ||||||||||||||||||||||||||||
// new id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/apis/exampleId | ||||||||||||||||||||||||||||
oldId := rawState["id"].(string) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// Prior to v3.70.0 of Terraform Provider, after importing resource, the id in state file ends with "/policies/policy", the id in state file ends with "/policies/xml" for creating resource by Terraform. | ||||||||||||||||||||||||||||
// So after migrating pandora SDK (starting from v3.70.0), these two cases need to be migrated. | ||||||||||||||||||||||||||||
// In ApiManagementApiPolicyV0ToV1, only the case where the ID ends with "/policies/xml" is processed, so the case where the ID ends with "/policies/policy" is processed here to solve the parse id error. | ||||||||||||||||||||||||||||
newId := strings.TrimSuffix(oldId, "/policies/policy") | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) | ||||||||||||||||||||||||||||
rawState["id"] = newId | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we parse the updated ID and reformat it such that we can ensure the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return rawState, nil | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = ApiManagementProductPolicyV1ToV2{} | ||
|
||
type ApiManagementProductPolicyV1ToV2 struct{} | ||
|
||
func (ApiManagementProductPolicyV1ToV2) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"api_management_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"product_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"xml_content": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
|
||
"xml_link": { | ||
Type: pluginsdk.TypeString, | ||
Optional: true, | ||
}, | ||
} | ||
} | ||
|
||
func (ApiManagementProductPolicyV1ToV2) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
// old id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/products/exampleId/policies/policy | ||
// new id : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.ApiManagement/service/service1/products/exampleId | ||
oldId := rawState["id"].(string) | ||
|
||
// Prior to v3.70.0 of Terraform Provider, after importing resource, the id in state file ends with "/policies/policy", the id in state file ends with "/policies/xml" for creating resource by Terraform. | ||
// So after migrating pandora SDK (starting from v3.70.0), these two cases need to be migrated. | ||
// In ApiManagementApiPolicyV0ToV1, only the case where the ID ends with "/policies/xml" is processed, so the case where the ID ends with "/policies/policy" is processed here to solve the parse id error. | ||
newId := strings.TrimSuffix(oldId, "/policies/policy") | ||
|
||
log.Printf("[DEBUG] Updating ID from %q tmakeo %q", oldId, newId) | ||
rawState["id"] = newId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (same here / as above) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
return rawState, nil | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.