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_key_vault_certificate return thumbprint as hex #1904

Merged
merged 3 commits into from
Sep 11, 2018

Conversation

steve-hawkins
Copy link
Contributor

@steve-hawkins steve-hawkins commented Sep 10, 2018

this is off the back of #1851

will return the thumbprint in hex for certificates, much like the x509ThumbprintHex returned in the Azure CLI command:-

$ az keyvault certificate show --id ...

Can be used like:-

...

resource "azurerm_key_vault_certificate" "test" {
  name      = "generated-cert"
  vault_uri = "${azurerm_key_vault.test.vault_uri}"

  certificate_policy {
    issuer_parameters {
      name = "Self"
    }

    key_properties {
      exportable = true
      key_size   = 2048
      key_type   = "RSA"
      reuse_key  = true
    }

    lifetime_action {
      action {
        action_type = "AutoRenew"
      }

      trigger {
        days_before_expiry = 30
      }
    }

    secret_properties {
      content_type = "application/x-pkcs12"
    }

    x509_certificate_properties {
      key_usage = [
        "cRLSign",
        "dataEncipherment",
        "digitalSignature",
        "keyAgreement",
        "keyCertSign",
        "keyEncipherment",
      ]

      subject            = "CN=hello-world"
      validity_in_months = 12
    }
  }
}

output "thumbprint" {
  value = "${azurerm_key_vault_certificate.test.thumbprint}"
}

(fixes #1851)

@ghost ghost added the size/S label Sep 10, 2018
@katbyte katbyte added this to the 1.15.0 milestone Sep 11, 2018
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.

Hi @steve-hawkins,

Thank you for the PR adding this property, I have left two comments inline with the blocker being the nil check.

Look forward to getting this merged for you once that is resolved 🙂

@@ -349,6 +357,16 @@ func resourceArmKeyVaultCertificateRead(d *schema.ResourceData, meta interface{}
if contents := cert.Cer; contents != nil {
d.Set("certificate_data", string(*contents))
}

x509Thumbprint, err := base64.RawURLEncoding.DecodeString(string(*cert.X509Thumbprint))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we get a nil check here?

if v := cert.X509Thumbprint; v != nil {
    x509Thumbprint, err := base64.RawURLEncoding.DecodeString(string(*v))


x509ThumbprintHex := hex.EncodeToString(x509Thumbprint)

d.Set("thumbprint", strings.ToUpper(x509ThumbprintHex))
Copy link
Collaborator

Choose a reason for hiding this comment

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

very minor, but we could combine these two lines as such: d.Set("thumbprint", strings.ToUpper(hex.EncodeToString(x509Thumbprint)))

@ghost ghost added the size/S label Sep 11, 2018
@steve-hawkins
Copy link
Contributor Author

Hi @katbyte thanks for looking into this one

All updated

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 @steve-hawkins

Thanks for this PR :)

I've taken a look through and this now LGTM - if we can add the documentation entry for this field we should be able to get this merged 👍

Thanks!

azurerm/resource_arm_key_vault_certificate.go Show resolved Hide resolved
if err != nil {
return err
}
d.Set("thumbprint", strings.ToUpper(hex.EncodeToString(x509Thumbprint)))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm assuming the thumbprint is case insensitive?

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 the cluster will accept lowercase, I was trying to replicate as close as possible what the Azure CLI returns

@ghost ghost added the size/S label Sep 11, 2018
@steve-hawkins
Copy link
Contributor Author

@tombuildsstuff documentation has now been updated, thanks for the heads up as this will make it easier for my next PR which should be coming shortly

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 for the quick updates @steve-hawkins, and noticing the missing docs @tombuildsstuff,

This LGTM now 💯

@ghost
Copy link

ghost commented Mar 6, 2019

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 6, 2019
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.

Thumbprint is not provided as an attribute for azurerm_key_vault_certificate
3 participants