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 - add reverse_proxy_certificate_common_names #10367

Merged
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -180,9 +180,10 @@ func resourceServiceFabricCluster() *schema.Resource {
},

"reverse_proxy_certificate": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"reverse_proxy_certificate_common_names"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"thumbprint": {
Expand All @@ -201,6 +202,41 @@ func resourceServiceFabricCluster() *schema.Resource {
},
},

"reverse_proxy_certificate_common_names": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
ConflictsWith: []string{"reverse_proxy_certificate"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"common_names": {
Type: schema.TypeSet,
Required: true,
MinItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"certificate_common_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"certificate_issuer_thumbprint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},
"x509_store_name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"client_certificate_thumbprint": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -433,9 +469,6 @@ func resourceServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta inter
azureActiveDirectoryRaw := d.Get("azure_active_directory").([]interface{})
azureActiveDirectory := expandServiceFabricClusterAzureActiveDirectory(azureActiveDirectoryRaw)

reverseProxyCertificateRaw := d.Get("reverse_proxy_certificate").([]interface{})
reverseProxyCertificate := expandServiceFabricClusterReverseProxyCertificate(reverseProxyCertificateRaw)

diagnosticsRaw := d.Get("diagnostics_config").([]interface{})
diagnostics := expandServiceFabricClusterDiagnosticsConfig(diagnosticsRaw)

Expand All @@ -449,17 +482,17 @@ func resourceServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta inter
Location: utils.String(location),
Tags: tags.Expand(t),
ClusterProperties: &servicefabric.ClusterProperties{
AddOnFeatures: addOnFeatures,
AzureActiveDirectory: azureActiveDirectory,
CertificateCommonNames: expandServiceFabricClusterCertificateCommonNames(d),
ReverseProxyCertificate: reverseProxyCertificate,
DiagnosticsStorageAccountConfig: diagnostics,
FabricSettings: fabricSettings,
ManagementEndpoint: utils.String(managementEndpoint),
NodeTypes: nodeTypes,
ReliabilityLevel: servicefabric.ReliabilityLevel(reliabilityLevel),
UpgradeMode: servicefabric.UpgradeMode(upgradeMode),
VMImage: utils.String(vmImage),
AddOnFeatures: addOnFeatures,
AzureActiveDirectory: azureActiveDirectory,
CertificateCommonNames: expandServiceFabricClusterCertificateCommonNames(d),
ReverseProxyCertificateCommonNames: expandServiceFabricClusterReverseProxyCertificateCommonNames(d),
DiagnosticsStorageAccountConfig: diagnostics,
FabricSettings: fabricSettings,
ManagementEndpoint: utils.String(managementEndpoint),
NodeTypes: nodeTypes,
ReliabilityLevel: servicefabric.ReliabilityLevel(reliabilityLevel),
UpgradeMode: servicefabric.UpgradeMode(upgradeMode),
VMImage: utils.String(vmImage),
},
}

Expand All @@ -468,6 +501,11 @@ func resourceServiceFabricClusterCreateUpdate(d *schema.ResourceData, meta inter
cluster.ClusterProperties.Certificate = certificate
}

if reverseProxyCertificateRaw, ok := d.GetOk("reverse_proxy_certificate"); ok {
reverseProxyCertificate := expandServiceFabricClusterReverseProxyCertificate(reverseProxyCertificateRaw.([]interface{}))
cluster.ClusterProperties.ReverseProxyCertificate = reverseProxyCertificate
}

if clientCertificateThumbprintRaw, ok := d.GetOk("client_certificate_thumbprint"); ok {
clientCertificateThumbprints := expandServiceFabricClusterClientCertificateThumbprints(clientCertificateThumbprintRaw.([]interface{}))
cluster.ClusterProperties.ClientCertificateThumbprints = clientCertificateThumbprints
Expand Down Expand Up @@ -564,6 +602,11 @@ func resourceServiceFabricClusterRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error setting `reverse_proxy_certificate`: %+v", err)
}

reverseProxyCertificateCommonNames := flattenServiceFabricClusterCertificateCommonNames(props.ReverseProxyCertificateCommonNames)
if err := d.Set("reverse_proxy_certificate_common_names", reverseProxyCertificateCommonNames); err != nil {
return fmt.Errorf("Error setting `reverse_proxy_certificate_common_names`: %+v", err)
}

clientCertificateThumbprints := flattenServiceFabricClusterClientCertificateThumbprints(props.ClientCertificateThumbprints)
if err := d.Set("client_certificate_thumbprint", clientCertificateThumbprints); err != nil {
return fmt.Errorf("Error setting `client_certificate_thumbprint`: %+v", err)
Expand Down Expand Up @@ -756,6 +799,39 @@ func expandServiceFabricClusterCertificateCommonNames(d *schema.ResourceData) *s
return &output
}

