diff --git a/ibm/service/schematics/data_source_ibm_schematics_workspace.go b/ibm/service/schematics/data_source_ibm_schematics_workspace.go index 69408e2c12..bdd9f28d1f 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_workspace.go +++ b/ibm/service/schematics/data_source_ibm_schematics_workspace.go @@ -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, @@ -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.", + }, }, }, }, @@ -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)) @@ -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)) @@ -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 @@ -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 { diff --git a/website/docs/d/schematics_workspace.html.markdown b/website/docs/d/schematics_workspace.html.markdown index dfadec7f5c..2f21acc368 100644 --- a/website/docs/d/schematics_workspace.html.markdown +++ b/website/docs/d/schematics_workspace.html.markdown @@ -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. @@ -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**: