Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_container_registry - deprecating the georeplication_locations property in favour of the georeplications property #11200

Conversation

ms-henglu
Copy link
Contributor

@ms-henglu ms-henglu commented Apr 2, 2021

The test results are listed as follows.

=== RUN   TestAccContainerRegistry_geoReplication
=== PAUSE TestAccContainerRegistry_geoReplication
=== CONT  TestAccContainerRegistry_geoReplication
--- PASS: TestAccContainerRegistry_geoReplication (501.49s)

=== RUN   TestAccContainerRegistry_geoReplicationLocation
=== PAUSE TestAccContainerRegistry_geoReplicationLocation
=== CONT  TestAccContainerRegistry_geoReplicationLocation
--- PASS: TestAccContainerRegistry_geoReplicationLocation (519.45s)

=== RUN   TestAccContainerRegistry_geoReplicationSwitch
=== PAUSE TestAccContainerRegistry_geoReplicationSwitch
=== CONT  TestAccContainerRegistry_geoReplicationSwitch
--- PASS: TestAccContainerRegistry_geoReplicationSwitch (418.32s)

Copy link
Contributor

@ArcturusZhang ArcturusZhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ms-henglu thank you for opening this PR!

This basically looks good to me 👍 aside from some inline comments and some recommendations on test case enhancement, please take a look, thanks

Optional: true,
Computed: true, // TODO -- remove this when deprecation resolves
ConflictsWith: []string{"georeplication_locations"},
ConfigMode: schema.SchemaConfigModeAttr,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some comments to describe the reason for this attribute here?
And also this also need a TODO -- remove in 3.0 comment.

Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringIsNotEmpty,
},
Set: location.HashCode,
},

"georeplications": {
Type: schema.TypeList,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need this to be a Set considering that we are using Set for the attribute georeplication_locations which we are replacing with this new block? Or List could meet the requirement here, the Set for georeplication_locations is an overkill?
To determine this, would the service accept an input with two elements with the same location but different tags?
Or would the service always return the response in the same order as the request?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think List is enough, since service always return the response in the same order as the request.

ref: https://github.com/microsoft/terraform-provider-azurerm/wiki/R-1006

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another reason to use list, is that there's an issue about optional-computed set, state won't be updated after applying, unless refresh.
hashicorp/terraform-plugin-sdk#618

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If order doesn't matter this should be a set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change it to set.

Comment on lines 368 to 392
if geoReplicationLocations != nil && geoReplicationLocations.Len() > 0 {
// the ACR is being created so no previous geo-replication locations
oldGeoReplicationLocations := []interface{}{}
err = applyGeoReplicationLocations(d, meta, resourceGroup, name, oldGeoReplicationLocations, geoReplicationLocations.List())
var oldGeoReplicationLocations []*containerregistry.Replication
err = applyGeoReplicationLocations(d, meta, resourceGroup, name, oldGeoReplicationLocations, expandReplicationsFromLocations(geoReplicationLocations.List()))
if err != nil {
return fmt.Errorf("Error applying geo replications for Container Registry %q (Resource Group %q): %+v", name, resourceGroup, err)
}
}
// geo replications have been specified
if len(geoReplications) > 0 {
// the ACR is being created so no previous geo-replication locations
var oldGeoReplicationLocations []*containerregistry.Replication
err = applyGeoReplicationLocations(d, meta, resourceGroup, name, oldGeoReplicationLocations, expandReplications(geoReplications))
if err != nil {
return fmt.Errorf("Error applying geo replications for Container Registry %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part looks a bit redundant - could we combine these two if's by saying first determine the newGeoReplicationLocations and then call the applyGeoReplicationLocations to apply them? It helps to make things more clear here

Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("sku").HasValue(skuBasic),
check.That(data.ResourceName).Key("georeplication_locations.#").HasValue("0"),
check.That(data.ResourceName).Key("georeplications.#").HasValue("0"),
),
},
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that we could introduce a update case to update only the tags propertyin thegeoReplicationLocation? also could we add a case with multiple location entries with the corresponding update cases? Finally to make sure this would not break our existing customer - could we add a test case that ensures if we switch the config written using georeplication_locationsto a config written usinggeoreplications` will give us no-diff?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the advice.
I updated the tests to test

  1. tags
  2. multiple locations
  3. switch from georeplication_locations to georeplications

@@ -58,6 +58,14 @@ The following arguments are supported:

~> **NOTE:** The `georeplication_locations` list cannot contain the location where the Container Registry exists.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COuld we also add the deprecation information to follow the Optional? Like this:

  • georeplication_locations - (Optional / Deprecated in favor of georeplications) A list of Azure locations where the container registry should be geo-replicated.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can just remove it, but either works

@ms-henglu ms-henglu force-pushed the branch-00000-add-resource-container-registry-replication-new branch 2 times, most recently from d952835 to c77fdad Compare April 14, 2021 03:41
@ms-henglu
Copy link
Contributor Author

@ArcturusZhang hi, I have added a commit to add more tests and fix some issues. Please review again, thanks!

@ms-henglu ms-henglu closed this Apr 16, 2021
@ms-henglu ms-henglu reopened this Apr 16, 2021
@ms-henglu ms-henglu force-pushed the branch-00000-add-resource-container-registry-replication-new branch 2 times, most recently from efdf3f1 to 93e39ab Compare April 16, 2021 03:47
@ghost ghost added the dependencies label Apr 16, 2021
@ms-henglu
Copy link
Contributor Author

@katbyte hi, I change the type to set, please check again, thanks!

@katbyte katbyte added this to the v2.57.0 milestone Apr 19, 2021
@ArcturusZhang
Copy link
Contributor

Hey @ms-henglu looks like we are having conflicts in this PR now, could you please resolve the conflict?

@ms-henglu ms-henglu force-pushed the branch-00000-add-resource-container-registry-replication-new branch from 93e39ab to e08fb47 Compare April 20, 2021 01:36
@ms-henglu
Copy link
Contributor Author

@ArcturusZhang hi, thanks! I have resolved the conflicts by removing latest commit go mod vendor

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from a couple minor comments this LGTM 👍

}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't aks?

Suggested change
name = "acctestRG-aks-%d"
name = "acctestRG-acr-%d"

@@ -58,6 +58,14 @@ The following arguments are supported:

~> **NOTE:** The `georeplication_locations` list cannot contain the location where the Container Registry exists.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can just remove it, but either works


* `location` - (Required) A location where the container registry should be geo-replicated.

* `tags` - (Optional) A mapping of tags to assign to the container registry replication resource.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phrasing

Suggested change
* `tags` - (Optional) A mapping of tags to assign to the container registry replication resource.
* `tags` - (Optional) A mapping of tags to assign to this replication location.

}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "acctestRG-aks-%d"
name = "acctestRG-acr-%d"

}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

}

resource "azurerm_resource_group" "test" {
name = "acctestRG-aks-%d"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@ms-henglu
Copy link
Contributor Author

@katbyte ,hi, I add one commit to fix it, please check again, thanks!

@katbyte katbyte changed the title add container registry georeplications property azurerm_container_registry - deprecating the georeplication_locations property in favour of the georeplications property Apr 20, 2021
@katbyte katbyte merged commit 7888c96 into hashicorp:master Apr 20, 2021
katbyte added a commit that referenced this pull request Apr 20, 2021
@ghost
Copy link

ghost commented Apr 30, 2021

This has been released in version 2.57.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.57.0"
}
# ... other configuration ...

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants