Skip to content

Updated Template with additional filters #266

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

Merged
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
1 change: 0 additions & 1 deletion docs/data-sources/compliance_report_resource_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ data "powerflex_compliance_report_resource_group" "example1" {
# firmware_repository_name = ["name1", "name2"]
# device_type = ["devicetype1", "devicetype2"]
# model = ["model1", "model2"]
# resource_ids = ["resourceid1", "resourceid2"]
# service_tag = ["servicetag1", "servicetag2"]
# compliant = true
# embedded_report = true
Expand Down
1 change: 0 additions & 1 deletion docs/data-sources/snapshot_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ data "powerflex_snapshot_policy" "sp" {
# snapshot_access_mode = ["read_write"]
# secure_snapshots = true
# time_of_last_auto_snapshot = [5]
# time_of_last_creation_time = [5]
# time_of_last_auto_snapshot_creation_failure = [5]
# last_auto_snapshot_creation_failure_reason = ["reason_for_failure"]
# last_auto_snapshot_failure_in_first_level = true
Expand Down
75 changes: 65 additions & 10 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,37 @@ limitations under the License.
data "powerflex_template" "example1" {
}

# Get template details using the ID of the template.
data "powerflex_template" "example2" {
template_ids = ["ID1", "ID2"]
}

# Get template details using the Name of the template.
data "powerflex_template" "example3" {
template_names = ["Name_1", "Name_2"]
// If multiple filter fields are provided then it will show the intersection of all of those fields.
// If there is no intersection between the filters then an empty datasource will be returned
// For more information about how we do our datasource filtering check out our guides: https://dell.github.io/terraform-docs/docs/storage/platforms/powerflex/product_guide/examples/
data "powerflex_template" "template" {
# filter{
# template_name = ["template_name"]
# id = ["template_id"]
# template_type = ["template_type"]
# template_version = ["template_version"]
# original_template_id = ["original_template_id"]
# template_locked = false
# in_configuration = false
# created_date = ["created_date"]
# created_by = ["created_by"]
# updated_date = ["updated_date"]
# last_deployed_date = ["last_deployed_date"]
# updated_by = ["updated_by"]
# manage_firmware = true
# use_default_catalog = true
# all_users_allowed = false
# category = ["category"]
# server_count = [3]
# storage_count = [0]
# cluster_count = [1]
# service_count = [0]
# switch_count = [2]
# vm_count = [0]
# sdnas_count = [3]
# brownfield_template_type = ["brownfield_template_type"]
# Draft = true
# }
}

output "template_result" {
Expand All @@ -74,14 +97,46 @@ After the successful execution of above said block, we can see the output by exe

### Optional

- `template_ids` (Set of String) List of template IDs
- `template_names` (Set of String) List of template names
- `filter` (Block, Optional) (see [below for nested schema](#nestedblock--filter))

### Read-Only

- `id` (String) Placeholder attribute.
- `template_details` (Attributes Set) Template details (see [below for nested schema](#nestedatt--template_details))

<a id="nestedblock--filter"></a>
### Nested Schema for `filter`

Optional:

- `all_users_allowed` (Boolean) Value for all_users_allowed
- `brownfield_template_type` (Set of String) List of brownfield_template_type
- `category` (Set of String) List of category
- `cluster_count` (Set of Number) List of cluster_count
- `created_by` (Set of String) List of created_by
- `created_date` (Set of String) List of created_date
- `draft` (Boolean) Value for draft
- `id` (Set of String) List of id
- `in_configuration` (Boolean) Value for in_configuration
- `last_deployed_date` (Set of String) List of last_deployed_date
- `manage_firmware` (Boolean) Value for manage_firmware
- `original_template_id` (Set of String) List of original_template_id
- `sdnas_count` (Set of Number) List of sdnas_count
- `server_count` (Set of Number) List of server_count
- `service_count` (Set of Number) List of service_count
- `storage_count` (Set of Number) List of storage_count
- `switch_count` (Set of Number) List of switch_count
- `template_description` (Set of String) List of template_description
- `template_locked` (Boolean) Value for template_locked
- `template_name` (Set of String) List of template_name
- `template_type` (Set of String) List of template_type
- `template_version` (Set of String) List of template_version
- `updated_by` (Set of String) List of updated_by
- `updated_date` (Set of String) List of updated_date
- `use_default_catalog` (Boolean) Value for use_default_catalog
- `vm_count` (Set of Number) List of vm_count


<a id="nestedatt--template_details"></a>
### Nested Schema for `template_details`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ data "powerflex_compliance_report_resource_group" "example1" {
# firmware_repository_name = ["name1", "name2"]
# device_type = ["devicetype1", "devicetype2"]
# model = ["model1", "model2"]
# resource_ids = ["resourceid1", "resourceid2"]
# service_tag = ["servicetag1", "servicetag2"]
# compliant = true
# embedded_report = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ data "powerflex_snapshot_policy" "sp" {
# snapshot_access_mode = ["read_write"]
# secure_snapshots = true
# time_of_last_auto_snapshot = [5]
# time_of_last_creation_time = [5]
# time_of_last_auto_snapshot_creation_failure = [5]
# last_auto_snapshot_creation_failure_reason = ["reason_for_failure"]
# last_auto_snapshot_failure_in_first_level = true
Expand Down
39 changes: 31 additions & 8 deletions examples/data-sources/powerflex_template/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,37 @@ limitations under the License.
data "powerflex_template" "example1" {
}

# Get template details using the ID of the template.
data "powerflex_template" "example2" {
template_ids = ["ID1", "ID2"]
}

# Get template details using the Name of the template.
data "powerflex_template" "example3" {
template_names = ["Name_1", "Name_2"]
// If multiple filter fields are provided then it will show the intersection of all of those fields.
// If there is no intersection between the filters then an empty datasource will be returned
// For more information about how we do our datasource filtering check out our guides: https://dell.github.io/terraform-docs/docs/storage/platforms/powerflex/product_guide/examples/
data "powerflex_template" "template" {
# filter{
# template_name = ["template_name"]
# id = ["template_id"]
# template_type = ["template_type"]
# template_version = ["template_version"]
# original_template_id = ["original_template_id"]
# template_locked = false
# in_configuration = false
# created_date = ["created_date"]
# created_by = ["created_by"]
# updated_date = ["updated_date"]
# last_deployed_date = ["last_deployed_date"]
# updated_by = ["updated_by"]
# manage_firmware = true
# use_default_catalog = true
# all_users_allowed = false
# category = ["category"]
# server_count = [3]
# storage_count = [0]
# cluster_count = [1]
# service_count = [0]
# switch_count = [2]
# vm_count = [0]
# sdnas_count = [3]
# brownfield_template_type = ["brownfield_template_type"]
# Draft = true
# }
}

output "template_result" {
Expand Down
33 changes: 31 additions & 2 deletions powerflex/models/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,41 @@ import (

// TemplateDataSourceModel maps the struct to Template data source schema
type TemplateDataSourceModel struct {
TemplateIDs types.Set `tfsdk:"template_ids"`
TemplateNames types.Set `tfsdk:"template_names"`
TemplateFilter *TemplateFilter `tfsdk:"filter"`
TemplateDetails []TemplateModel `tfsdk:"template_details"`
ID types.String `tfsdk:"id"`
}

// TemplateFilter is the filter of TemplateDetails
type TemplateFilter struct {
ID []types.String `tfsdk:"id"`
TemplateName []types.String `tfsdk:"template_name"`
TemplateDescription []types.String `tfsdk:"template_description"`
TemplateType []types.String `tfsdk:"template_type"`
TemplateVersion []types.String `tfsdk:"template_version"`
OriginalTemplateID []types.String `tfsdk:"original_template_id"`
TemplateLocked types.Bool `tfsdk:"template_locked"`
InConfiguration types.Bool `tfsdk:"in_configuration"`
CreatedDate []types.String `tfsdk:"created_date"`
CreatedBy []types.String `tfsdk:"created_by"`
UpdatedDate []types.String `tfsdk:"updated_date"`
LastDeployedDate []types.String `tfsdk:"last_deployed_date"`
UpdatedBy []types.String `tfsdk:"updated_by"`
ManageFirmware types.Bool `tfsdk:"manage_firmware"`
UseDefaultCatalog types.Bool `tfsdk:"use_default_catalog"`
AllUsersAllowed types.Bool `tfsdk:"all_users_allowed"`
Category []types.String `tfsdk:"category"`
ServerCount []types.Int64 `tfsdk:"server_count"`
StorageCount []types.Int64 `tfsdk:"storage_count"`
ClusterCount []types.Int64 `tfsdk:"cluster_count"`
ServiceCount []types.Int64 `tfsdk:"service_count"`
SwitchCount []types.Int64 `tfsdk:"switch_count"`
VMCount []types.Int64 `tfsdk:"vm_count"`
SdnasCount []types.Int64 `tfsdk:"sdnas_count"`
BrownfieldTemplateType []types.String `tfsdk:"brownfield_template_type"`
Draft types.Bool `tfsdk:"draft"`
}

// TemplateModel is the tfsdk model of TemplateDetails
type TemplateModel struct {
ID types.String `tfsdk:"id"`
Expand Down
21 changes: 0 additions & 21 deletions powerflex/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ type mdmDataPoints struct {
standByIP2 string
}

type templateDataPoints struct {
TemplateID string
TemplateName string
}

type complianceReportDataPoints struct {
ResourceGroupID string
IPAddress string
Expand Down Expand Up @@ -235,21 +230,6 @@ func getMdmDataPointsForTest() mdmDataPoints {
return MDMDataPoints
}

func getTemplateDataForTest() templateDataPoints {

var TemplateDataPoints templateDataPoints

envMap, err := loadEnvFile("powerflex.env")
if err != nil {
log.Fatal("Error loading .env file: ", err)
return TemplateDataPoints
}

TemplateDataPoints.TemplateID = setDefault(envMap["POWERFLEX_TEMPLATE_ID"], "tfacc_node_id")
TemplateDataPoints.TemplateName = setDefault(envMap["POWERFLEX_TEMPLATE_NAME"], "tfacc_node_pool_name")
return TemplateDataPoints
}

func getComplianceReportDataForTest() complianceReportDataPoints {
var ComplianceReportDataPoints complianceReportDataPoints
envMap, err := loadEnvFile("powerflex.env")
Expand Down Expand Up @@ -283,7 +263,6 @@ var username = setDefault(globalEnvMap["POWERFLEX_USERNAME"], "test")
var password = setDefault(globalEnvMap["POWERFLEX_PASSWORD"], "test")
var endpoint = setDefault(globalEnvMap["POWERFLEX_ENDPOINT"], "http://localhost:3002")
var insecure = setDefault(globalEnvMap["POWERFLEX_INSECURE"], "false")
var TemplateDataPoints = getTemplateDataForTest()
var SourceLocation = setDefault(globalEnvMap["POWERFLEX_SOURCE_LOCATION"], "tfacc_source_location")
var FirmwareRepoID1 = setDefault(globalEnvMap["POWERFLEX_FIRMWARE_REPO_ID1"], "tfacc_firmware_repo_id1")
var FirmwareRepoID2 = setDefault(globalEnvMap["POWERFLEX_FIRMWARE_REPO_ID2"], "tfacc_firmware_repo_id2")
Expand Down
55 changes: 20 additions & 35 deletions powerflex/provider/template_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"terraform-provider-powerflex/powerflex/models"

"github.com/dell/goscaleio"
scaleiotypes "github.com/dell/goscaleio/types/v1"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -86,46 +87,30 @@ func (d *templateDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}

templateDetails, err := d.gatewayClient.GetAllTemplates()
if err != nil {
resp.Diagnostics.AddError("Error in getting template details", err.Error())
return
}

// Fetch Template details if IDs are provided
if !state.TemplateIDs.IsNull() {
templateIDs := make([]string, 0)
diags.Append(state.TemplateIDs.ElementsAs(ctx, &templateIDs, true)...)

for _, templateID := range templateIDs {
templateDetails, err := d.gatewayClient.GetTemplateByID(templateID)
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error in getting template details using id %v", templateID), err.Error(),
)
return
}
templateModel = append(templateModel, helper.GetTemplateState(*templateDetails))
}
} else if !state.TemplateNames.IsNull() {
// Fetch Template details if IPs are provided
Names := make([]string, 0)
diags.Append(state.TemplateNames.ElementsAs(ctx, &Names, true)...)

for _, name := range Names {
templateDetails, err := d.gatewayClient.GetTemplateByFilters("name", name)
if err != nil {
resp.Diagnostics.AddError(
fmt.Sprintf("Error in getting template details using Name %v", name), err.Error(),
)
return
}
templateModel = append(templateModel, helper.GetTemplateState(templateDetails[0]))
}
} else {
templateDetails, err := d.gatewayClient.GetAllTemplates()
if state.TemplateFilter != nil {
filtered, err := helper.GetDataSourceByValue(*state.TemplateFilter, templateDetails)
if err != nil {
resp.Diagnostics.AddError("Error in getting template details", err.Error())
resp.Diagnostics.AddError(
fmt.Sprintf("Error in filtering Template: %v please validate the filter", state.TemplateDetails), err.Error(),
)
return
}

for _, template := range templateDetails {
templateModel = append(templateModel, helper.GetTemplateState(template))
filteredTemplate := []scaleiotypes.TemplateDetails{}
for _, val := range filtered {
filteredTemplate = append(filteredTemplate, val.(scaleiotypes.TemplateDetails))
}
templateDetails = filteredTemplate
}

for _, template := range templateDetails {
templateModel = append(templateModel, helper.GetTemplateState(template))
}

state.TemplateDetails = templateModel
Expand Down
38 changes: 8 additions & 30 deletions powerflex/provider/template_datasource_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ limitations under the License.
package provider

import (
"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"terraform-provider-powerflex/powerflex/helper"
"terraform-provider-powerflex/powerflex/models"

"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand All @@ -36,39 +35,18 @@ var TemplateDataSourceSchema schema.Schema = schema.Schema{
MarkdownDescription: "Placeholder attribute.",
Computed: true,
},
"template_ids": schema.SetAttribute{
Description: "List of template IDs",
MarkdownDescription: "List of template IDs",
Optional: true,
ElementType: types.StringType,
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(stringvalidator.LengthAtLeast(1)),
setvalidator.ConflictsWith(
path.MatchRoot("template_names"),
),
},
},
"template_names": schema.SetAttribute{
Description: "List of template names",
MarkdownDescription: "List of template names",
Optional: true,
ElementType: types.StringType,
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
setvalidator.ValueStringsAre(stringvalidator.LengthAtLeast(1)),
setvalidator.ConflictsWith(
path.MatchRoot("template_ids"),
),
},
},
"template_details": schema.SetNestedAttribute{
Description: "Template details",
MarkdownDescription: "Template details",
Computed: true,
NestedObject: schema.NestedAttributeObject{Attributes: TemplateDetailSchema()},
},
},
Blocks: map[string]schema.Block{
"filter": schema.SingleNestedBlock{
Attributes: helper.GenerateSchemaAttributes(helper.TypeToMap(models.TemplateFilter{})),
},
},
}

// TemplateDetailSchema is a function that returns the schema for TemplateDetails
Expand Down
Loading
Loading