Skip to content

Commit

Permalink
Remove CustomizeDiff logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Intskirveli committed Nov 10, 2019
1 parent e1962d1 commit 4ef1c85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 38 deletions.
20 changes: 14 additions & 6 deletions azurerm/common_hdinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,24 @@ func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema
edgeNodeConfig := edgeNodeRaw[0].(map[string]interface{})
applicationsClient := meta.(*ArmClient).HDInsight.ApplicationsClient

oldEdgeNodeCount, newEdgeNodeCount := d.GetChange("roles.0.edge_node.0.target_instance_count")
oldEdgeNodeInt := oldEdgeNodeCount.(int)
newEdgeNodeInt := newEdgeNodeCount.(int)

// Note: API currently doesn't support updating number of edge nodes
// if anything in the edge nodes changes, delete edge nodes then recreate them
err := deleteHDInsightEdgeNodes(ctx, applicationsClient, resourceGroup, name)
if err != nil {
return err
if oldEdgeNodeInt != 0 {
err := deleteHDInsightEdgeNodes(ctx, applicationsClient, resourceGroup, name)
if err != nil {
return err
}
}

err = createHDInsightEdgeNodes(ctx, applicationsClient, resourceGroup, name, edgeNodeConfig)
if err != nil {
return err
if newEdgeNodeInt != 0 {
err = createHDInsightEdgeNodes(ctx, applicationsClient, resourceGroup, name, edgeNodeConfig)
if err != nil {
return err
}
}

// we can't rely on the use of the Future here due to the node being successfully completed but now the cluster is applying those changes.
Expand Down
30 changes: 0 additions & 30 deletions azurerm/resource_arm_hdinsight_hadoop_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ import (
"context"
"fmt"
"log"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"

// "github.com/hashicorp/terraform/helper/resource"

"github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -60,33 +57,6 @@ func resourceArmHDInsightHadoopCluster() *schema.Resource {
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

CustomizeDiff: func(diff *schema.ResourceDiff, v interface{}) error {
// An edge node can be added but can't be update or removed without forcing a new resource to be created
oldEdgeNodeCount, newEdgeNodeCount := diff.GetChange("roles.0.edge_node.0.target_instance_count")
oldEdgeNodeInt := oldEdgeNodeCount.(int)
newEdgeNodeInt := newEdgeNodeCount.(int)

if oldEdgeNodeInt != newEdgeNodeInt {
diff.ForceNew("roles.0.edge_node.target_instance_count")
}

// DiffSuppressFunc comes after this check so we need to check if the strings aren't the same sans casing here.
oVMSize, newVMSize := diff.GetChange("roles.0.edge_node.0.vm_size")
if !strings.EqualFold(oVMSize.(string), newVMSize.(string)) {
diff.ForceNew("roles.0.edge_node.0.vm_size")
}

// ForceNew if attempting to update install scripts
oldInstallScriptCount, newInstallScriptCount := diff.GetChange("roles.0.edge_node.0.install_script_action.#")
oldInstallScriptInt := oldInstallScriptCount.(int)
newInstallScriptInt := newInstallScriptCount.(int)
if newInstallScriptInt == oldInstallScriptInt {
diff.ForceNew("roles.0.edge_node.0.install_script_action")
}

return nil
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_hdinsight_hadoop_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" {
}

func testAccAzureRMHDInsightHadoopCluster_edgeNodeBasic(rInt int, rString string, location string, numEdgeNodes int, instanceType string) string {
template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location, instanceType)
template := testAccAzureRMHDInsightHadoopCluster_template(rInt, rString, location)
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -763,7 +763,7 @@ resource "azurerm_hdinsight_hadoop_cluster" "test" {
}
}
}
`, template, rInt, rInt, rString)
`, template, rInt, numEdgeNodes, instanceType)
}

func testAccAzureRMHDInsightHadoopCluster_template(rInt int, rString string, location string) string {
Expand Down

0 comments on commit 4ef1c85

Please sign in to comment.