-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CDPCP-9784 - Terminate DH cluster deletion polling upon termination f…
…ailure
- Loading branch information
Showing
14 changed files
with
400 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright 2023 Cloudera. All Rights Reserved. | ||
// | ||
// This file is licensed under the Apache License Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
// OF ANY KIND, either express or implied. Refer to the License for the specific | ||
// permissions and limitations governing your use of the file. | ||
|
||
package datahub | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
var generalAttributes = map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"crn": schema.StringAttribute{ | ||
MarkdownDescription: "The CRN of the cluster.", | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"status": schema.StringAttribute{ | ||
MarkdownDescription: "The last known state of the cluster", | ||
Description: "The last known state of the cluster", | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
}, | ||
"name": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the cluster.", | ||
Required: true, | ||
}, | ||
"cluster_template": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the cluster template.", | ||
Required: true, | ||
}, | ||
"cluster_definition": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the cluster definition.", | ||
Required: true, | ||
}, | ||
"environment": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the environment where the cluster will belong to.", | ||
Required: true, | ||
}, | ||
"destroy_options": schema.SingleNestedAttribute{ | ||
Optional: true, | ||
Description: "Cluster deletion options.", | ||
MarkdownDescription: "Cluster deletion options.", | ||
Attributes: map[string]schema.Attribute{ | ||
"force_delete_cluster": schema.BoolAttribute{ | ||
MarkdownDescription: "An indicator that will take place once the cluster termination will be performed. " + | ||
"If it is true, that means if something would go sideways during termination, the operation will proceed, " + | ||
"however in such a case no notification would come thus it is advisable to check the cloud provider if " + | ||
"there are no leftover resources once the destroy is finished.", | ||
Description: "An indicator that will take place once the cluster termination will be performed. " + | ||
"If it is true, that means if something would go sideways during termination, the operation will proceed, " + | ||
"however in such a case no notification would come thus it is advisable to check the cloud provider if " + | ||
"there are no leftover resources once the destroy is finished.", | ||
Default: booldefault.StaticBool(false), | ||
Computed: true, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var instanceGroupSchemaAttributes = map[string]schema.Attribute{ | ||
"instance_group": schema.ListNestedAttribute{ | ||
Optional: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"node_count": schema.Int64Attribute{ | ||
MarkdownDescription: "The cluster node count. Has to be greater or equal than 0 and less than 100,000.", | ||
Required: true, | ||
}, | ||
"instance_group_name": schema.StringAttribute{ | ||
MarkdownDescription: "The name of the instance group.", | ||
Required: true, | ||
}, | ||
"instance_group_type": schema.StringAttribute{ | ||
MarkdownDescription: "The type of the instance group.", | ||
Required: true, | ||
}, | ||
"instance_type": schema.StringAttribute{ | ||
MarkdownDescription: "The cloud provider-side instance type.", | ||
Required: true, | ||
}, | ||
"root_volume_size": schema.Int64Attribute{ | ||
MarkdownDescription: "The size of the root volume in GB", | ||
Required: true, | ||
}, | ||
"recipes": schema.SetAttribute{ | ||
MarkdownDescription: "The set of recipe names that are going to be applied on the given instance group.", | ||
ElementType: types.StringType, | ||
Optional: true, | ||
}, | ||
"attached_volume_configuration": schema.ListNestedAttribute{ | ||
Required: true, | ||
MarkdownDescription: "Configuration regarding the attached volume to the specific instance group.", | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"volume_size": schema.Int64Attribute{ | ||
MarkdownDescription: "The size of the volume in GB.", | ||
Required: true, | ||
}, | ||
"volume_count": schema.Int64Attribute{ | ||
MarkdownDescription: "The number of volumes to be attached.", | ||
Required: true, | ||
}, | ||
"volume_type": schema.StringAttribute{ | ||
MarkdownDescription: "The - cloud provider - type of the volume.", | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"recovery_mode": schema.StringAttribute{ | ||
MarkdownDescription: "The type of the recovery mode.", | ||
Required: true, | ||
}, | ||
"volume_encryption": schema.SingleNestedAttribute{ | ||
MarkdownDescription: "The volume encryption related configuration.", | ||
Required: true, | ||
Attributes: map[string]schema.Attribute{ | ||
"encryption": schema.BoolAttribute{ | ||
Required: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 Cloudera. All Rights Reserved. | ||
// | ||
// This file is licensed under the Apache License Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
// OF ANY KIND, either express or implied. Refer to the License for the specific | ||
// permissions and limitations governing your use of the file. | ||
|
||
package datahub | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"testing" | ||
) | ||
|
||
func TestForceDeleteRequested(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
model *datahubResourceModel | ||
expectedResult bool | ||
}{ | ||
{ | ||
name: "when DestroyOptions nil", | ||
model: &datahubResourceModel{DestroyOptions: nil}, | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "when DestroyOptions not nil but ForceDeleteCluster is", | ||
model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolNull()}}, | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "when neither DestroyOptions or ForceDeleteCluster are nil but ForceDeleteCluster is false", | ||
model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(false)}}, | ||
expectedResult: false, | ||
}, | ||
{ | ||
name: "when ForceDeleteCluster is true", | ||
model: &datahubResourceModel{DestroyOptions: &DestroyOptions{ForceDeleteCluster: types.BoolValue(true)}}, | ||
expectedResult: true, | ||
}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
if test.model.forceDeleteRequested() != test.expectedResult { | ||
t.Errorf("Did not get the expected output! Expected: %t, got: %t", test.expectedResult, test.model.forceDeleteRequested()) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.