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_service_fabric_cluster - support for Client Certificate by common names (#4528) #6097

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Copy link
Collaborator

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

Suggested change
"certificate_common_name": {
"common_name": {

Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"certificate_issuer_thumbprint": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can drop the certificate

Suggested change
"certificate_issuer_thumbprint": {
"issuer_thumbprint": {

Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"is_admin": {
Type: schema.TypeBool,
Required: true,
},
},
},
},

"diagnostics_config": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -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)

Expand All @@ -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),
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading