From 1aa84caca83164e95ef3318e970d1437ff75d592 Mon Sep 17 00:00:00 2001 From: Valyria McFarland <36799275+valyria257@users.noreply.github.com> Date: Mon, 24 Jun 2024 03:35:28 -0600 Subject: [PATCH] azurerm_nginx_certificate - add new read only fields to data source (#26160) --- .../nginx/nginx_certificate_data_source.go | 47 +++++++++++++++++-- .../nginx_certificate_data_source_test.go | 3 ++ .../docs/d/nginx_certificate.html.markdown | 10 ++++ 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/internal/services/nginx/nginx_certificate_data_source.go b/internal/services/nginx/nginx_certificate_data_source.go index dfd37f9e78d0..51fda319f34c 100644 --- a/internal/services/nginx/nginx_certificate_data_source.go +++ b/internal/services/nginx/nginx_certificate_data_source.go @@ -18,11 +18,16 @@ import ( ) type CertificateDataSourceModel struct { - Name string `tfschema:"name"` - NginxDeploymentId string `tfschema:"nginx_deployment_id"` - KeyVirtualPath string `tfschema:"key_virtual_path"` - CertificateVirtualPath string `tfschema:"certificate_virtual_path"` - KeyVaultSecretId string `tfschema:"key_vault_secret_id"` + Name string `tfschema:"name"` + NginxDeploymentId string `tfschema:"nginx_deployment_id"` + CertificateVirtualPath string `tfschema:"certificate_virtual_path"` + KeyVirtualPath string `tfschema:"key_virtual_path"` + KeyVaultSecretId string `tfschema:"key_vault_secret_id"` + SHA1Thumbprint string `tfschema:"sha1_thumbprint"` + KeyVaultSecretVersion string `tfschema:"key_vault_secret_version"` + KeyVaultSecretCreationDate string `tfschema:"key_vault_secret_creation_date"` + ErrorCode string `tfschema:"error_code"` + ErrorMessage string `tfschema:"error_message"` } type CertificateDataSource struct{} @@ -61,6 +66,31 @@ func (m CertificateDataSource) Attributes() map[string]*pluginsdk.Schema { Type: pluginsdk.TypeString, Computed: true, }, + + "sha1_thumbprint": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "key_vault_secret_version": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "key_vault_secret_creation_date": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "error_code": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "error_message": { + Type: pluginsdk.TypeString, + Computed: true, + }, } } @@ -109,6 +139,13 @@ func (m CertificateDataSource) Read() sdk.ResourceFunc { output.KeyVirtualPath = pointer.From(prop.KeyVirtualPath) output.KeyVaultSecretId = pointer.From(prop.KeyVaultSecretId) output.CertificateVirtualPath = pointer.From(prop.CertificateVirtualPath) + output.SHA1Thumbprint = pointer.From(prop.Sha1Thumbprint) + output.KeyVaultSecretVersion = pointer.From(prop.KeyVaultSecretVersion) + output.KeyVaultSecretCreationDate = pointer.From(prop.KeyVaultSecretCreated) + if prop.CertificateError != nil { + output.ErrorCode = pointer.From(prop.CertificateError.Code) + output.ErrorMessage = pointer.From(prop.CertificateError.Message) + } } metadata.SetID(id) diff --git a/internal/services/nginx/nginx_certificate_data_source_test.go b/internal/services/nginx/nginx_certificate_data_source_test.go index 9d95709eea30..ecebf6ea3a60 100644 --- a/internal/services/nginx/nginx_certificate_data_source_test.go +++ b/internal/services/nginx/nginx_certificate_data_source_test.go @@ -24,6 +24,9 @@ func TestAccNginxCertificateDataSource_basic(t *testing.T) { check.That(data.ResourceName).Key("certificate_virtual_path").Exists(), check.That(data.ResourceName).Key("key_vault_secret_id").Exists(), check.That(data.ResourceName).Key("key_virtual_path").Exists(), + check.That(data.ResourceName).Key("sha1_thumbprint").Exists(), + check.That(data.ResourceName).Key("key_vault_secret_version").Exists(), + check.That(data.ResourceName).Key("key_vault_secret_creation_date").Exists(), ), }, }) diff --git a/website/docs/d/nginx_certificate.html.markdown b/website/docs/d/nginx_certificate.html.markdown index 823da57c991e..153a789c0dd0 100644 --- a/website/docs/d/nginx_certificate.html.markdown +++ b/website/docs/d/nginx_certificate.html.markdown @@ -43,6 +43,16 @@ In addition to the Arguments listed above - the following Attributes are exporte * `key_vault_secret_id` - The ID of the Key Vault Secret for the certificate. +* `sha1_thumbprint` - The SHA-1 thumbprint of the certificate. + +* `key_vault_secret_version` - The version of the certificate. + +* `key_vault_secret_creation_date` - The date/time the certificate was created in Azure Key Vault. + +* `error_code` - The error code of the certificate error, if any. + +* `error_message` - The error message of the certificate error, if any. + ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: