diff --git a/internal/services/frontdoor/frontdoor_rules_engine_rule.go b/internal/services/frontdoor/frontdoor_rules_engine_rule.go index 32374754f514..31f2ce76af00 100644 --- a/internal/services/frontdoor/frontdoor_rules_engine_rule.go +++ b/internal/services/frontdoor/frontdoor_rules_engine_rule.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/sdk/2020-05-01/frontdoors" azValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/synapse/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -24,7 +25,10 @@ func resourceFrontDoorRulesEngine() *pluginsdk.Resource { Update: resourceFrontDoorRulesEngineCreateUpdate, Delete: resourceFrontDoorRulesEngineDelete, - SchemaVersion: 1, + SchemaVersion: 2, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 1: migration.SynapseLinkedServiceV0ToV1{}, + }), Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.RulesEngineID(id) diff --git a/internal/services/frontdoor/migration/rules_engine_migration_v0_to_v1.go b/internal/services/frontdoor/migration/rules_engine_migration_v0_to_v1.go new file mode 100644 index 000000000000..75d028693443 --- /dev/null +++ b/internal/services/frontdoor/migration/rules_engine_migration_v0_to_v1.go @@ -0,0 +1,175 @@ +package migration + +import ( + "context" + "log" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" +) + +type RulesEngineV0ToV1 struct{} + +func (s RulesEngineV0ToV1) Schema() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + "frontdoor_name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + "location": commonschema.LocationComputed(), + + "resource_group_name": commonschema.ResourceGroupName(), + + "enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: true, + }, + + "rule": { + Type: pluginsdk.TypeList, + MaxItems: 100, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "priority": { + Type: pluginsdk.TypeInt, + Required: true, + }, + + "match_condition": { + Type: pluginsdk.TypeList, + MaxItems: 100, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "variable": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "selector": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "operator": { + Type: pluginsdk.TypeString, + Required: true, + }, + + "transform": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 6, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + + "negate_condition": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + }, + + "value": { + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 25, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + }, + }, + }, + + "action": { + Type: pluginsdk.TypeList, + MaxItems: 1, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "request_header": { + Type: pluginsdk.TypeList, + MaxItems: 100, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "header_action_type": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "header_name": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "value": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + + "response_header": { + Type: pluginsdk.TypeList, + MaxItems: 100, + Optional: true, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "header_action_type": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "header_name": { + Type: pluginsdk.TypeString, + Optional: true, + }, + + "value": { + Type: pluginsdk.TypeString, + Optional: true, + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func (s RulesEngineV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { + return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { + oldId := rawState["id"].(string) + newId, err := parse.RulesEngineIDInsensitively(oldId) + if err != nil { + return nil, err + } + + log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) + + rawState["id"] = newId.ID() + return rawState, nil + } +} diff --git a/internal/services/frontdoor/parse/rules_engine.go b/internal/services/frontdoor/parse/rules_engine.go index 3b73d1552c52..4e43e488abeb 100644 --- a/internal/services/frontdoor/parse/rules_engine.go +++ b/internal/services/frontdoor/parse/rules_engine.go @@ -36,7 +36,7 @@ func (id RulesEngineId) String() string { } func (id RulesEngineId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/frontdoors/%s/rulesengines/%s" + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Network/frontdoors/%s/rulesEngines/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.FrontdoorName, id.Name) } @@ -63,7 +63,7 @@ func RulesEngineID(input string) (*RulesEngineId, error) { if resourceId.FrontdoorName, err = id.PopSegment("frontdoors"); err != nil { return nil, err } - if resourceId.Name, err = id.PopSegment("rulesengines"); err != nil { + if resourceId.Name, err = id.PopSegment("rulesEngines"); err != nil { return nil, err } @@ -111,15 +111,15 @@ func RulesEngineIDInsensitively(input string) (*RulesEngineId, error) { return nil, err } - // find the correct casing for the 'rulesengines' segment - rulesenginesKey := "rulesengines" + // find the correct casing for the 'rulesEngines' segment + rulesEnginesKey := "rulesEngines" for key := range id.Path { - if strings.EqualFold(key, rulesenginesKey) { - rulesenginesKey = key + if strings.EqualFold(key, rulesEnginesKey) { + rulesEnginesKey = key break } } - if resourceId.Name, err = id.PopSegment(rulesenginesKey); err != nil { + if resourceId.Name, err = id.PopSegment(rulesEnginesKey); err != nil { return nil, err } diff --git a/internal/services/frontdoor/parse/rules_engine_test.go b/internal/services/frontdoor/parse/rules_engine_test.go index 7e7cba8fdb6f..7540ea89794b 100644 --- a/internal/services/frontdoor/parse/rules_engine_test.go +++ b/internal/services/frontdoor/parse/rules_engine_test.go @@ -12,7 +12,7 @@ var _ resourceids.Id = RulesEngineId{} func TestRulesEngineIDFormatter(t *testing.T) { actual := NewRulesEngineID("12345678-1234-9876-4563-123456789012", "resGroup1", "frontdoor1", "rule1").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1" + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1" if actual != expected { t.Fatalf("Expected %q but got %q", expected, actual) } @@ -75,13 +75,13 @@ func TestRulesEngineID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1", Expected: &RulesEngineId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", @@ -184,13 +184,13 @@ func TestRulesEngineIDInsensitively(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/", Error: true, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1", Expected: &RulesEngineId{ SubscriptionId: "12345678-1234-9876-4563-123456789012", ResourceGroup: "resGroup1", diff --git a/internal/services/frontdoor/resourceids.go b/internal/services/frontdoor/resourceids.go index b562b6af18c2..a125677bbfb9 100644 --- a/internal/services/frontdoor/resourceids.go +++ b/internal/services/frontdoor/resourceids.go @@ -9,4 +9,4 @@ package frontdoor //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=WebApplicationFirewallPolicy -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontDoorWebApplicationFirewallPolicies/policy1 -rewrite=true //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=CustomHttpsConfiguration -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontDoors/frontdoor1/customHttpsConfiguration/endpoint1 -rewrite=true //go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=LoadBalancingRule -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/loadBalancers/loadBalancer1/loadBalancingRules/rule1 -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=RulesEngine -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1 -rewrite=true +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=RulesEngine -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1 -rewrite=true diff --git a/internal/services/frontdoor/validate/rules_engine_id_test.go b/internal/services/frontdoor/validate/rules_engine_id_test.go index aaa77d2128cc..6ed2e048bf9f 100644 --- a/internal/services/frontdoor/validate/rules_engine_id_test.go +++ b/internal/services/frontdoor/validate/rules_engine_id_test.go @@ -60,13 +60,13 @@ func TestRulesEngineID(t *testing.T) { { // missing value for Name - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/", Valid: false, }, { // valid - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1", + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1", Valid: true, }, diff --git a/website/docs/r/frontdoor_rules_engine.html.markdown b/website/docs/r/frontdoor_rules_engine.html.markdown index ed8a9287892c..f4aa7e78121b 100644 --- a/website/docs/r/frontdoor_rules_engine.html.markdown +++ b/website/docs/r/frontdoor_rules_engine.html.markdown @@ -178,5 +178,5 @@ The `match_condition` block supports the following: Azure Front Door Rules Engine's can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_frontdoor_rules_engine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesengines/rule1 +terraform import azurerm_frontdoor_rules_engine.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resGroup1/providers/Microsoft.Network/frontdoors/frontdoor1/rulesEngines/rule1 ```