Skip to content

Commit

Permalink
support migrating resources from azurerm to azapi provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ms-henglu committed Oct 8, 2024
1 parent 551058f commit ffd1327
Show file tree
Hide file tree
Showing 20 changed files with 1,698 additions and 1,156 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Unreleased

FEATURES:
- Support migrating resources from `azurerm` provider to `azapi` provider.

## v2.0.0-beta

Target azurerm version: v4.0.0
Expand Down
318 changes: 318 additions & 0 deletions azurerm/coverage/tf.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,310 @@
[
{
"api_version": "2023-06-01-preview",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.CONTAINERREGISTRY/REGISTRIES/{}",
"operation": "DELETE"
},
{
"api_version": "2023-06-01-preview",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.CONTAINERREGISTRY/REGISTRIES/{}",
"operation": "GET",
"properties": [
{
"addr": "identity/principalId"
},
{
"addr": "identity/tenantId"
},
{
"addr": "identity/type"
},
{
"addr": "identity/userAssignedIdentities"
},
{
"addr": "location",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/location"
}
]
},
{
"addr": "properties/adminUserEnabled"
},
{
"addr": "properties/anonymousPullEnabled"
},
{
"addr": "properties/dataEndpointEnabled"
},
{
"addr": "properties/encryption/keyVaultProperties/identity",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/encryption/0/identity_client_id"
}
]
},
{
"addr": "properties/encryption/keyVaultProperties/keyIdentifier",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/encryption/0/key_vault_key_id"
}
]
},
{
"addr": "properties/encryption/status"
},
{
"addr": "properties/loginServer",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/login_server"
}
]
},
{
"addr": "properties/networkRuleBypassOptions",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/network_rule_bypass_option"
}
]
},
{
"addr": "properties/networkRuleSet/defaultAction",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/network_rule_set/0/default_action"
}
]
},
{
"addr": "properties/networkRuleSet/ipRules/action"
},
{
"addr": "properties/networkRuleSet/ipRules/value"
},
{
"addr": "properties/policies/exportPolicy/status"
},
{
"addr": "properties/policies/quarantinePolicy/status"
},
{
"addr": "properties/policies/retentionPolicy/days"
},
{
"addr": "properties/policies/retentionPolicy/status"
},
{
"addr": "properties/policies/trustPolicy/status"
},
{
"addr": "properties/policies/trustPolicy/type"
},
{
"addr": "properties/publicNetworkAccess"
},
{
"addr": "properties/zoneRedundancy"
},
{
"addr": "sku/name"
},
{
"addr": "sku/tier",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/sku"
}
]
},
{
"addr": "tags"
}
]
},
{
"api_version": "2023-06-01-preview",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.CONTAINERREGISTRY/REGISTRIES/{}",
"operation": "PUT",
"properties": [
{
"addr": "identity/principalId"
},
{
"addr": "identity/tenantId"
},
{
"addr": "identity/type"
},
{
"addr": "identity/userAssignedIdentities"
},
{
"addr": "properties/adminUserEnabled"
},
{
"addr": "properties/anonymousPullEnabled"
},
{
"addr": "properties/dataEndpointEnabled"
},
{
"addr": "properties/encryption/keyVaultProperties/identity",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/encryption/0/identity_client_id"
}
]
},
{
"addr": "properties/encryption/keyVaultProperties/keyIdentifier",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/encryption/0/key_vault_key_id"
}
]
},
{
"addr": "properties/encryption/status"
},
{
"addr": "properties/networkRuleBypassOptions",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/network_rule_bypass_option"
}
]
},
{
"addr": "properties/networkRuleSet/defaultAction",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/network_rule_set/0/default_action"
}
]
},
{
"addr": "properties/networkRuleSet/ipRules/action"
},
{
"addr": "properties/networkRuleSet/ipRules/value"
},
{
"addr": "properties/policies/exportPolicy/status"
},
{
"addr": "properties/policies/quarantinePolicy/status"
},
{
"addr": "properties/policies/retentionPolicy/days"
},
{
"addr": "properties/policies/retentionPolicy/status"
},
{
"addr": "properties/policies/trustPolicy/status"
},
{
"addr": "properties/policies/trustPolicy/type"
},
{
"addr": "properties/publicNetworkAccess"
},
{
"addr": "sku/name"
},
{
"addr": "sku/tier",
"app_property_maps": [
{
"name": "azurerm_container_registry",
"addr": "/sku"
}
]
},
{
"addr": "tags"
}
]
},
{
"api_version": "2023-11-01",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.NETWORK/SERVICEENDPOINTPOLICIES/{}",
"operation": "GET",
"properties": [
{
"addr": "location",
"app_property_maps": [
{
"name": "azurerm_subnet_service_endpoint_storage_policy",
"addr": "/location"
}
]
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/name"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/description"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/service"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/serviceResources"
},
{
"addr": "tags"
}
]
},
{
"api_version": "2023-11-01",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.NETWORK/SERVICEENDPOINTPOLICIES/{}",
"operation": "PUT",
"properties": [
{
"addr": "location",
"app_property_maps": [
{
"name": "azurerm_subnet_service_endpoint_storage_policy",
"addr": "/location"
}
]
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/name"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/description"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/service"
},
{
"addr": "properties/serviceEndpointPolicyDefinitions/properties/serviceResources"
},
{
"addr": "tags"
}
]
},
{
"api_version": "2015-10-31",
"api_path": "/SUBSCRIPTIONS/{}/RESOURCEGROUPS/{}/PROVIDERS/MICROSOFT.AUTOMATION/AUTOMATIONACCOUNTS/{}",
Expand All @@ -15,6 +321,15 @@
{
"addr": "properties/sku/name"
},
{
"addr": "identity/type"
},
{
"addr": "identity/tenantId"
},
{
"addr": "identity/principalId"
},
{
"addr": "tags"
}
Expand All @@ -31,6 +346,9 @@
{
"addr": "properties/sku/name"
},
{
"addr": "identity/type"
},
{
"addr": "tags"
}
Expand Down
44 changes: 44 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd_test

import tfjson "github.com/hashicorp/terraform-json"

type Action string

const (
ActionCreate Action = "create"
ActionReplace Action = "replace"
ActionUpdate Action = "update"
ActionDelete Action = "delete"
)

// Actions denotes a valid change type.
type Actions []Action

func GetChanges(plan *tfjson.Plan) []Action {
if plan == nil {
return []Action{}
}
actions := make([]Action, 0)
for _, change := range plan.ResourceChanges {
if change.Change != nil {
if len(change.Change.Actions) == 0 {
continue
}
if len(change.Change.Actions) == 1 {
switch change.Change.Actions[0] {
case tfjson.ActionCreate:
actions = append(actions, ActionCreate)
case tfjson.ActionDelete:
actions = append(actions, ActionDelete)
case tfjson.ActionUpdate:
actions = append(actions, ActionUpdate)
case tfjson.ActionNoop:
case tfjson.ActionRead:
}
} else {
actions = append(actions, ActionReplace)
}
}
}
return actions
}
Loading

0 comments on commit ffd1327

Please sign in to comment.