-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
frontdoor rules engine - a state migration to work around the previou…
…sly incorrect id casing
- Loading branch information
Showing
7 changed files
with
196 additions
and
17 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
175 changes: 175 additions & 0 deletions
175
internal/services/frontdoor/migration/rules_engine_migration_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,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 | ||
} | ||
} |
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
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