Skip to content

Commit

Permalink
Fill in property set identifiers when updating. (#82)
Browse files Browse the repository at this point in the history
This is a bit of a cludge, the frontend keeps property set identifiers
the same when updating them, as it knows the indicies as they are being
written.

We can't really do that here, but we do have some chance. If the
property set name stays the same, then we can align the identifier by comparing
the old values. This should cover most use cases, but one can also use
an explicit id as well.
  • Loading branch information
HuwCampbell authored Oct 5, 2023
2 parents e36450d + 0ccef54 commit 699b1e7
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions client/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ func resourceClusterCreate(d *schema.ResourceData, m interface{}) error {
}

d.SetId(strconv.Itoa(e.ID))
resourceClusterRead(d, m)
return err
}

Expand All @@ -386,6 +387,7 @@ func resourceClusterUpdate(d *schema.ResourceData, m interface{}) error {
return err
}

resourceClusterRead(d, m)
return nil
}

Expand Down Expand Up @@ -594,25 +596,44 @@ func composeSparkConfig(d map[string]interface{}) SparkConfig {
}

func expandPropertySet(d *schema.ResourceData) []PropertySet {
drs := d.Get("property_set").(*schema.Set).List()
prev, new := d.GetChange("property_set")
prevX := prev.(*schema.Set).List()
drs := new.(*schema.Set).List()
res := make([]PropertySet, 0, len(drs))
for _, dr := range drs {
val, _ := dr.(map[string]interface{})
source := val["additional_spark_properties"].(map[string]interface{})
vals := dr.(map[string]interface{})
source := vals["additional_spark_properties"].(map[string]interface{})
additionalSparkProperties := make(map[string]string)

for k, v := range source {
additionalSparkProperties[k] = v.(string)
}

if val["name"].(string) != "" {
parsed := PropertySet{
Name: val["name"].(string),
AdditionalSparkProperties: additionalSparkProperties,
if vals["name"].(string) != "" {
var identifier *int
name := vals["name"].(string)
explicit, hasId := vals["id"].(int)

if hasId && explicit != 0 {
identifier = &explicit
} else {
// No identifier was explicitly specified.
// Try to find a property set from the last read
// with the same name, we'll use its ID.
for _, drX := range prevX {
oldVals, _ := drX.(map[string]interface{})
implicit, hasOld := oldVals["id"].(int)
oldName := oldVals["name"].(string)
if oldName == name && hasOld && implicit != 0 {
identifier = &implicit
}
}
}

if id, ok := val["id"].(int); ok && id != 0 {
parsed.ID = &id
parsed := PropertySet{
ID: identifier,
Name: name,
AdditionalSparkProperties: additionalSparkProperties,
}

res = append(res, parsed)
Expand Down

0 comments on commit 699b1e7

Please sign in to comment.