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 specifying the cluster code version #1945

Merged
Merged
Show file tree
Hide file tree
Changes from 15 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
26 changes: 24 additions & 2 deletions azurerm/resource_arm_service_fabric_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func resourceArmServiceFabricCluster() *schema.Resource {
}, false),
},

"cluster_code_version": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.NoZeroValues,
},
steve-hawkins marked this conversation as resolved.
Show resolved Hide resolved

"management_endpoint": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -97,7 +103,7 @@ func resourceArmServiceFabricCluster() *schema.Resource {
"client_certificate_thumbprint": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
MaxItems: 2,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"thumbprint": {
Expand Down Expand Up @@ -275,6 +281,7 @@ func resourceArmServiceFabricClusterCreate(d *schema.ResourceData, meta interfac
reliabilityLevel := d.Get("reliability_level").(string)
managementEndpoint := d.Get("management_endpoint").(string)
upgradeMode := d.Get("upgrade_mode").(string)
clusterCodeVersion := d.Get("cluster_code_version").(string)
vmImage := d.Get("vm_image").(string)
tags := d.Get("tags").(map[string]interface{})

Expand Down Expand Up @@ -313,6 +320,10 @@ func resourceArmServiceFabricClusterCreate(d *schema.ResourceData, meta interfac
},
}

if clusterCodeVersion != "" {
cluster.ClusterProperties.ClusterCodeVersion = utils.String(clusterCodeVersion)
}

future, err := client.Create(ctx, resourceGroup, name, cluster)
if err != nil {
return fmt.Errorf("Error creating Service Fabric Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand Down Expand Up @@ -346,6 +357,7 @@ func resourceArmServiceFabricClusterUpdate(d *schema.ResourceData, meta interfac
name := d.Get("name").(string)
reliabilityLevel := d.Get("reliability_level").(string)
upgradeMode := d.Get("upgrade_mode").(string)
clusterCodeVersion := d.Get("cluster_code_version").(string)
tags := d.Get("tags").(map[string]interface{})

addOnFeaturesRaw := d.Get("add_on_features").(*schema.Set).List()
Expand Down Expand Up @@ -376,6 +388,10 @@ func resourceArmServiceFabricClusterUpdate(d *schema.ResourceData, meta interfac
Tags: expandTags(tags),
}

if clusterCodeVersion != "" {
parameters.ClusterPropertiesUpdateParameters.ClusterCodeVersion = utils.String(clusterCodeVersion)
}

future, err := client.Update(ctx, resourceGroup, name, parameters)
if err != nil {
return fmt.Errorf("Error updating Service Fabric Cluster %q (Resource Group %q): %+v", name, resourceGroup, err)
Expand Down Expand Up @@ -422,9 +438,15 @@ func resourceArmServiceFabricClusterRead(d *schema.ResourceData, meta interface{
d.Set("cluster_endpoint", props.ClusterEndpoint)
d.Set("management_endpoint", props.ManagementEndpoint)
d.Set("reliability_level", string(props.ReliabilityLevel))
d.Set("upgrade_mode", string(props.UpgradeMode))
d.Set("vm_image", props.VMImage)

upgradeMode := string(props.UpgradeMode)
d.Set("upgrade_mode", upgradeMode)

if upgradeMode == "Manual" {
d.Set("cluster_code_version", props.ClusterCodeVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we can remove the upgradeMode == "Manual" check here - and ensure this value is always set (since this information is always useful) - instead we can make this field Computed in the schema (above), which will allow this value to be optional & have whatever default value is specified by the Azure API


addOnFeatures := flattenServiceFabricClusterAddOnFeatures(props.AddOnFeatures)
if err := d.Set("add_on_features", schema.NewSet(schema.HashString, addOnFeatures)); err != nil {
return fmt.Errorf("Error setting `add_on_features`: %+v", err)
Expand Down
63 changes: 63 additions & 0 deletions azurerm/resource_arm_service_fabric_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,41 @@ func TestAccAzureRMServiceFabricCluster_basic(t *testing.T) {
})
}

func TestAccAzureRMServiceFabricCluster_manualClusterCodeVersion(t *testing.T) {
resourceName := "azurerm_service_fabric_cluster.test"
ri := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMServiceFabricClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(ri, location, "6.3.162.9494"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceFabricClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "upgrade_mode", "Manual"),
resource.TestCheckResourceAttr(resourceName, "cluster_code_version", "6.3.162.9494"),
),
},
{
Config: testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(ri, location, "6.3.176.9494"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMServiceFabricClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "upgrade_mode", "Manual"),
resource.TestCheckResourceAttr(resourceName, "cluster_code_version", "6.3.176.9494"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMServiceFabricCluster_addOnFeatures(t *testing.T) {
resourceName := "azurerm_service_fabric_cluster.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -432,6 +467,34 @@ resource "azurerm_service_fabric_cluster" "test" {
`, rInt, location, rInt, count)
}

func testAccAzureRMServiceFabricCluster_manualClusterCodeVersion(rInt int, location, clusterCodeVersion string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%[1]d"
location = "%[2]s"
}

resource "azurerm_service_fabric_cluster" "test" {
name = "acctest-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
reliability_level = "Bronze"
upgrade_mode = "Manual"
cluster_code_version = "%[3]s"
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
}
}
`, rInt, location, clusterCodeVersion)
}

func testAccAzureRMServiceFabricCluster_addOnFeatures(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand Down
17 changes: 10 additions & 7 deletions website/docs/r/service_fabric_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ resource "azurerm_resource_group" "test" {
}

resource "azurerm_service_fabric_cluster" "test" {
name = "example-servicefabric"
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"
name = "example-servicefabric"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
reliability_level = "Bronze"
upgrade_mode = "Manual"
cluster_code_version = "6.3.176.9494"
vm_image = "Windows"
management_endpoint = "https://example:80"

node_type {
name = "first"
Expand Down Expand Up @@ -60,6 +61,8 @@ The following arguments are supported:

---

* `cluster_code_version` - (Optional) Required if Upgrade Mode set to `Manual`, Specifies the Version of the Cluster Code of the cluster.

* `add_on_features` - (Optional) A List of one or more features which should be enabled, such as `DnsService`.

* `certificate` - (Optional) A `certificate` block as defined below.
Expand Down