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

Ignore autoaz changes #937

Merged
merged 4 commits into from
Nov 30, 2021
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
9 changes: 9 additions & 0 deletions clusters/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ func SparkConfDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool
return false
}

func AwsAttribsDiffSuppressFunc(k, old, new string, d *schema.ResourceData) bool {
if k == "aws_attributes.0.zone_id" && old != "" && new == "auto" {
log.Printf("[DEBUG] Suppressing diff for k=%#v old=%#v new=%#v", k, old, new)
nfx marked this conversation as resolved.
Show resolved Hide resolved
return true
}
return false
}

func resourceClusterSchema() map[string]*schema.Schema {
return common.StructToSchema(Cluster{}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
s["spark_conf"].DiffSuppressFunc = SparkConfDiffSuppressFunc
s["aws_attributes"].DiffSuppressFunc = AwsAttribsDiffSuppressFunc
// adds `library` configuration block
s["library"] = common.StructToSchema(libraries.ClusterLibraryList{},
func(ss map[string]*schema.Schema) map[string]*schema.Schema {
Expand Down
95 changes: 95 additions & 0 deletions clusters/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,101 @@ func TestResourceClusterUpdate_Error(t *testing.T) {
assert.Equal(t, "abc", d.Id())
}

func TestResourceClusterUpdate_AutoAz(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/clusters/get?cluster_id=abc",
ReuseRequest: true,
Response: ClusterInfo{
ClusterID: "abc",
NumWorkers: 100,
ClusterName: "Shared Autoscaling",
SparkVersion: "7.1-scala12",
NodeTypeID: "i3.xlarge",
AutoterminationMinutes: 15,
State: ClusterStateRunning,
AwsAttributes: &AwsAttributes{
Availability: "SPOT",
FirstOnDemand: 1,
ZoneID: "us-west-2a",
},
},
},
{
Method: "POST",
Resource: "/api/2.0/clusters/events",
ExpectedRequest: EventsRequest{
ClusterID: "abc",
Limit: 1,
Order: SortDescending,
EventTypes: []ClusterEventType{EvTypePinned, EvTypeUnpinned},
},
Response: EventsResponse{
Events: []ClusterEvent{},
TotalCount: 0,
},
},
{
Method: "POST",
Resource: "/api/2.0/clusters/start",
ExpectedRequest: ClusterID{
ClusterID: "abc",
},
},
{
Method: "GET",
Resource: "/api/2.0/libraries/cluster-status?cluster_id=abc",
Response: libraries.ClusterLibraryStatuses{
LibraryStatuses: []libraries.LibraryStatus{},
},
},
{
Method: "POST",
Resource: "/api/2.0/clusters/edit",
ExpectedRequest: Cluster{
AutoterminationMinutes: 15,
ClusterID: "abc",
NumWorkers: 100,
ClusterName: "Shared Autoscaling",
SparkVersion: "7.1-scala12",
NodeTypeID: "i3.xlarge",
AwsAttributes: &AwsAttributes{
Availability: "SPOT",
FirstOnDemand: 1,
nfx marked this conversation as resolved.
Show resolved Hide resolved
ZoneID: "auto",
},
},
},
{
Method: "GET",
Resource: "/api/2.0/libraries/cluster-status?cluster_id=abc",
Response: libraries.ClusterLibraryStatuses{
LibraryStatuses: []libraries.LibraryStatus{},
},
},
},
ID: "abc",
Update: true,
Resource: ResourceCluster(),
HCL: `
autotermination_minutes = 15
cluster_name = "Shared Autoscaling"
spark_version = "7.1-scala12"
node_type_id = "i3.xlarge"
num_workers = 100,
aws_attributes {
availability = "SPOT"
zone_id = "auto"
first_on_demand = 1
}
`,
}.Apply(t)
assert.NoError(t, err, err)
assert.Equal(t, "abc", d.Id(), "Id should be the same as in reading")
}

func TestResourceClusterDelete(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down
1 change: 1 addition & 0 deletions pipelines/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func adjustPipelineResourceSchema(m map[string]*schema.Schema) map[string]*schem
cluster, _ := m["cluster"].Elem.(*schema.Resource)
clustersSchema := cluster.Schema
clustersSchema["spark_conf"].DiffSuppressFunc = clusters.SparkConfDiffSuppressFunc
clustersSchema["aws_attributes"].DiffSuppressFunc = clusters.AwsAttribsDiffSuppressFunc

awsAttributes, _ := clustersSchema["aws_attributes"].Elem.(*schema.Resource)
awsAttributesSchema := awsAttributes.Schema
Expand Down