-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_service_fabric_cluster - support for Client Certificate by common names (#4528) #6097
Merged
katbyte
merged 7 commits into
hashicorp:master
from
JSchenken:SupportClusterClientCertCommonName
Mar 25, 2020
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
931ac98
Add suport for specifying cluster Client Certificate by common name
JSchenken c8bf5a3
fix formatting in testAccAzureRMServiceFabricCluster_clientCertificat…
JSchenken 8a9b6e3
2nd format fix
JSchenken fad5d1b
formatting (fix bad copy/paste)
JSchenken 3be91d7
Trigger new build with master fixes
JSchenken 62a9c26
change property names
katbyte 6fc40d8
fix tests
katbyte 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,29 @@ func resourceArmServiceFabricCluster() *schema.Resource { | |||||
}, | ||||||
}, | ||||||
|
||||||
"client_certificate_common_name": { | ||||||
Type: schema.TypeList, | ||||||
Optional: true, | ||||||
Elem: &schema.Resource{ | ||||||
Schema: map[string]*schema.Schema{ | ||||||
"certificate_common_name": { | ||||||
Type: schema.TypeString, | ||||||
Required: true, | ||||||
ValidateFunc: validation.StringIsNotEmpty, | ||||||
}, | ||||||
"certificate_issuer_thumbprint": { | ||||||
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. I think we can drop the certificate
Suggested change
|
||||||
Type: schema.TypeString, | ||||||
Optional: true, | ||||||
ValidateFunc: validation.StringIsNotEmpty, | ||||||
}, | ||||||
"is_admin": { | ||||||
Type: schema.TypeBool, | ||||||
Required: true, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
}, | ||||||
|
||||||
"diagnostics_config": { | ||||||
Type: schema.TypeList, | ||||||
Optional: true, | ||||||
|
@@ -415,9 +438,6 @@ func resourceArmServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta in | |||||
reverseProxyCertificateRaw := d.Get("reverse_proxy_certificate").([]interface{}) | ||||||
reverseProxyCertificate := expandServiceFabricClusterReverseProxyCertificate(reverseProxyCertificateRaw) | ||||||
|
||||||
clientCertificateThumbprintRaw := d.Get("client_certificate_thumbprint").([]interface{}) | ||||||
clientCertificateThumbprints := expandServiceFabricClusterClientCertificateThumbprints(clientCertificateThumbprintRaw) | ||||||
|
||||||
diagnosticsRaw := d.Get("diagnostics_config").([]interface{}) | ||||||
diagnostics := expandServiceFabricClusterDiagnosticsConfig(diagnosticsRaw) | ||||||
|
||||||
|
@@ -435,7 +455,6 @@ func resourceArmServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta in | |||||
AzureActiveDirectory: azureActiveDirectory, | ||||||
CertificateCommonNames: expandServiceFabricClusterCertificateCommonNames(d), | ||||||
ReverseProxyCertificate: reverseProxyCertificate, | ||||||
ClientCertificateThumbprints: clientCertificateThumbprints, | ||||||
DiagnosticsStorageAccountConfig: diagnostics, | ||||||
FabricSettings: fabricSettings, | ||||||
ManagementEndpoint: utils.String(managementEndpoint), | ||||||
|
@@ -451,6 +470,16 @@ func resourceArmServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta in | |||||
cluster.ClusterProperties.Certificate = certificate | ||||||
} | ||||||
|
||||||
if clientCertificateThumbprintRaw, ok := d.GetOk("client_certificate_thumbprint"); ok { | ||||||
clientCertificateThumbprints := expandServiceFabricClusterClientCertificateThumbprints(clientCertificateThumbprintRaw.([]interface{})) | ||||||
cluster.ClusterProperties.ClientCertificateThumbprints = clientCertificateThumbprints | ||||||
} | ||||||
|
||||||
if clientCertificateCommonNamesRaw, ok := d.GetOk("client_certificate_common_name"); ok { | ||||||
clientCertificateCommonNames := expandServiceFabricClusterClientCertificateCommonNames(clientCertificateCommonNamesRaw.([]interface{})) | ||||||
cluster.ClusterProperties.ClientCertificateCommonNames = clientCertificateCommonNames | ||||||
} | ||||||
|
||||||
if clusterCodeVersion != "" { | ||||||
cluster.ClusterProperties.ClusterCodeVersion = utils.String(clusterCodeVersion) | ||||||
} | ||||||
|
@@ -542,6 +571,11 @@ func resourceArmServiceFabricClusterRead(d *schema.ResourceData, meta interface{ | |||||
return fmt.Errorf("Error setting `client_certificate_thumbprint`: %+v", err) | ||||||
} | ||||||
|
||||||
clientCertificateCommonNames := flattenServiceFabricClusterClientCertificateCommonNames(props.ClientCertificateCommonNames) | ||||||
if err := d.Set("client_certificate_common_name", clientCertificateCommonNames); err != nil { | ||||||
return fmt.Errorf("Error setting `client_certificate_common_name`: %+v", err) | ||||||
} | ||||||
|
||||||
diagnostics := flattenServiceFabricClusterDiagnosticsConfig(props.DiagnosticsStorageAccountConfig) | ||||||
if err := d.Set("diagnostics_config", diagnostics); err != nil { | ||||||
return fmt.Errorf("Error setting `diagnostics_config`: %+v", err) | ||||||
|
@@ -841,6 +875,54 @@ func flattenServiceFabricClusterClientCertificateThumbprints(input *[]servicefab | |||||
return results | ||||||
} | ||||||
|
||||||
func expandServiceFabricClusterClientCertificateCommonNames(input []interface{}) *[]servicefabric.ClientCertificateCommonName { | ||||||
results := make([]servicefabric.ClientCertificateCommonName, 0) | ||||||
|
||||||
for _, v := range input { | ||||||
val := v.(map[string]interface{}) | ||||||
|
||||||
certificate_common_name := val["certificate_common_name"].(string) | ||||||
certificate_issuer_thumbprint := val["certificate_issuer_thumbprint"].(string) | ||||||
isAdmin := val["is_admin"].(bool) | ||||||
|
||||||
result := servicefabric.ClientCertificateCommonName{ | ||||||
CertificateCommonName: utils.String(certificate_common_name), | ||||||
CertificateIssuerThumbprint: utils.String(certificate_issuer_thumbprint), | ||||||
IsAdmin: utils.Bool(isAdmin), | ||||||
} | ||||||
results = append(results, result) | ||||||
} | ||||||
|
||||||
return &results | ||||||
} | ||||||
|
||||||
func flattenServiceFabricClusterClientCertificateCommonNames(input *[]servicefabric.ClientCertificateCommonName) []interface{} { | ||||||
if input == nil { | ||||||
return []interface{}{} | ||||||
} | ||||||
|
||||||
results := make([]interface{}, 0) | ||||||
|
||||||
for _, v := range *input { | ||||||
result := make(map[string]interface{}) | ||||||
|
||||||
if certificate_common_name := v.CertificateCommonName; certificate_common_name != nil { | ||||||
result["certificate_common_name"] = *certificate_common_name | ||||||
} | ||||||
|
||||||
if certificate_issuer_thumbprint := v.CertificateIssuerThumbprint; certificate_issuer_thumbprint != nil { | ||||||
result["certificate_issuer_thumbprint"] = *certificate_issuer_thumbprint | ||||||
} | ||||||
|
||||||
if isAdmin := v.IsAdmin; isAdmin != nil { | ||||||
result["is_admin"] = *isAdmin | ||||||
} | ||||||
results = append(results, result) | ||||||
} | ||||||
|
||||||
return results | ||||||
} | ||||||
|
||||||
func expandServiceFabricClusterDiagnosticsConfig(input []interface{}) *servicefabric.DiagnosticsStorageAccountConfig { | ||||||
if len(input) == 0 { | ||||||
return nil | ||||||
|
Oops, something went wrong.
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.
i think we can make this