From c646fce71dbc0a35c5086697546775c0bd4dd3ae Mon Sep 17 00:00:00 2001 From: steve-hawkins Date: Fri, 22 Feb 2019 12:13:58 +0000 Subject: [PATCH] add service fabric cluster placement properties and capacities --- .../resource_arm_service_fabric_cluster.go | 44 +++- ...esource_arm_service_fabric_cluster_test.go | 228 +++++++++++------- .../r/service_fabric_cluster.html.markdown | 4 + 3 files changed, 189 insertions(+), 87 deletions(-) diff --git a/azurerm/resource_arm_service_fabric_cluster.go b/azurerm/resource_arm_service_fabric_cluster.go index e2905a83fda4..778e3c6f8e8f 100644 --- a/azurerm/resource_arm_service_fabric_cluster.go +++ b/azurerm/resource_arm_service_fabric_cluster.go @@ -4,12 +4,11 @@ import ( "fmt" "log" - "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" - "github.com/Azure/azure-sdk-for-go/services/servicefabric/mgmt/2018-02-01/servicefabric" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -232,6 +231,14 @@ func resourceArmServiceFabricCluster() *schema.Resource { Required: true, ForceNew: true, }, + "placement_properties": { + Type: schema.TypeMap, + Optional: true, + }, + "capacities": { + Type: schema.TypeMap, + Optional: true, + }, "instance_count": { Type: schema.TypeInt, Required: true, @@ -918,6 +925,25 @@ func expandServiceFabricClusterNodeTypes(input []interface{}) *[]servicefabric.N HTTPGatewayEndpointPort: utils.Int32(int32(httpEndpointPort)), DurabilityLevel: servicefabric.DurabilityLevel(durabilityLevel), } + + if props, ok := node["placement_properties"]; ok { + placementProperties := make(map[string]*string) + for key, value := range props.(map[string]interface{}) { + placementProperties[key] = utils.String(value.(string)) + } + + result.PlacementProperties = placementProperties + } + + if caps, ok := node["capacities"]; ok { + capacities := make(map[string]*string) + for key, value := range caps.(map[string]interface{}) { + capacities[key] = utils.String(value.(string)) + } + + result.Capacities = capacities + } + if v := int32(node["reverse_proxy_endpoint_port"].(int)); v != 0 { result.ReverseProxyEndpointPort = utils.Int32(v) } @@ -968,6 +994,14 @@ func flattenServiceFabricClusterNodeTypes(input *[]servicefabric.NodeTypeDescrip output["name"] = *name } + if placementProperties := v.PlacementProperties; placementProperties != nil { + output["placement_properties"] = placementProperties + } + + if capacities := v.Capacities; capacities != nil { + output["capacities"] = capacities + } + if count := v.VMInstanceCount; count != nil { output["instance_count"] = int(*count) } @@ -1003,7 +1037,7 @@ func flattenServiceFabricClusterNodeTypes(input *[]servicefabric.NodeTypeDescrip } output["application_ports"] = applicationPorts - ephermeralPorts := make([]interface{}, 0) + ephemeralPorts := make([]interface{}, 0) if ports := v.EphemeralPorts; ports != nil { r := make(map[string]interface{}) if start := ports.StartPort; start != nil { @@ -1012,9 +1046,9 @@ func flattenServiceFabricClusterNodeTypes(input *[]servicefabric.NodeTypeDescrip if end := ports.EndPort; end != nil { r["end_port"] = int(*end) } - ephermeralPorts = append(ephermeralPorts, r) + ephemeralPorts = append(ephemeralPorts, r) } - output["ephemeral_ports"] = ephermeralPorts + output["ephemeral_ports"] = ephemeralPorts results = append(results, output) } diff --git a/azurerm/resource_arm_service_fabric_cluster_test.go b/azurerm/resource_arm_service_fabric_cluster_test.go index 7ed25d623330..53030df038d5 100644 --- a/azurerm/resource_arm_service_fabric_cluster_test.go +++ b/azurerm/resource_arm_service_fabric_cluster_test.go @@ -612,6 +612,35 @@ func TestAccAzureRMServiceFabricCluster_nodeTypesUpdate(t *testing.T) { }) } +func TestAccAzureRMServiceFabricCluster_nodeTypeProperties(t *testing.T) { + resourceName := "azurerm_service_fabric_cluster.test" + ri := tf.AccRandTimeInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMServiceFabricCluster_nodeTypeProperties(ri, testLocation()), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMServiceFabricClusterExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "node_type.0.placement_properties.%", "1"), + resource.TestCheckResourceAttr(resourceName, "node_type.0.placement_properties.HasSSD", "true"), + resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.%", "2"), + resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.ClientConnections", "20000"), + resource.TestCheckResourceAttr(resourceName, "node_type.0.capacities.MemoryGB", "8"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMServiceFabricCluster_tags(t *testing.T) { resourceName := "azurerm_service_fabric_cluster.test" ri := tf.AccRandTimeInt() @@ -708,8 +737,8 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + node_type { name = "first" instance_count = %d @@ -732,8 +761,8 @@ resource "azurerm_service_fabric_cluster" "import" { reliability_level = "${azurerm_service_fabric_cluster.test.reliability_level}" upgrade_mode = "${azurerm_service_fabric_cluster.test.upgrade_mode}" vm_image = "${azurerm_service_fabric_cluster.test.vm_image}" - management_endpoint = "${azurerm_service_fabric_cluster.test.management_endpoint}" - + management_endpoint = "${azurerm_service_fabric_cluster.test.management_endpoint}" + node_type { name = "first" instance_count = %d @@ -760,8 +789,8 @@ resource "azurerm_service_fabric_cluster" "test" { upgrade_mode = "Manual" cluster_code_version = "%[3]s" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + node_type { name = "first" instance_count = 3 @@ -788,8 +817,8 @@ resource "azurerm_service_fabric_cluster" "test" { upgrade_mode = "Automatic" vm_image = "Windows" management_endpoint = "http://example:80" - add_on_features = ["DnsService", "RepairManager"] - + add_on_features = ["DnsService", "RepairManager"] + node_type { name = "first" instance_count = 3 @@ -815,21 +844,21 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "https://example:80" - + management_endpoint = "https://example:80" + certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "EncryptAndSign" } - } - + } + node_type { name = "first" instance_count = 3 @@ -855,26 +884,26 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "https://example:80" - + management_endpoint = "https://example:80" + certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + reverse_proxy_certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "EncryptAndSign" } - } - + } + node_type { name = "first" instance_count = 3 @@ -901,26 +930,26 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "https://example:80" - + management_endpoint = "https://example:80" + certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + client_certificate_thumbprint { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" is_admin = true - } - + } + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "EncryptAndSign" } - } - + } + node_type { name = "first" instance_count = 3 @@ -946,31 +975,31 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "https://example:80" - + management_endpoint = "https://example:80" + certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + client_certificate_thumbprint { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" is_admin = true - } - + } + client_certificate_thumbprint { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" is_admin = false - } - + } + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "EncryptAndSign" } - } - + } + node_type { name = "first" instance_count = 3 @@ -1007,27 +1036,27 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "https://example:80" - + management_endpoint = "https://example:80" + certificate { thumbprint = "33:41:DB:6C:F2:AF:72:C6:11:DF:3B:E3:72:1A:65:3A:F1:D4:3E:CD:50:F5:84:F8:28:79:3D:BE:91:03:C3:EE" x509_store_name = "My" - } - + } + azure_active_directory { tenant_id = "${data.azurerm_client_config.current.tenant_id}" cluster_application_id = "${azurerm_azuread_application.test.application_id}" client_application_id = "00000000-0000-0000-0000-000000000000" - } - + } + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "EncryptAndSign" } - } - + } + node_type { name = "first" instance_count = 3 @@ -1061,16 +1090,16 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + diagnostics_config { storage_account_name = "${azurerm_storage_account.test.name}" protected_account_key_name = "StorageAccountKey1" blob_endpoint = "${azurerm_storage_account.test.primary_blob_endpoint}" queue_endpoint = "${azurerm_storage_account.test.primary_queue_endpoint}" table_endpoint = "${azurerm_storage_account.test.primary_table_endpoint}" - } - + } + node_type { name = "first" instance_count = 3 @@ -1096,16 +1125,16 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + fabric_settings { - name = "Security" - + name = "Security" + parameters { "ClusterProtectionLevel" = "None" } - } - + } + node_type { name = "first" instance_count = 3 @@ -1131,20 +1160,20 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + node_type { name = "first" instance_count = 3 is_primary = true client_endpoint_port = 2020 - http_endpoint_port = 80 - + http_endpoint_port = 80 + application_ports { start_port = 20000 end_port = 29999 - } - + } + ephemeral_ports { start_port = 30000 end_port = 39999 @@ -1168,16 +1197,16 @@ resource "azurerm_service_fabric_cluster" "test" { reliability_level = "Bronze" upgrade_mode = "Automatic" vm_image = "Windows" - management_endpoint = "http://example:80" - + management_endpoint = "http://example:80" + node_type { name = "first" instance_count = 3 is_primary = true client_endpoint_port = 2020 http_endpoint_port = 80 - } - + } + node_type { name = "second" instance_count = 4 @@ -1189,13 +1218,12 @@ resource "azurerm_service_fabric_cluster" "test" { `, rInt, location, rInt) } -func testAccAzureRMServiceFabricCluster_tags(rInt int, location string) string { +func testAccAzureRMServiceFabricCluster_nodeTypeProperties(rInt int, location string) string { return fmt.Sprintf(` 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}" @@ -1204,15 +1232,51 @@ resource "azurerm_service_fabric_cluster" "test" { upgrade_mode = "Automatic" vm_image = "Windows" management_endpoint = "http://example:80" + node_type { + name = "first" + placement_properties { + "HasSSD" = "true" + } + capacities { + "ClientConnections" = "20000" + "MemoryGB" = "8" + } + instance_count = 3 + is_primary = true + client_endpoint_port = 2020 + http_endpoint_port = 80 + } + tags { + "Hello" = "World" + } +} +`, rInt, location, rInt) +} +func testAccAzureRMServiceFabricCluster_tags(rInt int, location string) string { + return fmt.Sprintf(` +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 = "http://example:80" + node_type { name = "first" instance_count = 3 is_primary = true client_endpoint_port = 2020 http_endpoint_port = 80 - } - + } + tags { "Hello" = "World" } diff --git a/website/docs/r/service_fabric_cluster.html.markdown b/website/docs/r/service_fabric_cluster.html.markdown index d296562f7ac7..a60e63d94128 100644 --- a/website/docs/r/service_fabric_cluster.html.markdown +++ b/website/docs/r/service_fabric_cluster.html.markdown @@ -147,6 +147,10 @@ A `node_type` block supports the following: * `name` - (Required) The name of the Node Type. Changing this forces a new resource to be created. +* `placement_properties` - (Optional) The placement tags applied to nodes in the node type, which can be used to indicate where certain services (workload) should run. + +* `capacities` - (Optional) The capacity tags applied to the nodes in the node type, the cluster resource manager uses these tags to understand how much resource a node has. + * `instance_count` - (Required) The number of nodes for this Node Type. * `is_primary` - (Required) Is this the Primary Node Type? Changing this forces a new resource to be created.