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

Fixed catalog service extensions and values metadata params of ws ds #4957

Merged
merged 1 commit into from
Nov 29, 2023
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
219 changes: 212 additions & 7 deletions ibm/service/schematics/data_source_ibm_schematics_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,31 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource {
Computed: true,
Description: "The version of the software template that you chose to install from the IBM Cloud catalog.",
},
},
},
},
"service_extensions": {
Type: schema.TypeList,
Computed: true,
Description: "List of service data",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the Service Data.",
},
"value": {
Type: schema.TypeString,
Computed: true,
Description: "Value of the Service Data.",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Type of the value string, int, bool.",
},
},
},
},
}}},
"created_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -406,6 +428,58 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource {
Computed: true,
Description: "The source of this meta-data.",
},
"metadata": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "A list of input variables that are associated with the workspace.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default_value": {
Type: schema.TypeString,
Computed: true,
Description: "Default value for the variable only if the override value is not specified.",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "The description of the meta data.",
},
"hidden": {
Type: schema.TypeBool,
Computed: true,
Description: "If **true**, the variable is not displayed on UI or Command line.",
},
"required": {
Type: schema.TypeBool,
Computed: true,
Description: "If the variable required?.",
},
"options": {
Type: schema.TypeList,
Computed: true,
Description: "The list of possible values for this variable. If type is **integer** or **date**, then the array of string is converted to array of integers or date during the runtime.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Type of the variable.",
},
"secure": {
Type: schema.TypeBool,
Computed: true,
Description: "If set to `true`, the value of your input variable is protected and not returned in your API response.",
},
},
},
},
"value": {
Type: schema.TypeString,
Computed: true,
Description: "The value of the variable. Applicable for the integer type.",
},
},
},
},
Expand Down Expand Up @@ -675,8 +749,9 @@ func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Res
if err = d.Set("template_values", templateData[0]["values"]); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error reading values: %s", err))
}
if err = d.Set("template_values_metadata", templateData[0]["values_metadata"]); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error reading values_metadata: %s", err))
err = d.Set("template_values_metadata", dataSourceWorkspaceResponseFlattenValuesMetadata(templateData[0]["values_metadata"]))
if err != nil {
fmt.Println(fmt.Errorf("[ERROR] Error reading template_values_metadata %s", err))
}
if err = d.Set("template_inputs", templateData[0]["variablestore"]); err != nil {
return diag.FromErr(fmt.Errorf("[ERROR] Error reading variablestore: %s", err))
Expand Down Expand Up @@ -804,10 +879,31 @@ func dataSourceWorkspaceResponseCatalogRefToMap(catalogRefItem schematicsv1.Cata
if catalogRefItem.OfferingVersion != nil {
catalogRefMap["offering_version"] = catalogRefItem.OfferingVersion
}

if catalogRefItem.ServiceExtensions != nil {
serviceExtensionsList := []map[string]interface{}{}
for _, serviceExtensionsItem := range catalogRefItem.ServiceExtensions {
serviceExtensionsList = append(serviceExtensionsList, dataSourceWorkspaceResponseCatalogRefServiceExtensionsToMap(serviceExtensionsItem))
}
catalogRefMap["service_extensions"] = serviceExtensionsList
}
return catalogRefMap
}

func dataSourceWorkspaceResponseCatalogRefServiceExtensionsToMap(serviceExtensionsItem schematicsv1.ServiceExtensions) (serviceExtensionMap map[string]interface{}) {
serviceExtensionMap = map[string]interface{}{}

if serviceExtensionsItem.Name != nil {
serviceExtensionMap["name"] = *serviceExtensionsItem.Name
}
if serviceExtensionsItem.Type != nil {
serviceExtensionMap["type"] = serviceExtensionsItem.Type
}
if serviceExtensionsItem.Value != nil {
serviceExtensionMap["value"] = *serviceExtensionsItem.Value
}
return serviceExtensionMap
}

func dataSourceWorkspaceResponseFlattenRuntimeData(result []schematicsv1.TemplateRunTimeDataResponse) (runtimeData []map[string]interface{}) {
for _, runtimeDataItem := range result {
runtimeData = append(runtimeData, dataSourceWorkspaceResponseRuntimeDataToMap(runtimeDataItem))
Expand Down Expand Up @@ -920,7 +1016,11 @@ func dataSourceWorkspaceResponseTemplateDataToMap(templateDataItem schematicsv1.
templateDataMap["values"] = templateDataItem.Values
}
if templateDataItem.ValuesMetadata != nil {
templateDataMap["values_metadata"] = templateDataItem.ValuesMetadata
valuesMetadataList := []interface{}{}
for _, valuesMetadataItem := range templateDataItem.ValuesMetadata {
valuesMetadataList = append(valuesMetadataList, valuesMetadataItem)
}
templateDataMap["values_metadata"] = valuesMetadataList
}
if templateDataItem.ValuesURL != nil {
templateDataMap["values_url"] = templateDataItem.ValuesURL
Expand All @@ -935,6 +1035,111 @@ func dataSourceWorkspaceResponseTemplateDataToMap(templateDataItem schematicsv1.

return templateDataMap
}

func dataSourceWorkspaceResponseFlattenValuesMetadata(result interface{}) (valuesMetadata []map[string]interface{}) {
if result != nil {
for _, res := range result.([]interface{}) {
valuesMetadataMap := dataSourceWorkspaceResponseValuesMetadataToMap(res.(map[string]interface{}))
valuesMetadata = append(valuesMetadata, valuesMetadataMap)
}
}
return valuesMetadata
}

func dataSourceWorkspaceResponseValuesMetadataToMap(valuesMetadataItem map[string]interface{}) map[string]interface{} {
valuesMetadataMap := map[string]interface{}{}

if valuesMetadataItem["name"] != nil {
valuesMetadataMap["name"] = valuesMetadataItem["name"].(string)
}
if valuesMetadataItem["type"] != nil {
valuesMetadataMap["type"] = valuesMetadataItem["type"].(string)
}

if valuesMetadataItem["aliases"] != nil {
valuesMetadataMap["aliases"] = valuesMetadataItem["aliases"]
}

if valuesMetadataItem["description"] != nil {
valuesMetadataMap["description"] = valuesMetadataItem["description"].(string)
}

if valuesMetadataItem["cloud_data_type"] != nil {
valuesMetadataMap["cloud_data_type"] = valuesMetadataItem["cloud_data_type"].(string)
}

if valuesMetadataItem["default"] != nil {
valuesMetadataMap["default"] = valuesMetadataItem["default"].(string)
}

if valuesMetadataItem["link_status"] != nil {
valuesMetadataMap["link_status"] = valuesMetadataItem["link_status"].(string)
}

if valuesMetadataItem["secure"] != nil {
valuesMetadataMap["secure"] = valuesMetadataItem["secure"]
}

if valuesMetadataItem["immutable"] != nil {
valuesMetadataMap["immutable"] = valuesMetadataItem["immutable"]
}

if valuesMetadataItem["hidden"] != nil {
valuesMetadataMap["hidden"] = valuesMetadataItem["hidden"]
}

if valuesMetadataItem["required"] != nil {
valuesMetadataMap["required"] = valuesMetadataItem["required"]
}

if valuesMetadataItem["options"] != nil {
valuesMetadataMap["options"] = valuesMetadataItem["options"]
}

if valuesMetadataItem["min_value"] != nil {
valuesMetadataMap["min_value"] = valuesMetadataItem["min_value"]
}

if valuesMetadataItem["max_value"] != nil {
valuesMetadataMap["max_value"] = valuesMetadataItem["max_value"]
}

if valuesMetadataItem["min_length"] != nil {
valuesMetadataMap["min_length"] = valuesMetadataItem["min_length"]
}

if valuesMetadataItem["max_length"] != nil {
valuesMetadataMap["max_length"] = valuesMetadataItem["max_length"]
}

if valuesMetadataItem["matches"] != nil {
valuesMetadataMap["matches"] = valuesMetadataItem["matches"].(string)
}

if valuesMetadataItem["position"] != nil {
valuesMetadataMap["position"] = valuesMetadataItem["position"]
}

if valuesMetadataItem["group_by"] != nil {
valuesMetadataMap["group_by"] = valuesMetadataItem["group_by"].(string)
}

if valuesMetadataItem["source"] != nil {
valuesMetadataMap["source"] = valuesMetadataItem["source"].(string)
}

if valuesMetadataItem["metadata"] != nil {
metadataList := []map[string]interface{}{}

valuesMetadataMap["metadata"] = append(metadataList, valuesMetadataItem["metadata"].(map[string]interface{}))

}
if valuesMetadataItem["value"] != nil {
valuesMetadataMap["value"] = valuesMetadataItem["value"].(string)
}

return valuesMetadataMap
}
func dataSourceIbmSchematicsWorkspaceVariableMetadataToMap(model *schematicsv1.VariableMetadata) map[string]interface{} {
modelMap := make(map[string]interface{})
if model.Type != nil {
Expand Down
18 changes: 17 additions & 1 deletion website/docs/d/schematics_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Nested scheme for **catalog_ref**:
* `item_url` - (String) The URL to the software template in the IBM Cloud catalog.
* `launch_url` - (String) The URL to the dashboard to access your software.
* `offering_version` - (String) The version of the software template that you chose to install from the IBM Cloud catalog.
* `service_extensions` - (List) List of service data
Nested scheme for **service_extensions**:
* `name` - (String) Name of the Service Data.
* `value` - (String) Value of the Service Data.
* `type` - (String) Type of the value string, int, bool.

* `created_at` - (String) The timestamp when the workspace was created.

Expand Down Expand Up @@ -123,8 +128,19 @@ Nested scheme for **env_values**:
* `required` - (Boolean) If the variable required?.
* `secure` - (Boolean) Is the variable secure or sensitive ?.
* `source` - (String) The source of this meta-data.
* `value` - (String) The value of the variable. Applicable for the integer type.
* `type` - (String) Type of the variable.
* Constraints: Allowable values are: `boolean`, `string`, `integer`, `date`, `array`, `list`, `map`, `complex`, `link`.
* Constraints: Allowable values are: `boolean`, `string`, `integer`, `date`, `array`, `list`, `map`, `complex`, `link`.
* `metadata` - (List) List of service data
Nested scheme for **metadata**:
* `default_value` - (String) Default value for the variable only if the override value is not specified.
* `description` - (String) The description of the meta data.
* `hidden` - (Boolean) If **true**, the variable is not displayed on UI or Command line.
* `options` - (List) The list of possible values for this variable. If type is **integer** or **date**, then the array of string is converted to array of integers or date during the runtime.
* `required` - (Boolean) If the variable required?.
* `secure` - (Boolean) Is the variable secure or sensitive ?.
* `type` - (String) Type of the variable.
* Constraints: Allowable values are: `boolean`, `string`, `integer`, `date`, `array`, `list`, `map`, `complex`, `link`.

* `template_inputs` - (List) Information about the input variables that your template uses.
Nested scheme for **variablestore**:
Expand Down
Loading