func expandServiceFabricClusterReverseProxyCertificateCommonNames(d *schema.ResourceData) *servicefabric.ServerCertificateCommonNames {
i := d.Get("reverse_proxy_certificate_common_names").([]interface{})
if len(i) == 0 || i[0] == nil {
return nil
}
input := i[0].(map[string]interface{})

commonNamesRaw := input["common_names"].(*schema.Set).List()
commonNames := make([]servicefabric.ServerCertificateCommonName, 0)

for _, commonName := range commonNamesRaw {
commonNameDetails := commonName.(map[string]interface{})
certificateCommonName := commonNameDetails["certificate_common_name"].(string)
certificateIssuerThumbprint := commonNameDetails["certificate_issuer_thumbprint"].(string)

commonName := servicefabric.ServerCertificateCommonName{
CertificateCommonName: &certificateCommonName,
CertificateIssuerThumbprint: &certificateIssuerThumbprint,
}

commonNames = append(commonNames, commonName)
}

x509StoreName := input["x509_store_name"].(string)

output := servicefabric.ServerCertificateCommonNames{
CommonNames: &commonNames,
X509StoreName: servicefabric.X509StoreName1(x509StoreName),
}

return &output
}

func flattenServiceFabricClusterCertificateCommonNames(in *servicefabric.ServerCertificateCommonNames) []interface{} {
if in == nil {
return []interface{}{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,26 @@ func TestAccAzureRMServiceFabricCluster_certificateCommonNames(t *testing.T) {
})
}

func TestAccAzureRMServiceFabricCluster_reverseProxyCertificateCommonNames(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test")
r := ServiceFabricClusterResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.reverseProxyCertificateCommonNames(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("reverse_proxy_certificate_common_names.0.common_names.2962847220.certificate_common_name").HasValue("example"),
check.That(data.ResourceName).Key("reverse_proxy_certificate_common_names.0.x509_store_name").HasValue("My"),
check.That(data.ResourceName).Key("fabric_settings.0.name").HasValue("Security"),
check.That(data.ResourceName).Key("fabric_settings.0.parameters.ClusterProtectionLevel").HasValue("EncryptAndSign"),
check.That(data.ResourceName).Key("management_endpoint").HasValue("https://example:80"),
),
},
data.ImportStep(),
})
}

func TestAccAzureRMServiceFabricCluster_azureActiveDirectory(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_service_fabric_cluster", "test")
r := ServiceFabricClusterResource{}
Expand Down Expand Up @@ -1199,6 +1219,61 @@ resource "azurerm_service_fabric_cluster" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (r ServiceFabricClusterResource) reverseProxyCertificateCommonNames(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_service_fabric_cluster" "test" {
name = "acctest-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
reliability_level = "Bronze"
upgrade_mode = "Automatic"
vm_image = "Windows"
management_endpoint = "https://example:80"

certificate_common_names {
common_names {
certificate_common_name = "example"
}

x509_store_name = "My"
}

reverse_proxy_certificate_common_names {
common_names {
certificate_common_name = "example"
}

x509_store_name = "My"
}

fabric_settings {
name = "Security"

parameters = {
"ClusterProtectionLevel" = "EncryptAndSign"
}
}

node_type {
name = "first"
instance_count = 3
is_primary = true
client_endpoint_port = 2020
http_endpoint_port = 80
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func (r ServiceFabricClusterResource) azureActiveDirectory(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
16 changes: 13 additions & 3 deletions website/docs/r/service_fabric_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ The following arguments are supported:

* `certificate` - (Optional) A `certificate` block as defined below. Conflicts with `certificate_common_names`.

* `reverse_proxy_certificate` - (Optional) A `reverse_proxy_certificate` block as defined below.
* `reverse_proxy_certificate` - (Optional) A `reverse_proxy_certificate` block as defined below. Conflicts with `reverse_proxy_certificate_common_names`.

* `client_certificate_thumbprint` - (Optional) One or more `client_certificate_thumbprint` blocks as defined below.
* `reverse_proxy_certificate_common_names` - (Optional) A `reverse_proxy_certificate_common_names` block as defined below. Conflicts with `reverse_proxy_certificate`.

* `client_certificate_common_name` - (Optional) A `client_certificate_common_name` block as defined below.
* `client_certificate_thumbprint` - (Optional) One or more `client_certificate_thumbprint` blocks as defined below.

* `client_certificate_common_name` - (Optional) A `client_certificate_common_name` block as defined below.

-> **NOTE:** If Client Certificates are enabled then at a Certificate must be configured on the cluster.

Expand Down Expand Up @@ -136,6 +138,14 @@ A `reverse_proxy_certificate` block supports the following:

---

A `reverse_proxy_certificate_common_names` block supports the following:

* `common_names` - (Required) A `common_names` block as defined below.

* `x509_store_name` - (Required) The X509 Store where the Certificate Exists, such as `My`.

---

A `client_certificate_thumbprint` block supports the following:

* `thumbprint` - (Required) The Thumbprint associated with the Client Certificate.
Expand Down