-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_token_password
- Handle gone container registry token and mark this password as gone
#27232
Merged
stephybun
merged 7 commits into
hashicorp:main
from
magodo:acr_token_password_markasgone
Nov 15, 2024
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d89b363
Update
magodo 6156283
Update internal/services/containers/container_registry_token_password…
magodo 0100768
Merge remote-tracking branch 'upstream/main' into acr_token_password_…
magodo cd57967
Merge main and pass tests
magodo 90476b1
rename test cases
magodo 8d3f369
Revert "rename test cases"
magodo d807b05
Skip the test cases
magodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -56,7 +56,7 @@ func TestAccContainerRegistryTokenPassword_update(t *testing.T) { | |
data := acceptance.BuildTestData(t, "azurerm_container_registry_token_password", "test") | ||
r := ContainerRegistryTokenPasswordResource{Expiry: time.Now().Add(time.Hour)} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
data.ResourceTestIgnoreRecreate(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basic(data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
|
@@ -86,7 +86,7 @@ func TestAccContainerRegistryTokenPassword_updateExpiryReflectNewValue(t *testin | |
data := acceptance.BuildTestData(t, "azurerm_container_registry_token_password", "test") | ||
r := ContainerRegistryTokenPasswordResource{} | ||
|
||
data.ResourceTest(t, r, []acceptance.TestStep{ | ||
data.ResourceTestIgnoreRecreate(t, r, []acceptance.TestStep{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same applies to this test. |
||
{ | ||
Config: r.expiryReflectValue(data, time.Now().Add(time.Hour).Format(time.RFC3339), "password1"), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
|
@@ -104,6 +104,28 @@ func TestAccContainerRegistryTokenPassword_updateExpiryReflectNewValue(t *testin | |
}) | ||
} | ||
|
||
func TestAccContainerRegistryTokenPassword_replace(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_container_registry_token_password", "test") | ||
r := ContainerRegistryTokenPasswordResource{Expiry: time.Now().Add(time.Hour)} | ||
|
||
data.ResourceTestIgnoreRecreate(t, r, []acceptance.TestStep{ | ||
{ | ||
Config: r.basicWithACRName("acctest1", data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep("password1.0.value"), | ||
{ | ||
Config: r.basicWithACRName("acctest2", data), | ||
Check: acceptance.ComposeTestCheckFunc( | ||
check.That(data.ResourceName).ExistsInAzure(r), | ||
), | ||
}, | ||
data.ImportStep("password1.0.value"), | ||
}) | ||
} | ||
|
||
func TestAccContainerRegistryTokenPassword_requiresImport(t *testing.T) { | ||
data := acceptance.BuildTestData(t, "azurerm_container_registry_token_password", "test") | ||
r := ContainerRegistryTokenPasswordResource{Expiry: time.Now().Add(time.Hour)} | ||
|
@@ -249,3 +271,50 @@ resource "azurerm_container_registry_token" "test" { | |
} | ||
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) | ||
} | ||
|
||
func (r ContainerRegistryTokenPasswordResource) basicWithACRName(name string, data acceptance.TestData) string { | ||
template := r.templateWithACRName(name, data) | ||
return fmt.Sprintf(` | ||
%s | ||
|
||
resource "azurerm_container_registry_token_password" "test" { | ||
container_registry_token_id = azurerm_container_registry_token.test.id | ||
password1 {} | ||
} | ||
`, template) | ||
} | ||
|
||
func (r ContainerRegistryTokenPasswordResource) templateWithACRName(name string, data acceptance.TestData) string { | ||
return fmt.Sprintf(` | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
resource "azurerm_resource_group" "test" { | ||
name = "acctestRG-acr-%d" | ||
location = "%s" | ||
} | ||
|
||
resource "azurerm_container_registry" "test" { | ||
name = "%s%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
location = azurerm_resource_group.test.location | ||
sku = "Premium" | ||
admin_enabled = true | ||
} | ||
|
||
# use system wide scope map for tests | ||
data "azurerm_container_registry_scope_map" "pull_repos" { | ||
name = "_repositories_pull" | ||
container_registry_name = azurerm_container_registry.test.name | ||
resource_group_name = azurerm_container_registry.test.resource_group_name | ||
} | ||
|
||
resource "azurerm_container_registry_token" "test" { | ||
name = "testtoken-%d" | ||
resource_group_name = azurerm_resource_group.test.name | ||
container_registry_name = azurerm_container_registry.test.name | ||
scope_map_id = data.azurerm_container_registry_scope_map.pull_repos.id | ||
} | ||
`, data.RandomInteger, data.Locations.Primary, name, data.RandomInteger, data.RandomInteger) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are called
_update
so presumably they're checking that certain properties are updating correctly on the resource and not triggering a ForceNew, which means that this isn't a proper fix for the test and is masking an underlying issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason can be found at:
terraform-provider-azurerm/internal/services/containers/container_registry_token_password_resource.go
Lines 59 to 66 in cd57967
Due to this bug, we are not able to update it, but can only recreate a new token password. This doesn't make a big difference for this resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the test called
_update
is misleading then since we're not actually updating anything, either the config should be adjusted so that we're actually correctly testing the update of update-able properties, or the test should be renamed or removed since we don't typically test forForceNew
behavioursThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I skip these two test cases now until we migrated to fw.