Skip to content

Commit

Permalink
Azure Container Registry - Update API from 2021-08-01-preview to 2023…
Browse files Browse the repository at this point in the history
…-06-01-preview
  • Loading branch information
magodo committed Jul 25, 2024
1 parent 4546a7a commit 48768c6
Show file tree
Hide file tree
Showing 326 changed files with 4,270 additions and 441 deletions.
8 changes: 4 additions & 4 deletions internal/services/containers/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2023-05-01/containerinstance"
containerregistry_v2019_06_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2019-06-01-preview"
containerregistry_v2021_08_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview"
containerregistry_v2023_06_01_preview "github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/cacherules"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2019-08-01/containerservices"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-09-02-preview/agentpools"
Expand All @@ -28,7 +28,7 @@ type Client struct {
AgentPoolsClient *agentpools.AgentPoolsClient
ContainerInstanceClient *containerinstance.ContainerInstanceClient
CacheRulesClient *cacherules.CacheRulesClient
ContainerRegistryClient_v2021_08_01_preview *containerregistry_v2021_08_01_preview.Client
ContainerRegistryClient_v2023_06_01_preview *containerregistry_v2023_06_01_preview.Client
// v2019_06_01_preview is needed for container registry agent pools and tasks
ContainerRegistryClient_v2019_06_01_preview *containerregistry_v2019_06_01_preview.Client
FleetUpdateRunsClient *updateruns.UpdateRunsClient
Expand Down Expand Up @@ -56,7 +56,7 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) {
return nil, err
}

