-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Add subject alternative names to azurerm_key_vault_certificate #2123
Merged
tombuildsstuff
merged 23 commits into
hashicorp:master
from
draggeta:add-subject-alternative-names-to-key-vault-certificates
Oct 30, 2018
Merged
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
524a35f
azurerm_keyvault_certificate: Add subject alternative names
draggeta 31ed307
azurerm_keyvault_certificate: update example as it is broken
draggeta c04c4a4
azurerm_keyvault_certificate: update documentation to add san capability
draggeta eb2533c
azurerm_keyvault_certificate: update test to deploy SANs
draggeta 9e4ee91
azurerm_key_vault_certificate: remove unnecessary commented code
draggeta bcd540c
Update san acceptance tests
draggeta b2c569d
Update acceptance tests
draggeta bca17b8
azurerm_key_vault_certificate: documentation, changed email to emails
draggeta dc2f6cb
merge master
draggeta 468d60d
azurerm_key_vault_certificate: fix unnecessary conversions, gofmt -s run
draggeta 029686f
azurerm_key_vault_certificate: fix errors
draggeta 6caa257
make fmt
katbyte 786fe4b
Update azurerm/resource_arm_key_vault_certificate.go
tombuildsstuff 853c3a2
Update azurerm/resource_arm_key_vault_certificate.go
tombuildsstuff 46dfdd2
Update azurerm/resource_arm_key_vault_certificate.go
tombuildsstuff dd26590
Update azurerm/resource_arm_key_vault_certificate.go
tombuildsstuff add8500
azurerm_key_vault_certificate: Add requested changes
draggeta 6d5c7d0
Merge branch 'master' of https://github.com/terraform-providers/terra…
draggeta 8cc14a8
make subject_alternative_names computed
draggeta 6fdb279
Flatten array always
draggeta 3111e78
fix panic regarding empty item
draggeta 8b3f5fe
remove if statements
draggeta de467bb
Fix the gofmt issue by running version 1.10 version of binary
draggeta 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,6 +220,39 @@ func resourceArmKeyVaultCertificate() *schema.Resource { | |
Required: true, | ||
ForceNew: true, | ||
}, | ||
"subject_alternative_names": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
MaxItems: 1, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"emails": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"dns_names": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"upns": { | ||
Type: schema.TypeList, | ||
Optional: true, | ||
ForceNew: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"validity_in_months": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
|
@@ -474,17 +507,47 @@ func expandKeyVaultCertificatePolicy(d *schema.ResourceData) keyvault.Certificat | |
keyUsage = append(keyUsage, keyvault.KeyUsageType(key.(string))) | ||
} | ||
|
||
subjectAlternativeNames := &keyvault.SubjectAlternativeNames{} | ||
if v, ok := cert["subject_alternative_names"]; ok { | ||
sans := v.([]interface{}) | ||
san := sans[0].(map[string]interface{}) | ||
|
||
emails := san["emails"].([]interface{}) | ||
if len(emails) > 0 { | ||
subjectAlternativeNames.Emails = expandKeyVaultSanProperty(emails) | ||
} | ||
|
||
dnsNames := san["dns_names"].([]interface{}) | ||
if len(dnsNames) > 0 { | ||
subjectAlternativeNames.DNSNames = expandKeyVaultSanProperty(dnsNames) | ||
} | ||
|
||
upns := san["upns"].([]interface{}) | ||
if len(upns) > 0 { | ||
subjectAlternativeNames.Upns = expandKeyVaultSanProperty(upns) | ||
} | ||
} | ||
|
||
policy.X509CertificateProperties = &keyvault.X509CertificateProperties{ | ||
ValidityInMonths: utils.Int32(int32(cert["validity_in_months"].(int))), | ||
Subject: utils.String(cert["subject"].(string)), | ||
KeyUsage: &keyUsage, | ||
Ekus: extendedKeyUsage, | ||
ValidityInMonths: utils.Int32(int32(cert["validity_in_months"].(int))), | ||
Subject: utils.String(cert["subject"].(string)), | ||
KeyUsage: &keyUsage, | ||
Ekus: extendedKeyUsage, | ||
SubjectAlternativeNames: subjectAlternativeNames, | ||
} | ||
} | ||
|
||
return policy | ||
} | ||
|
||
func expandKeyVaultSanProperty(input []interface{}) *[]string { | ||
properties := make([]string, len(input)) | ||
for i, v := range input { | ||
properties[i] = fmt.Sprint(v) | ||
} | ||
return &properties | ||
} | ||
|
||
func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy) []interface{} { | ||
policy := make(map[string]interface{}, 0) | ||
|
||
|
@@ -549,13 +612,31 @@ func flattenKeyVaultCertificatePolicy(input *keyvault.CertificatePolicy) []inter | |
for _, usage := range *props.KeyUsage { | ||
usages = append(usages, string(usage)) | ||
} | ||
|
||
sanOutput := make(map[string]interface{}, 0) | ||
draggeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if san := props.SubjectAlternativeNames; san != nil { | ||
if emails := san.Emails; emails != nil { | ||
draggeta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
sanOutput["emails"] = *san.Emails | ||
} | ||
|
||
if dnsNames := san.DNSNames; dnsNames != nil { | ||
sanOutput["dns_names"] = *san.DNSNames | ||
} | ||
|
||
if upns := san.Upns; upns != nil { | ||
sanOutput["upns"] = *san.Upns | ||
} | ||
draggeta marked this conversation as resolved.
Show resolved
Hide resolved
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. in retrospect (since they're returned from the API) - we'll want to always flatten these fields (even if there's no items returned) - as such we should be able to make this:
|
||
} | ||
|
||
certProps["key_usage"] = usages | ||
certProps["subject"] = *props.Subject | ||
certProps["validity_in_months"] = int(*props.ValidityInMonths) | ||
if props.Ekus != nil { | ||
certProps["extended_key_usage"] = props.Ekus | ||
} | ||
|
||
certProps["subject_alternative_names"] = []interface{}{sanOutput} | ||
|
||
policy["x509_certificate_properties"] = []interface{}{certProps} | ||
} | ||
|
||
|
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
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.
There is a
utils.ExpandStringArray
that does exactly this