Skip to content

Commit

Permalink
azurerm_nginx_certificate - add new read only fields to data source (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
valyria257 authored Jun 24, 2024
1 parent 9844ea4 commit 1aa84ca
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
47 changes: 42 additions & 5 deletions internal/services/nginx/nginx_certificate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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,
},
}
}

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions internal/services/nginx/nginx_certificate_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
),
},
})
Expand Down
10 changes: 10 additions & 0 deletions website/docs/d/nginx_certificate.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1aa84ca

Please sign in to comment.