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

New DataSource: azurerm_key_vault_certificates #19498

Merged

Conversation

harshavmb
Copy link
Contributor

Support new data source azurerm_key_vault_certificates

Fixes 19451

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.

Thanks @harshavmb, looks good overall but we have a test failure:

------- Stdout: -------
=== RUN   TestAccDataSourceKeyVaultCertificates_basic
=== PAUSE TestAccDataSourceKeyVaultCertificates_basic
=== CONT  TestAccDataSourceKeyVaultCertificates_basic
    testcase.go:110: Step 1/1 error: Error running apply: exit status 1
        
        Error: making Read request on Azure KeyVault "Vault: (Name \"acctestkeyvaultoo3qd\" / Resource Group \"acctestRG-221205172152005995\")": keyvault.BaseClient#GetCertificates: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=*******;oid=3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21;numgroups=9;iss=https://sts.windows.net/*******/' does not have certificates list permission on key vault 'acctestkeyvaultoo3qd;location=westus2'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"}
        
          with data.azurerm_key_vault_certificates.test,
          on terraform_plugin_test.tf line 157, in data "azurerm_key_vault_certificates" "test":
         157: data "azurerm_key_vault_certificates" "test" {
        
--- FAIL: TestAccDataSourceKeyVaultCertificates_basic (474.80s)
FAIL

@harshavmb
Copy link
Contributor Author

Thanks @harshavmb, looks good overall but we have a test failure:

------- Stdout: -------
=== RUN   TestAccDataSourceKeyVaultCertificates_basic
=== PAUSE TestAccDataSourceKeyVaultCertificates_basic
=== CONT  TestAccDataSourceKeyVaultCertificates_basic
    testcase.go:110: Step 1/1 error: Error running apply: exit status 1
        
        Error: making Read request on Azure KeyVault "Vault: (Name \"acctestkeyvaultoo3qd\" / Resource Group \"acctestRG-221205172152005995\")": keyvault.BaseClient#GetCertificates: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=*******;oid=3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21;numgroups=9;iss=https://sts.windows.net/*******/' does not have certificates list permission on key vault 'acctestkeyvaultoo3qd;location=westus2'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"}
        
          with data.azurerm_key_vault_certificates.test,
          on terraform_plugin_test.tf line 157, in data "azurerm_key_vault_certificates" "test":
         157: data "azurerm_key_vault_certificates" "test" {
        
--- FAIL: TestAccDataSourceKeyVaultCertificates_basic (474.80s)
FAIL

Thanks @harshavmb, looks good overall but we have a test failure:

------- Stdout: -------
=== RUN   TestAccDataSourceKeyVaultCertificates_basic
=== PAUSE TestAccDataSourceKeyVaultCertificates_basic
=== CONT  TestAccDataSourceKeyVaultCertificates_basic
    testcase.go:110: Step 1/1 error: Error running apply: exit status 1
        
        Error: making Read request on Azure KeyVault "Vault: (Name \"acctestkeyvaultoo3qd\" / Resource Group \"acctestRG-221205172152005995\")": keyvault.BaseClient#GetCertificates: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=*******;oid=3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21;numgroups=9;iss=https://sts.windows.net/*******/' does not have certificates list permission on key vault 'acctestkeyvaultoo3qd;location=westus2'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"}
        
          with data.azurerm_key_vault_certificates.test,
          on terraform_plugin_test.tf line 157, in data "azurerm_key_vault_certificates" "test":
         157: data "azurerm_key_vault_certificates" "test" {
        
--- FAIL: TestAccDataSourceKeyVaultCertificates_basic (474.80s)
FAIL

Hello @katbyte ,

I've added missing permissions for tests to succeed.

@harshavmb harshavmb requested a review from katbyte December 6, 2022 20:56
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @harshavmb

Thanks for this PR - I've taken a look through and left some comments inline, but if we can fix those up then we should be able to take another look/get this merged 👍

Thanks!

Comment on lines 21 to 32
check.That(data.ResourceName).Key("names.#").HasValue("9"),
),
},
})
}

func (KeyVaultCertificatesDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_key_vault_certificate" "test2" {
count = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

we're creating 10 of these, so this would indicate that we're not paging or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Paging happens after 25 resources as per doc here.
So, left untouched.

Copy link
Contributor

Choose a reason for hiding this comment

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

so could we create 26 for test purposes to check we cross the boundary?

website/docs/d/key_vault_certificates.html.markdown Outdated Show resolved Hide resolved
website/docs/d/key_vault_certificates.html.markdown Outdated Show resolved Hide resolved
website/docs/d/key_vault_certificates.html.markdown Outdated Show resolved Hide resolved
@harshavmb
Copy link
Contributor Author

hey @harshavmb

Thanks for this PR - I've taken a look through and left some comments inline, but if we can fix those up then we should be able to take another look/get this merged 👍

Thanks!

Hi @tombuildsstuff ,

I've made changes as per your review. Let me know if it looks good.

@harshavmb harshavmb requested review from tombuildsstuff and katbyte and removed request for katbyte and tombuildsstuff December 7, 2022 15:50
Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

One comment but this otherwise LGTM 👍

Comment on lines 21 to 32
check.That(data.ResourceName).Key("names.#").HasValue("9"),
),
},
})
}

func (KeyVaultCertificatesDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s

resource "azurerm_key_vault_certificate" "test2" {
count = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

so could we create 26 for test purposes to check we cross the boundary?

@harshavmb
Copy link
Contributor Author

One comment but this otherwise LGTM 👍

Sure, I've increased tests to 30 now just to be in sync with secrets data source.

From my state file ::

"names": [ "certificate-0", "certificate-1", "certificate-10", "certificate-11", "certificate-12", "certificate-13", "certificate-14", "certificate-15", "certificate-16", "certificate-17", "certificate-18", "certificate-19", "certificate-2", "certificate-20", "certificate-21", "certificate-22", "certificate-23", "certificate-24", "certificate-25", "certificate-26", "certificate-27", "certificate-28", "certificate-29", "certificate-3", "certificate-4", "certificate-5", "certificate-6", "certificate-7", "certificate-8", "certificate-9" ],

@harshavmb harshavmb requested review from katbyte and tombuildsstuff and removed request for katbyte December 16, 2022 10:23
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.

Thanks @harshavmb - looks good aside from a test failure:

------- Stdout: -------
=== RUN   TestAccDataSourceKeyVaultCertificates_basic
=== PAUSE TestAccDataSourceKeyVaultCertificates_basic
=== CONT  TestAccDataSourceKeyVaultCertificates_basic
    testcase.go:110: Step 1/1 error: Error running apply: exit status 1
        
        Error: A resource with the ID "/subscriptions/*******/resourceGroups/acctestRG-221219175714268125/providers/Microsoft.KeyVault/vaults/acctestkeyvault8ck08/objectId/3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_key_vault_access_policy" for more information.
        
          with azurerm_key_vault_access_policy.certificates,
          on terraform_plugin_test.tf line 157, in resource "azurerm_key_vault_access_policy" "certificates":
         157: resource "azurerm_key_vault_access_policy" "certificates" {
        
        
        Error: retrieving Vault: (Name "acctestkeyvault8ck08" / Resource Group "acctestRG-221219175714268125"): keyvault.BaseClient#GetCertificates: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="Forbidden" Message="The user, group or application 'appid=*******;oid=3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21;numgroups=9;iss=https://sts.windows.net/*******/' does not have certificates list permission on key vault 'acctestkeyvault8ck08;location=westeurope'. For help resolving this issue, please see https://go.microsoft.com/fwlink/?linkid=2125287" InnerError={"code":"ForbiddenByPolicy"}
        
          with data.azurerm_key_vault_certificates.test,
          on terraform_plugin_test.tf line 172, in data "azurerm_key_vault_certificates" "test":
         172: data "azurerm_key_vault_certificates" "test" {
        
--- FAIL: TestAccDataSourceKeyVaultCertificates_basic (769.17s)
FAIL

once thats fixed up this should be good to merge!

@StefanSchoof
Copy link
Contributor

@harshavmb I really like, to have this data source. Do you know, if you have time to look at this in the near future?

@harshavmb
Copy link
Contributor Author

@harshavmb I really like, to have this data source. Do you know, if you have time to look at this in the near future?

I tried my best to push for this PR. If tests are failing due to 403 error, I'm not going to do anything. Also, I can't test on my Azure environment as resource group creation is restricted.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

Hey @harshavmb, the test isn't passing because of a 403 but because we're managing certificate access policies in the template but you've declared a resource to manage certificate access policies so Terraform is stuck.

Error: A resource with the ID "/subscriptions/*******/resourceGroups/acctestRG-221219175714268125/providers/Microsoft.KeyVault/vaults/acctestkeyvault8ck08/objectId/3aa04c8c-5a75-4e5e-9117-1b7cf6f33e21" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_key_vault_access_policy" for more information.

I've detailed how to fix this in a comment below

key_vault_id = azurerm_key_vault.test.id
}

resource "azurerm_key_vault_access_policy" "certificates" {
Copy link
Member

Choose a reason for hiding this comment

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

There is an issue with this resource because we're managing certificate access policies inside of the template. If you remove resource "azurerm_key_vault_access_policy" "certificates" { and add "List" to the linked block, this test should pass

@harshavmb harshavmb requested review from mbfrahry and removed request for tombuildsstuff January 25, 2023 09:03
@harshavmb
Copy link
Contributor Author

Hi @mbfrahry ,

I've pushed changes as you asked. Please let me know if tests run fine now.

@harshavmb harshavmb requested review from katbyte and mbfrahry and removed request for mbfrahry and katbyte January 25, 2023 15:02
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.

LGTM aside from 1 mincor change

{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("names.#").HasValue("9"),
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
check.That(data.ResourceName).Key("names.#").HasValue("9"),
check.That(data.ResourceName).Key("names.#").HasValue("31"),

Copy link
Collaborator

Choose a reason for hiding this comment

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

i can't edit this PR, @harshavmb once this change is made this is good to go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @katbyte ,

I've pushed the change from my end.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for getting that test fixed

@mbfrahry mbfrahry changed the title Support new data source azurerm_key_vault_certificates New DataSource: azurerm_key_vault_certificates Jan 26, 2023
@mbfrahry mbfrahry added this to the v3.41.0 milestone Jan 26, 2023
@mbfrahry mbfrahry merged commit 34b2614 into hashicorp:main Jan 26, 2023
mbfrahry added a commit that referenced this pull request Jan 26, 2023
@github-actions
Copy link

This functionality has been released in v3.41.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@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 Feb 27, 2023
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.

Support for data.azurerm_key_vault_certificates
5 participants