-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redis: refactoring to use
hashicorp/go-azure-sdk
(#20313)
Co-authored-by: kt <kt@katbyte.me>
- Loading branch information
1 parent
fdd3382
commit 4560e89
Showing
159 changed files
with
7,849 additions
and
7,917 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,14 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2021-06-01/redis" // nolint: staticcheck | ||
"github.com/Azure/go-autorest/autorest" | ||
redis_2021_06_01 "github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/common" | ||
) | ||
|
||
type Client struct { | ||
Client *redis.Client | ||
FirewallRulesClient *redis.FirewallRulesClient | ||
PatchSchedulesClient *redis.PatchSchedulesClient | ||
LinkedServerClient *redis.LinkedServerClient | ||
} | ||
|
||
func NewClient(o *common.ClientOptions) *Client { | ||
client := redis.NewClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&client.Client, o.ResourceManagerAuthorizer) | ||
|
||
FirewallRulesClient := redis.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&FirewallRulesClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
PatchSchedulesClient := redis.NewPatchSchedulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&PatchSchedulesClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
LinkedServerClient := redis.NewLinkedServerClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) | ||
o.ConfigureClient(&LinkedServerClient.Client, o.ResourceManagerAuthorizer) | ||
|
||
return &Client{ | ||
Client: &client, | ||
FirewallRulesClient: &FirewallRulesClient, | ||
PatchSchedulesClient: &PatchSchedulesClient, | ||
LinkedServerClient: &LinkedServerClient, | ||
} | ||
func NewClient(o *common.ClientOptions) *redis_2021_06_01.Client { | ||
client := redis_2021_06_01.NewClientWithBaseURI(o.ResourceManagerEndpoint, func(c *autorest.Client) { | ||
c.Authorizer = o.ResourceManagerAuthorizer | ||
}) | ||
return &client | ||
} |
61 changes: 61 additions & 0 deletions
61
internal/services/redis/migration/firewall_rule_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,61 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/firewallrules" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = FirewallRuleV0ToV1{} | ||
|
||
type FirewallRuleV0ToV1 struct{} | ||
|
||
func (FirewallRuleV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"redis_cache_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"start_ip": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"end_ip": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
}, | ||
} | ||
} | ||
|
||
func (FirewallRuleV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
oldIdRaw := rawState["id"].(string) | ||
oldId, err := firewallrules.ParseFirewallRuleIDInsensitively(oldIdRaw) | ||
if err != nil { | ||
return rawState, err | ||
} | ||
|
||
newId := oldId.ID() | ||
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) | ||
rawState["id"] = newId | ||
|
||
return rawState, nil | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
internal/services/redis/migration/linked_server_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,68 @@ | ||
package migration | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/hashicorp/go-azure-sdk/resource-manager/redis/2021-06-01/redis" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" | ||
) | ||
|
||
var _ pluginsdk.StateUpgrade = LinkedServerV0ToV1{} | ||
|
||
type LinkedServerV0ToV1 struct{} | ||
|
||
func (LinkedServerV0ToV1) Schema() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"target_redis_cache_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"linked_redis_cache_id": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"linked_redis_cache_location": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"resource_group_name": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"server_role": { | ||
Type: pluginsdk.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
|
||
"name": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
} | ||
} | ||
|
||
func (LinkedServerV0ToV1) UpgradeFunc() pluginsdk.StateUpgraderFunc { | ||
return func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { | ||
oldIdRaw := rawState["id"].(string) | ||
oldId, err := redis.ParseLinkedServerIDInsensitively(oldIdRaw) | ||
if err != nil { | ||
return rawState, err | ||
} | ||
|
||
newId := oldId.ID() | ||
log.Printf("[DEBUG] Updating ID from %q to %q", oldId, newId) | ||
rawState["id"] = newId | ||
|
||
return rawState, nil | ||
} | ||
} |
Oops, something went wrong.