containerRegistryClient_v2021_08_01_preview, err := containerregistry_v2021_08_01_preview.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
containerRegistryClient_v2023_06_01_preview, err := containerregistry_v2023_06_01_preview.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)
})
if err != nil {
Expand Down Expand Up @@ -128,7 +128,7 @@ func NewContainersClient(o *common.ClientOptions) (*Client, error) {
AgentPoolsClient: agentPoolsClient,
ContainerInstanceClient: containerInstanceClient,
CacheRulesClient: cacheRulesClient,
ContainerRegistryClient_v2021_08_01_preview: containerRegistryClient_v2021_08_01_preview,
ContainerRegistryClient_v2023_06_01_preview: containerRegistryClient_v2023_06_01_preview,
ContainerRegistryClient_v2019_06_01_preview: containerRegistryClient_v2019_06_01_preview,
FleetUpdateRunsClient: fleetUpdateRunsClient,
FleetUpdateStrategiesClient: fleetUpdateStrategiesClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/connectedregistries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/tokens"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/connectedregistries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/tokens"
tfvalidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/parse"
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r ContainerConnectedRegistryResource) Create() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Containers.ContainerRegistryClient_v2021_08_01_preview.ConnectedRegistries
client := metadata.Client.Containers.ContainerRegistryClient_v2023_06_01_preview.ConnectedRegistries

var model ContainerConnectedRegistryModel
if err := metadata.Decode(&model); err != nil {
Expand Down Expand Up @@ -275,7 +275,7 @@ func (r ContainerConnectedRegistryResource) Read() sdk.ResourceFunc {
Timeout: 5 * time.Minute,

Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Containers.ContainerRegistryClient_v2021_08_01_preview.ConnectedRegistries
client := metadata.Client.Containers.ContainerRegistryClient_v2023_06_01_preview.ConnectedRegistries
id, err := connectedregistries.ParseConnectedRegistryID(metadata.ResourceData.Id())
if err != nil {
return err
Expand Down Expand Up @@ -374,7 +374,7 @@ func (r ContainerConnectedRegistryResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 30 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Containers.ContainerRegistryClient_v2021_08_01_preview.ConnectedRegistries
client := metadata.Client.Containers.ContainerRegistryClient_v2023_06_01_preview.ConnectedRegistries

id, err := connectedregistries.ParseConnectedRegistryID(metadata.ResourceData.Id())
if err != nil {
Expand Down Expand Up @@ -404,7 +404,7 @@ func (r ContainerConnectedRegistryResource) Update() sdk.ResourceFunc {
return err
}

client := metadata.Client.Containers.ContainerRegistryClient_v2021_08_01_preview.ConnectedRegistries
client := metadata.Client.Containers.ContainerRegistryClient_v2023_06_01_preview.ConnectedRegistries

existing, err := client.Get(ctx, *id)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"testing"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/connectedregistries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/connectedregistries"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestAccContainerConnectedRegistry_requiresImport(t *testing.T) {
}

func (r ContainerConnectedRegistryResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
client := clients.Containers.ContainerRegistryClient_v2021_08_01_preview.ConnectedRegistries
client := clients.Containers.ContainerRegistryClient_v2023_06_01_preview.ConnectedRegistries

id, err := connectedregistries.ParseConnectedRegistryID(state.ID)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/cacherules"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/cacherules"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-07-01/credentialsets"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/registries"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand All @@ -31,7 +31,7 @@ func dataSourceContainerRegistry() *pluginsdk.Resource {
}

func dataSourceContainerRegistryRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down
78 changes: 11 additions & 67 deletions internal/services/containers/container_registry_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/operation"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2021-08-01-preview/replications"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/operation"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/registries"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerregistry/2023-06-01-preview/replications"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/helpers/validate"
Expand Down Expand Up @@ -164,8 +164,8 @@ func resourceContainerRegistry() *pluginsdk.Resource {
}

func resourceContainerRegistryCreate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
operationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Operation
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
operationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Operation
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand Down Expand Up @@ -297,7 +297,7 @@ func resourceContainerRegistryCreate(d *pluginsdk.ResourceData, meta interface{}
}

func resourceContainerRegistryUpdate(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -487,7 +487,7 @@ func resourceContainerRegistryUpdate(d *pluginsdk.ResourceData, meta interface{}
}

func applyContainerRegistrySku(d *pluginsdk.ResourceData, meta interface{}, sku string, id registries.RegistryId) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand All @@ -506,7 +506,7 @@ func applyContainerRegistrySku(d *pluginsdk.ResourceData, meta interface{}, sku
}

func applyGeoReplicationLocations(ctx context.Context, meta interface{}, registryId registries.RegistryId, oldGeoReplications []replications.Replication, newGeoReplications []replications.Replication) error {
replicationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Replications
replicationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Replications
log.Printf("[INFO] preparing to apply geo-replications for Container Registry.")

oldReplications := map[string]replications.Replication{}
Expand Down Expand Up @@ -635,8 +635,8 @@ func applyGeoReplicationLocations(ctx context.Context, meta interface{}, registr
}

func resourceContainerRegistryRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
replicationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Replications
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
replicationClient := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Replications
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -781,7 +781,7 @@ func resourceContainerRegistryRead(d *pluginsdk.ResourceData, meta interface{})
}

func resourceContainerRegistryDelete(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2021_08_01_preview.Registries
client := meta.(*clients.Client).Containers.ContainerRegistryClient_v2023_06_01_preview.Registries
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

Expand Down Expand Up @@ -815,25 +815,6 @@ func expandNetworkRuleSet(profiles []interface{}) *registries.NetworkRuleSet {
ipRules = append(ipRules, newIpRule)
}

if !features.FourPointOhBeta() {
networkRuleConfigs := profile["virtual_network"].(*pluginsdk.Set).List()
virtualNetworkRules := make([]registries.VirtualNetworkRule, 0)
for _, networkRuleInterface := range networkRuleConfigs {
config := networkRuleInterface.(map[string]interface{})
newVirtualNetworkRule := registries.VirtualNetworkRule{
Action: pointer.To(registries.Action(config["action"].(string))),
Id: config["subnet_id"].(string),
}
virtualNetworkRules = append(virtualNetworkRules, newVirtualNetworkRule)
}

return &registries.NetworkRuleSet{
DefaultAction: registries.DefaultAction(profile["default_action"].(string)),
IPRules: &ipRules,
VirtualNetworkRules: &virtualNetworkRules,
}
}

return &registries.NetworkRuleSet{
DefaultAction: registries.DefaultAction(profile["default_action"].(string)),
IPRules: &ipRules,
Expand Down Expand Up @@ -1010,20 +991,6 @@ func flattenNetworkRuleSet(networkRuleSet *registries.NetworkRuleSet) []interfac

values["ip_rule"] = ipRules

if !features.FourPointOhBeta() {
virtualNetworkRules := make([]interface{}, 0)
if networkRuleSet.VirtualNetworkRules != nil {
for _, virtualNetworkRule := range *networkRuleSet.VirtualNetworkRules {
value := make(map[string]interface{})
value["action"] = string(*virtualNetworkRule.Action)

value["subnet_id"] = virtualNetworkRule.Id
virtualNetworkRules = append(virtualNetworkRules, value)
}
}
values["virtual_network"] = virtualNetworkRules
}

return []interface{}{values}
}

Expand Down Expand Up @@ -1366,29 +1333,6 @@ func resourceContainerRegistrySchema() map[string]*pluginsdk.Schema {
},
},
},

"virtual_network": {
Deprecated: "The property `virtual_network` is deprecated since this is used exclusively for service endpoints which are being deprecated. Users are expected to use Private Endpoints instead. This property will be removed in v4.0 of the AzureRM Provider.",
Type: pluginsdk.TypeSet,
Optional: true,
ConfigMode: pluginsdk.SchemaConfigModeAttr,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"action": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
string(registries.ActionAllow),
}, false),
},
"subnet_id": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: commonids.ValidateSubnetID,
},
},
},
},
},
},
}
Expand Down
Loading

0 comments on commit 48768c6

Please sign in to comment.