diff --git a/ibm/service/schematics/data_source_ibm_schematics_action.go b/ibm/service/schematics/data_source_ibm_schematics_action.go index ad97052fa1..3c00f993cb 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_action.go +++ b/ibm/service/schematics/data_source_ibm_schematics_action.go @@ -947,7 +947,9 @@ func DataSourceIBMSchematicsAction() *schema.Resource { func dataSourceIBMSchematicsActionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -962,139 +964,201 @@ func dataSourceIBMSchematicsActionRead(context context.Context, d *schema.Resour action, response, err := schematicsClient.GetActionWithContext(context, getActionOptions) if err != nil { - log.Printf("[DEBUG] GetActionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetActionWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead GetActionWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*getActionOptions.ActionID) if err = d.Set("name", action.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", action.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", action.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", action.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.UserState != nil { err = d.Set("user_state", dataSourceActionFlattenUserState(*action.UserState)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting user_state %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("source_readme_url", action.SourceReadmeURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_readme_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Source != nil { err = d.Set("source", dataSourceActionFlattenSource(*action.Source)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("source_type", action.SourceType); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_parameter", action.CommandParameter); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_parameter: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("inventory", action.Inventory); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting inventory: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Credentials != nil { err = d.Set("credentials", dataSourceActionFlattenCredentials(action.Credentials)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting credentials %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.Bastion != nil { err = d.Set("bastion", dataSourceActionFlattenBastion(*action.Bastion)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.BastionCredential != nil { err = d.Set("bastion_credential", dataSourceActionFlattenBastionCredential(*action.BastionCredential)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion_credential %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("targets_ini", action.TargetsIni); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting targets_ini: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Inputs != nil { err = d.Set("action_inputs", dataSourceActionFlattenInputs(action.Inputs)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting action_inputs %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.Outputs != nil { err = d.Set("action_outputs", dataSourceActionFlattenOutputs(action.Outputs)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting action_outputs %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.Settings != nil { err = d.Set("settings", dataSourceActionFlattenSettings(action.Settings)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting settings %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("id", action.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("crn", action.Crn); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("account", action.Account); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting account: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_created_at", flex.DateTimeToString(action.SourceCreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_created_by", action.SourceCreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_updated_at", flex.DateTimeToString(action.SourceUpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_updated_by", action.SourceUpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(action.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", action.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(action.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", action.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.State != nil { err = d.Set("state", dataSourceActionFlattenState(*action.State)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting state %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.SysLock != nil { err = d.Set("sys_lock", dataSourceActionFlattenSysLock(*action.SysLock)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting sys_lock %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/data_source_ibm_schematics_agent.go b/ibm/service/schematics/data_source_ibm_schematics_agent.go index f11932e05f..55389d7496 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_agent.go +++ b/ibm/service/schematics/data_source_ibm_schematics_agent.go @@ -537,7 +537,9 @@ func DataSourceIbmSchematicsAgent() *schema.Resource { func dataSourceIbmSchematicsAgentRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -548,50 +550,70 @@ func dataSourceIbmSchematicsAgentRead(context context.Context, d *schema.Resourc agentData, response, err := schematicsClient.GetAgentDataWithContext(context, getAgentDataOptions) if err != nil { - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s", *getAgentDataOptions.AgentID)) if err = d.Set("name", agentData.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", agentData.Description); err != nil { - return diag.FromErr(fmt.Errorf("Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", agentData.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("schematics_location", agentData.SchematicsLocation); err != nil { - return diag.FromErr(fmt.Errorf("Error setting schematics_location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_location", agentData.AgentLocation); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.Tags != nil { if err = d.Set("tags", agentData.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } agentInfrastructure := []map[string]interface{}{} if agentData.AgentInfrastructure != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentInfrastructureToMap(agentData.AgentInfrastructure) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInfrastructure = append(agentInfrastructure, modelMap) } if err = d.Set("agent_infrastructure", agentInfrastructure); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_infrastructure %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentMetadata := []map[string]interface{}{} @@ -599,13 +621,17 @@ func dataSourceIbmSchematicsAgentRead(context context.Context, d *schema.Resourc for _, modelItem := range agentData.AgentMetadata { modelMap, err := dataSourceIbmSchematicsAgentAgentMetadataInfoToMap(&modelItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentMetadata = append(agentMetadata, modelMap) } } if err = d.Set("agent_metadata", agentMetadata); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_metadata %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInputs := []map[string]interface{}{} @@ -613,109 +639,149 @@ func dataSourceIbmSchematicsAgentRead(context context.Context, d *schema.Resourc for _, modelItem := range agentData.AgentInputs { modelMap, err := dataSourceIbmSchematicsAgentVariableDataToMap(&modelItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInputs = append(agentInputs, modelMap) } } if err = d.Set("agent_inputs", agentInputs); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_inputs %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } userState := []map[string]interface{}{} if agentData.UserState != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentUserStateToMap(agentData.UserState) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } userState = append(userState, modelMap) } if err = d.Set("user_state", userState); err != nil { - return diag.FromErr(fmt.Errorf("Error setting user_state %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_crn", agentData.AgentCrn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("id", agentData.ID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(agentData.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("creation_by", agentData.CreationBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting creation_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(agentData.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } systemState := []map[string]interface{}{} if agentData.SystemState != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentSystemStatusToMap(agentData.SystemState) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } systemState = append(systemState, modelMap) } if err = d.Set("system_state", systemState); err != nil { - return diag.FromErr(fmt.Errorf("Error setting system_state %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentKpi := []map[string]interface{}{} if agentData.AgentKpi != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentKPIDataToMap(agentData.AgentKpi) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentKpi = append(agentKpi, modelMap) } if err = d.Set("agent_kpi", agentKpi); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_kpi %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentPrsJob := []map[string]interface{}{} if agentData.RecentPrsJob != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentDataRecentPrsJobToMap(agentData.RecentPrsJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentPrsJob = append(recentPrsJob, modelMap) } if err = d.Set("recent_prs_job", recentPrsJob); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_prs_job %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentDeployJob := []map[string]interface{}{} if agentData.RecentDeployJob != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentDataRecentDeployJobToMap(agentData.RecentDeployJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentDeployJob = append(recentDeployJob, modelMap) } if err = d.Set("recent_deploy_job", recentDeployJob); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_deploy_job %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentHealthJob := []map[string]interface{}{} if agentData.RecentHealthJob != nil { modelMap, err := dataSourceIbmSchematicsAgentAgentDataRecentHealthJobToMap(agentData.RecentHealthJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } recentHealthJob = append(recentHealthJob, modelMap) } if err = d.Set("recent_health_job", recentHealthJob); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_health_job %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_agent_deploy.go b/ibm/service/schematics/data_source_ibm_schematics_agent_deploy.go index ebc1cafde8..dbbeeee4f1 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_agent_deploy.go +++ b/ibm/service/schematics/data_source_ibm_schematics_agent_deploy.go @@ -75,7 +75,9 @@ func dataSourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.R schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -89,41 +91,61 @@ func dataSourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.R d.SetId(DataSourceIBMSchematicsAgentID(d)) return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(DataSourceIBMSchematicsAgentID(d)) if agentData.RecentDeployJob != nil { if err = d.Set("agent_id", getAgentDataOptions.AgentID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentDeployJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } else if agentData.RecentDeployJob.JobID != nil { d.SetId(fmt.Sprintf("%s", *agentData.RecentDeployJob.JobID)) } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentDeployJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentDeployJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("is_redeployed", agentData.RecentDeployJob.IsRedeployed); err != nil { - return diag.FromErr(fmt.Errorf("Error setting is_redeployed: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentDeployJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentDeployJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentDeployJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/data_source_ibm_schematics_agent_health.go b/ibm/service/schematics/data_source_ibm_schematics_agent_health.go index 637d819706..e4fb84281e 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_agent_health.go +++ b/ibm/service/schematics/data_source_ibm_schematics_agent_health.go @@ -70,7 +70,9 @@ func dataSourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.R schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -84,38 +86,56 @@ func dataSourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.R d.SetId(DataSourceIBMSchematicsAgentID(d)) return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(DataSourceIBMSchematicsAgentID(d)) if agentData.RecentHealthJob != nil { if err = d.Set("agent_id", getAgentDataOptions.AgentID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentHealthJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } else if agentData.RecentHealthJob.JobID != nil { d.SetId(fmt.Sprintf("%s", *agentData.RecentHealthJob.JobID)) } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentHealthJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentHealthJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentHealthJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentHealthJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentHealthJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/data_source_ibm_schematics_agent_prs.go b/ibm/service/schematics/data_source_ibm_schematics_agent_prs.go index d54b38d38c..2eedf7ba83 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_agent_prs.go +++ b/ibm/service/schematics/data_source_ibm_schematics_agent_prs.go @@ -70,7 +70,9 @@ func DataSourceIbmSchematicsAgentPrs() *schema.Resource { func dataSourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -84,38 +86,56 @@ func dataSourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.Reso d.SetId(DataSourceIBMSchematicsAgentID(d)) return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(DataSourceIBMSchematicsAgentID(d)) if agentData.RecentPrsJob != nil { if err = d.Set("agent_id", getAgentDataOptions.AgentID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentPrsJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } else if agentData.RecentPrsJob.JobID != nil { d.SetId(fmt.Sprintf("%s", *agentData.RecentPrsJob.JobID)) } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentPrsJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentPrsJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentPrsJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentPrsJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentPrsJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/data_source_ibm_schematics_agents.go b/ibm/service/schematics/data_source_ibm_schematics_agents.go index 2b37171461..4dcc7d234f 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_agents.go +++ b/ibm/service/schematics/data_source_ibm_schematics_agents.go @@ -188,15 +188,19 @@ func DataSourceIbmSchematicsAgents() *schema.Resource { func dataSourceIbmSchematicsAgentsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } listAgentOptions := &schematicsv1.ListAgentOptions{} agentList, response, err := schematicsClient.ListAgentWithContext(context, listAgentOptions) if err != nil { - log.Printf("[DEBUG] ListAgentWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListAgentWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead ListAgentWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } // Use the provided filter argument and construct a new list with only the requested resource(s) @@ -219,8 +223,10 @@ func dataSourceIbmSchematicsAgentsRead(context context.Context, d *schema.Resour if suppliedFilter { if len(agentList.Agents) == 0 { - log.Printf("[DEBUG] no Agents found with name %s\n", name) - // return diag.FromErr(fmt.Errorf("no Agents found with name %s", name)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed with error: %s", err), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(name) } else { @@ -228,15 +234,21 @@ func dataSourceIbmSchematicsAgentsRead(context context.Context, d *schema.Resour } if err = d.Set("total_count", flex.IntValue(agentList.TotalCount)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting total_count: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed with error: %s", err), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("limit", flex.IntValue(agentList.Limit)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting limit: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed with error: %s", err), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("offset", flex.IntValue(agentList.Offset)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting offset: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed with error: %s", err), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agents := []map[string]interface{}{} @@ -244,13 +256,17 @@ func dataSourceIbmSchematicsAgentsRead(context context.Context, d *schema.Resour for _, modelItem := range agentList.Agents { modelMap, err := dataSourceIbmSchematicsAgentsAgentToMap(&modelItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed: %s", err.Error()), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agents = append(agents, modelMap) } } if err = d.Set("agents", agents); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agents %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsAgentsRead failed with error: %s", err), "ibm_schematics_agents", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_inventory.go b/ibm/service/schematics/data_source_ibm_schematics_inventory.go index bbd7746e25..7cacc49ada 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_inventory.go +++ b/ibm/service/schematics/data_source_ibm_schematics_inventory.go @@ -92,7 +92,9 @@ func DataSourceIBMSchematicsInventory() *schema.Resource { func dataSourceIBMSchematicsInventoryRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -108,40 +110,62 @@ func dataSourceIBMSchematicsInventoryRead(context context.Context, d *schema.Res inventoryResourceRecord, response, err := schematicsClient.GetInventoryWithContext(context, getInventoryOptions) if err != nil { - log.Printf("[DEBUG] GetInventoryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetInventoryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead GetInventoryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*getInventoryOptions.InventoryID) if err = d.Set("name", inventoryResourceRecord.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("id", inventoryResourceRecord.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", inventoryResourceRecord.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", inventoryResourceRecord.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", inventoryResourceRecord.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(inventoryResourceRecord.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", inventoryResourceRecord.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(inventoryResourceRecord.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", inventoryResourceRecord.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("inventories_ini", inventoryResourceRecord.InventoriesIni); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting inventories_ini: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_job.go b/ibm/service/schematics/data_source_ibm_schematics_job.go index 64f35170d5..88b0211e60 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_job.go +++ b/ibm/service/schematics/data_source_ibm_schematics_job.go @@ -2816,7 +2816,9 @@ func DataSourceIBMSchematicsJob() *schema.Resource { func dataSourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -2831,106 +2833,156 @@ func dataSourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceD job, response, err := schematicsClient.GetJobWithContext(context, getJobOptions) if err != nil { - log.Printf("[DEBUG] GetJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead GetJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*getJobOptions.JobID) if err = d.Set("command_object", job.CommandObject); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_object: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_object_id", job.CommandObjectID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_object_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_name", job.CommandName); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_parameter", job.CommandParameter); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_parameter: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if job.Inputs != nil { err = d.Set("job_inputs", dataSourceJobFlattenInputs(job.Inputs)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting job_inputs %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Settings != nil { err = d.Set("job_env_settings", dataSourceJobFlattenSettings(job.Settings)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting job_env_settings %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("id", job.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", job.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", job.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", job.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", job.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("submitted_at", flex.DateTimeToString(job.SubmittedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting submitted_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("submitted_by", job.SubmittedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting submitted_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("start_at", flex.DateTimeToString(job.StartAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting start_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("end_at", flex.DateTimeToString(job.EndAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting end_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("duration", job.Duration); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting duration: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if job.Status != nil { err = d.Set("status", dataSourceJobFlattenStatus(*job.Status)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting status %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Data != nil { err = d.Set("data", dataSourceJobFlattenData(*job.Data)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting data %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Bastion != nil { err = d.Set("bastion", dataSourceJobFlattenBastion(*job.Bastion)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.LogSummary != nil { err = d.Set("log_summary", dataSourceJobFlattenLogSummary(*job.LogSummary)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting log_summary %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("log_store_url", job.LogStoreURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting log_store_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("state_store_url", job.StateStoreURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting state_store_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("results_url", job.ResultsURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting results_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(job.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_output.go b/ibm/service/schematics/data_source_ibm_schematics_output.go index 0e46b0c9c9..3696ff165f 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_output.go +++ b/ibm/service/schematics/data_source_ibm_schematics_output.go @@ -76,7 +76,8 @@ func dataSourceIBMSchematicsOutputRead(d *schema.ResourceData, meta interface{}) outputValuesList, response, err := schematicsClient.GetWorkspaceOutputs(getWorkspaceOutputsOptions) if err != nil { - log.Printf("[DEBUG] GetWorkspaceOutputs failed %s\n%s", err, response) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsOutputRead GetWorkspaceOutputs failed with error: %s and response:\n%s", err, response), "ibm_schematics_output", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) return err } diff --git a/ibm/service/schematics/data_source_ibm_schematics_policies.go b/ibm/service/schematics/data_source_ibm_schematics_policies.go index 7cfe407d0e..d44c0f59b9 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_policies.go +++ b/ibm/service/schematics/data_source_ibm_schematics_policies.go @@ -145,15 +145,19 @@ func DataSourceIbmSchematicsPolicies() *schema.Resource { func dataSourceIbmSchematicsPoliciesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } listPolicyOptions := &schematicsv1.ListPolicyOptions{} policyList, response, err := schematicsClient.ListPolicyWithContext(context, listPolicyOptions) if err != nil { - log.Printf("[DEBUG] ListPolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ListPolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead ListPolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } // Use the provided filter argument and construct a new list with only the requested resource(s) @@ -178,8 +182,10 @@ func dataSourceIbmSchematicsPoliciesRead(context context.Context, d *schema.Reso if suppliedFilter { if len(policyList.Policies) == 0 { - log.Printf("[DEBUG] no Policies found with policyKind %s\n", policyKind) - // return diag.FromErr(fmt.Errorf("no Policies found with policyKind %s", policyKind)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed with error: %s", err), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(policyKind) } else { @@ -187,15 +193,21 @@ func dataSourceIbmSchematicsPoliciesRead(context context.Context, d *schema.Reso } if err = d.Set("total_count", flex.IntValue(policyList.TotalCount)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting total_count: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed with error: %s", err), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("limit", flex.IntValue(policyList.Limit)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting limit: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed with error: %s", err), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("offset", flex.IntValue(policyList.Offset)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting offset: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed with error: %s", err), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } policies := []map[string]interface{}{} @@ -203,13 +215,17 @@ func dataSourceIbmSchematicsPoliciesRead(context context.Context, d *schema.Reso for _, modelItem := range policyList.Policies { modelMap, err := dataSourceIbmSchematicsPoliciesPolicyLiteToMap(&modelItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed: %s", err.Error()), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } policies = append(policies, modelMap) } } if err = d.Set("policies", policies); err != nil { - return diag.FromErr(fmt.Errorf("Error setting policies %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPoliciesRead failed with error: %s", err), "ibm_schematics_policies", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_policy.go b/ibm/service/schematics/data_source_ibm_schematics_policy.go index 5bab24dfe2..ab09041fb8 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_policy.go +++ b/ibm/service/schematics/data_source_ibm_schematics_policy.go @@ -268,7 +268,9 @@ func DataSourceIbmSchematicsPolicy() *schema.Resource { func dataSourceIbmSchematicsPolicyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getPolicyOptions := &schematicsv1.GetPolicyOptions{} @@ -277,83 +279,115 @@ func dataSourceIbmSchematicsPolicyRead(context context.Context, d *schema.Resour policy, response, err := schematicsClient.GetPolicyWithContext(context, getPolicyOptions) if err != nil { - log.Printf("[DEBUG] GetPolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetPolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead GetPolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s", *getPolicyOptions.PolicyID)) if err = d.Set("name", policy.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", policy.Description); err != nil { - return diag.FromErr(fmt.Errorf("Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", policy.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", policy.Location); err != nil { - return diag.FromErr(fmt.Errorf("Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } state := []map[string]interface{}{} if policy.State != nil { modelMap, err := dataSourceIbmSchematicsPolicyUserStateToMap(policy.State) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } state = append(state, modelMap) } if err = d.Set("state", state); err != nil { - return diag.FromErr(fmt.Errorf("Error setting state %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("kind", policy.Kind); err != nil { - return diag.FromErr(fmt.Errorf("Error setting kind: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if policy.Tags != nil { if err = d.Set("tags", policy.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } target := []map[string]interface{}{} if policy.Target != nil { modelMap, err := dataSourceIbmSchematicsPolicyPolicyObjectsToMap(policy.Target) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } target = append(target, modelMap) } if err = d.Set("target", target); err != nil { - return diag.FromErr(fmt.Errorf("Error setting target %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } parameter := []map[string]interface{}{} if policy.Parameter != nil { modelMap, err := dataSourceIbmSchematicsPolicyPolicyParameterToMap(policy.Parameter) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } parameter = append(parameter, modelMap) } if err = d.Set("parameter", parameter); err != nil { - return diag.FromErr(fmt.Errorf("Error setting parameter %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("id", policy.ID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("crn", policy.Crn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("account", policy.Account); err != nil { - return diag.FromErr(fmt.Errorf("Error setting account: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } scopedResources := []map[string]interface{}{} @@ -361,25 +395,35 @@ func dataSourceIbmSchematicsPolicyRead(context context.Context, d *schema.Resour for _, modelItem := range policy.ScopedResources { modelMap, err := dataSourceIbmSchematicsPolicyScopedResourceToMap(&modelItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } scopedResources = append(scopedResources, modelMap) } } if err = d.Set("scoped_resources", scopedResources); err != nil { - return diag.FromErr(fmt.Errorf("Error setting scoped_resources %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(policy.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", policy.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(policy.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil diff --git a/ibm/service/schematics/data_source_ibm_schematics_resource_query.go b/ibm/service/schematics/data_source_ibm_schematics_resource_query.go index d9625ba981..0efc508045 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_resource_query.go +++ b/ibm/service/schematics/data_source_ibm_schematics_resource_query.go @@ -117,7 +117,9 @@ func DataSourceIBMSchematicsResourceQuery() *schema.Resource { func dataSourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { @@ -133,37 +135,55 @@ func dataSourceIBMSchematicsResourceQueryRead(context context.Context, d *schema resourceQueryRecord, response, err := schematicsClient.GetResourcesQueryWithContext(context, getResourcesQueryOptions) if err != nil { - log.Printf("[DEBUG] GetResourcesQueryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetResourcesQueryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead GetResourcesQueryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*getResourcesQueryOptions.QueryID) if err = d.Set("type", resourceQueryRecord.Type); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", resourceQueryRecord.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("id", resourceQueryRecord.ID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(resourceQueryRecord.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", resourceQueryRecord.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(resourceQueryRecord.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", resourceQueryRecord.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if resourceQueryRecord.Queries != nil { err = d.Set("queries", dataSourceResourceQueryRecordFlattenQueries(resourceQueryRecord.Queries)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting queries %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/data_source_ibm_schematics_state.go b/ibm/service/schematics/data_source_ibm_schematics_state.go index c66d1145ce..6785aef006 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_state.go +++ b/ibm/service/schematics/data_source_ibm_schematics_state.go @@ -59,7 +59,9 @@ func DataSourceIBMSchematicsState() *schema.Resource { func dataSourceIBMSchematicsStateRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsStateRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_state", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -76,8 +78,10 @@ func dataSourceIBMSchematicsStateRead(context context.Context, d *schema.Resourc _, response, _ := schematicsClient.GetWorkspaceTemplateStateWithContext(context, getWorkspaceTemplateStateOptions) if response.StatusCode != 200 { - log.Printf("[DEBUG] GetWorkspaceTemplateStateWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetWorkspaceTemplateStateWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsStateRead GetWorkspaceTemplateStateWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_state", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(dataSourceIBMSchematicsStateID(d)) @@ -96,7 +100,9 @@ func dataSourceIBMSchematicsStateRead(context context.Context, d *schema.Resourc stateByte, err := json.MarshalIndent(stateStore, "", "") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsStateRead failed: %s", err.Error()), "ibm_schematics_state", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } stateStoreJSON := string(stateByte[:]) @@ -104,7 +110,9 @@ func dataSourceIBMSchematicsStateRead(context context.Context, d *schema.Resourc controller, err := flex.GetBaseController(meta) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsStateRead failed: %s", err.Error()), "ibm_schematics_state", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.Set(flex.ResourceControllerURL, controller+"/schematics") diff --git a/ibm/service/schematics/data_source_ibm_schematics_workspace.go b/ibm/service/schematics/data_source_ibm_schematics_workspace.go index 7e59232d2f..4d28946df1 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_workspace.go +++ b/ibm/service/schematics/data_source_ibm_schematics_workspace.go @@ -638,7 +638,9 @@ func SchematicsEndpointURL(region, meta interface{}) (string, bool, error) { func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -654,8 +656,10 @@ func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Res workspaceResponse, response, err := schematicsClient.GetWorkspaceWithContext(context, getWorkspaceOptions) if err != nil { - log.Printf("[DEBUG] GetWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead GetWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*getWorkspaceOptions.WID) @@ -663,104 +667,156 @@ func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Res if workspaceResponse.CatalogRef != nil { err = d.Set("catalog_ref", dataSourceWorkspaceResponseFlattenCatalogRef(*workspaceResponse.CatalogRef)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting catalog_ref %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("created_at", flex.DateTimeToString(workspaceResponse.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", workspaceResponse.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("crn", workspaceResponse.Crn); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", workspaceResponse.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("last_health_check_at", flex.DateTimeToString(workspaceResponse.LastHealthCheckAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting last_health_check_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", workspaceResponse.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", workspaceResponse.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", workspaceResponse.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.RuntimeData != nil { err = d.Set("runtime_data", dataSourceWorkspaceResponseFlattenRuntimeData(workspaceResponse.RuntimeData)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting runtime_data %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.SharedData != nil { err = d.Set("shared_data", dataSourceWorkspaceResponseFlattenSharedData(*workspaceResponse.SharedData)) if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting shared_data %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("status", workspaceResponse.Status); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting status: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.TemplateData != nil { templateData := dataSourceWorkspaceResponseFlattenTemplateData(workspaceResponse.TemplateData) if err = d.Set("template_env_settings", templateData[0]["env_values"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading env_values: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_folder", templateData[0]["folder"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading folder: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_init_state_file", templateData[0]["init_state_file"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading init_state_file: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_type", templateData[0]["type"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_uninstall_script_name", templateData[0]["uninstall_script_name"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading uninstall_script_name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_values", templateData[0]["values"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading values: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } 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)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("template_ref", workspaceResponse.TemplateRef); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting template_ref: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.TemplateRepo != nil { templateRepoMap := dataSourceWorkspaceResponseFlattenTemplateRepo(*workspaceResponse.TemplateRepo) if err = d.Set("template_git_branch", templateRepoMap[0]["branch"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading branch: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_release", templateRepoMap[0]["release"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading release: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_repo_sha_value", templateRepoMap[0]["repo_sha_value"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading repo_sha_value: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_repo_url", templateRepoMap[0]["repo_url"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading repo_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_url", templateRepoMap[0]["url"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_has_uploadedgitrepotar", templateRepoMap[0]["has_uploadedgitrepotar"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading has_uploadedgitrepotar: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } /*if err = d.Set("type", workspaceResponse.Type); err != nil { @@ -768,54 +824,80 @@ func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Res }*/ if workspaceResponse.UpdatedAt != nil { if err = d.Set("updated_at", workspaceResponse.UpdatedAt.String()); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("updated_by", workspaceResponse.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.WorkspaceStatus != nil { workspaceStatusMap := dataSourceWorkspaceResponseFlattenWorkspaceStatus(*workspaceResponse.WorkspaceStatus) if err = d.Set("is_frozen", workspaceStatusMap[0]["frozen"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("frozen", workspaceStatusMap[0]["frozen"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("frozen_at", workspaceStatusMap[0]["frozen_at"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("frozen_by", workspaceStatusMap[0]["frozen_by"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("is_locked", workspaceStatusMap[0]["locked"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked", workspaceStatusMap[0]["locked"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked_by", workspaceStatusMap[0]["locked_by"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked_time", workspaceStatusMap[0]["locked_time"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked_time: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.WorkspaceStatusMsg != nil { workspaceStatusMsgMap := dataSourceWorkspaceResponseFlattenWorkspaceStatusMsg(*workspaceResponse.WorkspaceStatusMsg) if err = d.Set("status_code", workspaceStatusMsgMap[0]["status_code"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_msg", workspaceStatusMsgMap[0]["status_msg"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading status_msg: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } controller, err := flex.GetBaseController(meta) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("dataSourceIBMSchematicsWorkspaceRead failed: %s", err.Error()), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.Set(flex.ResourceControllerURL, controller+"/schematics") @@ -863,7 +945,7 @@ func dataSourceWorkspaceResponseCatalogRefToMap(catalogRefItem schematicsv1.Cata if catalogRefItem.ServiceExtensions != nil { serviceExtensionsByte, err := json.MarshalIndent(catalogRefItem.ServiceExtensions, "", "") if err != nil { - log.Printf("[DEBUG] Marshelling of service extensions failed %s", err) + } serviceExtensionsJSON := string(serviceExtensionsByte[:]) catalogRefMap["service_extensions"] = serviceExtensionsJSON diff --git a/ibm/service/schematics/resource_ibm_schematics_action.go b/ibm/service/schematics/resource_ibm_schematics_action.go index cf291e7807..1c3a39313b 100644 --- a/ibm/service/schematics/resource_ibm_schematics_action.go +++ b/ibm/service/schematics/resource_ibm_schematics_action.go @@ -960,7 +960,7 @@ func ResourceIBMSchematicsActionValidator() *validate.ResourceValidator { ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, Type: validate.TypeString, Optional: true, - AllowedValues: "cos_bucket, external_scm, git_hub, git_hub_enterprise, git_lab, ibm_cloud_catalog, ibm_git_lab, local", + AllowedValues: "cos_bucket, external_scm, git_hub, git_hub_enterprise, git_lab, ibm_schematics_action_catalog, ibm_git_lab, local", }, validate.ValidateSchema{ Identifier: actionName, @@ -978,7 +978,9 @@ func ResourceIBMSchematicsActionValidator() *validate.ResourceValidator { func resourceIBMSchematicsActionCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_action", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -1077,8 +1079,10 @@ func resourceIBMSchematicsActionCreate(context context.Context, d *schema.Resour action, response, err := schematicsClient.CreateActionWithContext(context, createActionOptions) if err != nil { - log.Printf("[DEBUG] CreateActionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateActionWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionCreate CreateActionWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*action.ID) @@ -1334,7 +1338,9 @@ func resourceIBMSchematicsActionMapToSystemLock(systemLockMap map[string]interfa func resourceIBMSchematicsActionRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1352,51 +1358,75 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource d.SetId("") return nil } - log.Printf("[DEBUG] GetActionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetActionWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead GetActionWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", action.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", action.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", action.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", action.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Tags != nil { if err = d.Set("tags", action.Tags); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.UserState != nil { userStateMap := resourceIBMSchematicsActionUserStateToMap(*action.UserState) if err = d.Set("user_state", []map[string]interface{}{userStateMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting user_state: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("source_readme_url", action.SourceReadmeURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_readme_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if _, ok := d.GetOk("source"); ok { if action.Source != nil { sourceMap := resourceIBMSchematicsActionExternalSourceToMap(*action.Source) if err = d.Set("source", []map[string]interface{}{sourceMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } } if err = d.Set("source_type", action.SourceType); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_parameter", action.CommandParameter); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_parameter: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("inventory", action.Inventory); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting inventory: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Credentials != nil { credentials := []map[string]interface{}{} @@ -1405,25 +1435,33 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource credentials = append(credentials, credentialsItemMap) } if err = d.Set("credentials", credentials); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting credentials: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if _, ok := d.GetOk("bastion"); ok { if action.Bastion != nil { bastionMap := resourceIBMSchematicsActionBastionResourceDefinitionToMap(*action.Bastion) if err = d.Set("bastion", []map[string]interface{}{bastionMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } } if action.BastionCredential != nil { bastionCredentialMap := resourceIBMSchematicsActionCredentialVariableDataToMap(*action.BastionCredential) if err = d.Set("bastion_credential", []map[string]interface{}{bastionCredentialMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion_credential: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("targets_ini", action.TargetsIni); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting targets_ini: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.Inputs != nil { actionInputs := []map[string]interface{}{} @@ -1432,7 +1470,9 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource actionInputs = append(actionInputs, actionInputsItemMap) } if err = d.Set("action_inputs", actionInputs); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting action_inputs: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.Outputs != nil { @@ -1442,7 +1482,9 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource actionOutputs = append(actionOutputs, actionOutputsItemMap) } if err = d.Set("action_outputs", actionOutputs); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting action_outputs: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.Settings != nil { @@ -1452,54 +1494,82 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource settings = append(settings, settingsItemMap) } if err = d.Set("settings", settings); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting settings: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.State != nil { stateMap := resourceIBMSchematicsActionActionStateToMap(*action.State) if err = d.Set("state", []map[string]interface{}{stateMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting state: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if action.SysLock != nil { sysLockMap := resourceIBMSchematicsActionSystemLockToMap(*action.SysLock) if err = d.Set("sys_lock", []map[string]interface{}{sysLockMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting sys_lock: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("crn", action.Crn); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("account", action.Account); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting account: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_created_at", flex.DateTimeToString(action.SourceCreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_created_by", action.SourceCreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_updated_at", flex.DateTimeToString(action.SourceUpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("source_updated_by", action.SourceUpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting source_updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(action.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", action.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(action.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", action.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if action.PlaybookNames != nil && len(action.PlaybookNames) > 0 { if err = d.Set("playbook_names", action.PlaybookNames); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting playbook_names: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionRead failed with error: %s", err), "ibm_schematics_action", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } else { d.Set("playbook_names", []string{}) @@ -1782,7 +1852,9 @@ func resourceIBMSchematicsActionSystemLockToMap(systemLock schematicsv1.SystemLo func resourceIBMSchematicsActionUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_action", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1907,8 +1979,10 @@ func resourceIBMSchematicsActionUpdate(context context.Context, d *schema.Resour if hasChange { _, response, err := schematicsClient.UpdateActionWithContext(context, updateActionOptions) if err != nil { - log.Printf("[DEBUG] UpdateActionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateActionWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionUpdate failed with error: %s and response:\n%s", err, response), "ibm_schematics_action", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -1918,7 +1992,9 @@ func resourceIBMSchematicsActionUpdate(context context.Context, d *schema.Resour func resourceIBMSchematicsActionDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_action", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1932,8 +2008,10 @@ func resourceIBMSchematicsActionDelete(context context.Context, d *schema.Resour response, err := schematicsClient.DeleteActionWithContext(context, deleteActionOptions) if err != nil { - log.Printf("[DEBUG] DeleteActionWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteActionWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsActionDelete DeleteActionWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_action", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_agent.go b/ibm/service/schematics/resource_ibm_schematics_agent.go index 5dd0150fe9..67033ee671 100644 --- a/ibm/service/schematics/resource_ibm_schematics_agent.go +++ b/ibm/service/schematics/resource_ibm_schematics_agent.go @@ -558,7 +558,9 @@ func ResourceIbmSchematicsAgent() *schema.Resource { func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createAgentDataOptions := &schematicsv1.CreateAgentDataOptions{} @@ -570,7 +572,9 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc createAgentDataOptions.SetAgentLocation(d.Get("agent_location").(string)) agentInfrastructureModel, err := resourceIbmSchematicsAgentMapToAgentInfrastructure(d.Get("agent_infrastructure.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate failed: %s", err.Error()), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createAgentDataOptions.SetAgentInfrastructure(agentInfrastructureModel) if _, ok := d.GetOk("description"); ok { @@ -585,7 +589,9 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc value := e.(map[string]interface{}) agentMetadataItem, err := resourceIbmSchematicsAgentMapToAgentMetadataInfo(value) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate failed: %s", err.Error()), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentMetadata = append(agentMetadata, *agentMetadataItem) } @@ -597,7 +603,9 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc value := e.(map[string]interface{}) agentInputsItem, err := resourceIbmSchematicsAgentMapToVariableData(value) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate failed: %s", err.Error()), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInputs = append(agentInputs, *agentInputsItem) } @@ -606,15 +614,19 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc if _, ok := d.GetOk("user_state"); ok { userStateModel, err := resourceIbmSchematicsAgentMapToAgentUserState(d.Get("user_state.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate failed: %s", err.Error()), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createAgentDataOptions.SetUserState(userStateModel) } agentData, response, err := schematicsClient.CreateAgentDataWithContext(context, createAgentDataOptions) if err != nil { - log.Printf("[DEBUG] CreateAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentCreate CreateAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*agentData.ID) @@ -625,7 +637,9 @@ func resourceIbmSchematicsAgentCreate(context context.Context, d *schema.Resourc func resourceIbmSchematicsAgentRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -640,38 +654,58 @@ func resourceIbmSchematicsAgentRead(context context.Context, d *schema.ResourceD d.SetId("") return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", agentData.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", agentData.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("schematics_location", agentData.SchematicsLocation); err != nil { - return diag.FromErr(fmt.Errorf("Error setting schematics_location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_location", agentData.AgentLocation); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInfrastructureMap, err := resourceIbmSchematicsAgentAgentInfrastructureToMap(agentData.AgentInfrastructure) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_infrastructure", []map[string]interface{}{agentInfrastructureMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_infrastructure: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", agentData.Description); err != nil { - return diag.FromErr(fmt.Errorf("Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.Tags != nil { if err = d.Set("tags", agentData.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } agentMetadata := []map[string]interface{}{} @@ -679,94 +713,136 @@ func resourceIbmSchematicsAgentRead(context context.Context, d *schema.ResourceD for _, agentMetadataItem := range agentData.AgentMetadata { agentMetadataItemMap, err := resourceIbmSchematicsAgentAgentMetadataInfoToMap(&agentMetadataItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentMetadata = append(agentMetadata, agentMetadataItemMap) } } if err = d.Set("agent_metadata", agentMetadata); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_metadata: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInputs := []map[string]interface{}{} if agentData.AgentInputs != nil { for _, agentInputsItem := range agentData.AgentInputs { agentInputsItemMap, err := resourceIbmSchematicsAgentVariableDataToMap(&agentInputsItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentInputs = append(agentInputs, agentInputsItemMap) } } if err = d.Set("agent_inputs", agentInputs); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_inputs: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.UserState != nil { userStateMap, err := resourceIbmSchematicsAgentAgentUserStateToMap(agentData.UserState) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("user_state", []map[string]interface{}{userStateMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting user_state: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if agentData.AgentKpi != nil { agentKpiMap, err := resourceIbmSchematicsAgentAgentKPIDataToMap(agentData.AgentKpi) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_kpi", []map[string]interface{}{agentKpiMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_kpi: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("agent_crn", agentData.AgentCrn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(agentData.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("creation_by", agentData.CreationBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting creation_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(agentData.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.SystemState != nil { systemStateMap, err := resourceIbmSchematicsAgentAgentSystemStatusToMap(agentData.SystemState) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("system_state", []map[string]interface{}{systemStateMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting system_state: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if agentData.RecentPrsJob != nil { recentPrsJobMap, err := resourceIbmSchematicsAgentAgentDataRecentPrsJobToMap(agentData.RecentPrsJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("recent_prs_job", []map[string]interface{}{recentPrsJobMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_prs_job: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if agentData.RecentDeployJob != nil { recentDeployJobMap, err := resourceIbmSchematicsAgentAgentDataRecentDeployJobToMap(agentData.RecentDeployJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("recent_deploy_job", []map[string]interface{}{recentDeployJobMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_deploy_job: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if agentData.RecentHealthJob != nil { recentHealthJobMap, err := resourceIbmSchematicsAgentAgentDataRecentHealthJobToMap(agentData.RecentHealthJob) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed: %s", err.Error()), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("recent_health_job", []map[string]interface{}{recentHealthJobMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting recent_health_job: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentRead failed with error: %s", err), "ibm_schematics_agent", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -804,13 +880,17 @@ func agentDestroyRefreshFunc(schematicsClient *schematicsv1.SchematicsV1, id str func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updateAgentDataOptions := &schematicsv1.UpdateAgentDataOptions{} session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -836,8 +916,10 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc d.SetId("") return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.Name != nil { updateAgentDataOptions.Name = agentData.Name @@ -892,7 +974,9 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc if d.HasChange("agent_infrastructure") { agentInfrastructure, err := resourceIbmSchematicsAgentMapToAgentInfrastructure(d.Get("agent_infrastructure.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate failed: %s", err.Error()), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updateAgentDataOptions.SetAgentInfrastructure(agentInfrastructure) hasChange = true @@ -911,7 +995,9 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc value := e.(map[string]interface{}) agentMetadataItem, err := resourceIbmSchematicsAgentMapToAgentMetadataInfo(value) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate failed: %s", err.Error()), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } agentMetadata = append(agentMetadata, *agentMetadataItem) } @@ -927,19 +1013,22 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc response, err := schematicsClient.DeleteAgentResourcesWithContext(context, deleteAgentResourcesOptions) if err != nil { - log.Printf("[DEBUG] DeleteAgentResourcesWithContext failed %s\n%s", err, response) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate DeleteAgentResourcesWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) } else { _, err = isWaitForAgentDestroyResources(context, schematicsClient, *deleteAgentResourcesOptions.AgentID, d.Timeout(schema.TimeoutUpdate)) if err != nil { - log.Printf("[DEBUG] waiting for agent deploy resources to be destroyed has failed %s", err) + } } } if hasChange { _, response, err := schematicsClient.UpdateAgentDataWithContext(context, updateAgentDataOptions) if err != nil { - log.Printf("[DEBUG] UpdateAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentUpdate failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -949,7 +1038,9 @@ func resourceIbmSchematicsAgentUpdate(context context.Context, d *schema.Resourc func resourceIbmSchematicsAgentDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deleteAgentDataOptions := &schematicsv1.DeleteAgentDataOptions{ @@ -957,7 +1048,9 @@ func resourceIbmSchematicsAgentDelete(context context.Context, d *schema.Resourc } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDelete bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -979,11 +1072,12 @@ func resourceIbmSchematicsAgentDelete(context context.Context, d *schema.Resourc response, err := schematicsClient.DeleteAgentResourcesWithContext(context, deleteAgentResourcesOptions) if err != nil { - log.Printf("[DEBUG] DeleteAgentResourcesWithContext failed %s\n%s", err, response) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDelete DeleteAgentResourcesWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) } else { _, err = isWaitForAgentDestroyResources(context, schematicsClient, *deleteAgentResourcesOptions.AgentID, d.Timeout(schema.TimeoutDelete)) if err != nil { - log.Printf("[DEBUG] waiting for agent deploy resources to be destroyed has failed %s", err) + } } @@ -991,8 +1085,9 @@ func resourceIbmSchematicsAgentDelete(context context.Context, d *schema.Resourc deleteresponse, err := schematicsClient.DeleteAgentDataWithContext(context, deleteAgentDataOptions) if err != nil { - log.Printf("[DEBUG] DeleteAgentDataWithContext failed %s\n%s", err, deleteresponse) - return diag.FromErr(fmt.Errorf("DeleteAgentDataWithContext failed %s\n%s", err, deleteresponse)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDelete DeleteAgentDataWithContext failed with error: %s and response:\n%s", err, deleteresponse), "ibm_schematics_agent", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_agent_deploy.go b/ibm/service/schematics/resource_ibm_schematics_agent_deploy.go index 5610a01ef6..e40ebefb90 100644 --- a/ibm/service/schematics/resource_ibm_schematics_agent_deploy.go +++ b/ibm/service/schematics/resource_ibm_schematics_agent_deploy.go @@ -91,11 +91,15 @@ func ResourceIbmSchematicsAgentDeploy() *schema.Resource { func resourceIbmSchematicsAgentDeployCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployCreate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -113,8 +117,10 @@ func resourceIbmSchematicsAgentDeployCreate(context context.Context, d *schema.R agentDeployJob, response, err := schematicsClient.DeployAgentJobWithContext(context, deployAgentJobOptions) if err != nil { - log.Printf("[DEBUG] DeployAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeployAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployCreate DeployAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_deploy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *deployAgentJobOptions.AgentID, *agentDeployJob.JobID)) @@ -122,7 +128,9 @@ func resourceIbmSchematicsAgentDeployCreate(context context.Context, d *schema.R _, err = isWaitForAgentAvailable(context, schematicsClient, *deployAgentJobOptions.AgentID, d.Timeout(schema.TimeoutCreate)) if err != nil { - return diag.FromErr(fmt.Errorf("Waiting for agent to be available failed %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployCreate failed with error: %s", err), "ibm_schematics_agent_deploy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return resourceIbmSchematicsAgentDeployRead(context, d, meta) @@ -172,12 +180,16 @@ func agentRefreshFunc(schematicsClient *schematicsv1.SchematicsV1, id string) re func resourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -191,34 +203,52 @@ func resourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.Res d.SetId("") return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.RecentDeployJob != nil { if err = d.Set("agent_id", parts[0]); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentDeployJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentDeployJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentDeployJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentDeployJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentDeployJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentDeployJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployRead failed with error: %s", err), "ibm_schematics_agent_deploy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -228,11 +258,15 @@ func resourceIbmSchematicsAgentDeployRead(context context.Context, d *schema.Res func resourceIbmSchematicsAgentDeployUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -245,7 +279,9 @@ func resourceIbmSchematicsAgentDeployUpdate(context context.Context, d *schema.R parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate failed: %s", err.Error()), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deployAgentJobOptions.SetAgentID(parts[0]) @@ -253,8 +289,9 @@ func resourceIbmSchematicsAgentDeployUpdate(context context.Context, d *schema.R hasChange := false if d.HasChange("agent_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "agent_id")) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate failed with error: %s", err), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if d.HasChange("force") { deployAgentJobOptions.SetForce(d.Get("force").(bool)) @@ -264,14 +301,18 @@ func resourceIbmSchematicsAgentDeployUpdate(context context.Context, d *schema.R if hasChange { agentDeployJob, response, err := schematicsClient.DeployAgentJobWithContext(context, deployAgentJobOptions) if err != nil { - log.Printf("[DEBUG] DeployAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeployAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate DeployAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *deployAgentJobOptions.AgentID, *agentDeployJob.JobID)) _, err = isWaitForAgentAvailable(context, schematicsClient, parts[0], d.Timeout(schema.TimeoutUpdate)) if err != nil { - return diag.FromErr(fmt.Errorf("Waiting for agent to be available failed %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentDeployUpdate failed with error: %s", err), "ibm_schematics_agent_deploy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } diff --git a/ibm/service/schematics/resource_ibm_schematics_agent_health.go b/ibm/service/schematics/resource_ibm_schematics_agent_health.go index a0765c75d9..1e9f977033 100644 --- a/ibm/service/schematics/resource_ibm_schematics_agent_health.go +++ b/ibm/service/schematics/resource_ibm_schematics_agent_health.go @@ -79,11 +79,15 @@ func ResourceIbmSchematicsAgentHealth() *schema.Resource { func resourceIbmSchematicsAgentHealthCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthCreate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -102,8 +106,10 @@ func resourceIbmSchematicsAgentHealthCreate(context context.Context, d *schema.R agentHealthJob, response, err := schematicsClient.HealthCheckAgentJobWithContext(context, healthCheckAgentJobOptions) if err != nil { - log.Printf("[DEBUG] HealthCheckAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("HealthCheckAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthCreate HealthCheckAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_health", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *healthCheckAgentJobOptions.AgentID, *agentHealthJob.JobID)) @@ -114,12 +120,16 @@ func resourceIbmSchematicsAgentHealthCreate(context context.Context, d *schema.R func resourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed: %s", err.Error()), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -134,35 +144,53 @@ func resourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.Res d.SetId("") return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.RecentHealthJob != nil { if err = d.Set("agent_id", parts[0]); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentHealthJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentHealthJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentHealthJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentHealthJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentHealthJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentHealthJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthRead failed with error: %s", err), "ibm_schematics_agent_health", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -173,11 +201,15 @@ func resourceIbmSchematicsAgentHealthRead(context context.Context, d *schema.Res func resourceIbmSchematicsAgentHealthUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthUpdate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_health", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -191,7 +223,9 @@ func resourceIbmSchematicsAgentHealthUpdate(context context.Context, d *schema.R parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthUpdate failed: %s", err.Error()), "ibm_schematics_agent_health", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } healthCheckAgentJobOptions.SetAgentID(parts[0]) @@ -199,8 +233,9 @@ func resourceIbmSchematicsAgentHealthUpdate(context context.Context, d *schema.R hasChange := false if d.HasChange("agent_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "agent_id")) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthUpdate failed with error: %s", err), "ibm_schematics_agent_health", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if d.HasChange("force") { healthCheckAgentJobOptions.SetForce(d.Get("force").(bool)) @@ -210,8 +245,10 @@ func resourceIbmSchematicsAgentHealthUpdate(context context.Context, d *schema.R if hasChange { agentHealthJob, response, err := schematicsClient.HealthCheckAgentJobWithContext(context, healthCheckAgentJobOptions) if err != nil { - log.Printf("[DEBUG] HealthCheckAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("HealthCheckAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentHealthUpdate HealthCheckAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_health", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *healthCheckAgentJobOptions.AgentID, *agentHealthJob.JobID)) } diff --git a/ibm/service/schematics/resource_ibm_schematics_agent_prs.go b/ibm/service/schematics/resource_ibm_schematics_agent_prs.go index 73032e4bc3..935b845d03 100644 --- a/ibm/service/schematics/resource_ibm_schematics_agent_prs.go +++ b/ibm/service/schematics/resource_ibm_schematics_agent_prs.go @@ -79,11 +79,15 @@ func ResourceIbmSchematicsAgentPrs() *schema.Resource { func resourceIbmSchematicsAgentPrsCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsCreate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -101,8 +105,10 @@ func resourceIbmSchematicsAgentPrsCreate(context context.Context, d *schema.Reso agentPrsJob, response, err := schematicsClient.PrsAgentJobWithContext(context, prsAgentJobOptions) if err != nil { - log.Printf("[DEBUG] PrsAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("PrsAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsCreate PrsAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_prs", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *prsAgentJobOptions.AgentID, *agentPrsJob.JobID)) @@ -113,12 +119,16 @@ func resourceIbmSchematicsAgentPrsCreate(context context.Context, d *schema.Reso func resourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed: %s", err.Error()), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getAgentDataOptions := &schematicsv1.GetAgentDataOptions{ @@ -133,34 +143,52 @@ func resourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.Resour d.SetId("") return nil } - log.Printf("[DEBUG] GetAgentDataWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetAgentDataWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead GetAgentDataWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if agentData.RecentPrsJob != nil { if err = d.Set("agent_id", parts[0]); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("job_id", agentData.RecentPrsJob.JobID); err != nil { - return diag.FromErr(fmt.Errorf("Error setting job_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(agentData.RecentPrsJob.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", agentData.RecentPrsJob.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("agent_version", agentData.Version); err != nil { - return diag.FromErr(fmt.Errorf("Error setting agent_version: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_code", agentData.RecentPrsJob.StatusCode); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_message", agentData.RecentPrsJob.StatusMessage); err != nil { - return diag.FromErr(fmt.Errorf("Error setting status_message: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_url", agentData.RecentPrsJob.LogURL); err != nil { - return diag.FromErr(fmt.Errorf("Error setting log_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsRead failed with error: %s", err), "ibm_schematics_agent_prs", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -170,11 +198,15 @@ func resourceIbmSchematicsAgentPrsRead(context context.Context, d *schema.Resour func resourceIbmSchematicsAgentPrsUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsUpdate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_agent_prs", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamAccessToken := session.Config.IAMAccessToken iamRefreshToken := session.Config.IAMRefreshToken @@ -188,7 +220,9 @@ func resourceIbmSchematicsAgentPrsUpdate(context context.Context, d *schema.Reso parts, err := flex.SepIdParts(d.Id(), "/") if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsUpdate failed: %s", err.Error()), "ibm_schematics_agent_prs", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } prsAgentJobOptions.SetAgentID(parts[0]) @@ -196,8 +230,9 @@ func resourceIbmSchematicsAgentPrsUpdate(context context.Context, d *schema.Reso hasChange := false if d.HasChange("agent_id") { - return diag.FromErr(fmt.Errorf("Cannot update resource property \"%s\" with the ForceNew annotation."+ - " The resource must be re-created to update this property.", "agent_id")) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsUpdate failed with error: %s", err), "ibm_schematics_agent_prs", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if d.HasChange("force") { prsAgentJobOptions.SetForce(d.Get("force").(bool)) @@ -207,8 +242,10 @@ func resourceIbmSchematicsAgentPrsUpdate(context context.Context, d *schema.Reso if hasChange { agentPrsJob, response, err := schematicsClient.PrsAgentJobWithContext(context, prsAgentJobOptions) if err != nil { - log.Printf("[DEBUG] PrsAgentJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("PrsAgentJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsAgentPrsUpdate PrsAgentJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_agent_prs", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(fmt.Sprintf("%s/%s", *prsAgentJobOptions.AgentID, *agentPrsJob.JobID)) } diff --git a/ibm/service/schematics/resource_ibm_schematics_inventory.go b/ibm/service/schematics/resource_ibm_schematics_inventory.go index 77b7e70630..b49aebf5be 100644 --- a/ibm/service/schematics/resource_ibm_schematics_inventory.go +++ b/ibm/service/schematics/resource_ibm_schematics_inventory.go @@ -112,7 +112,9 @@ func ResourceIBMSchematicsInventoryValidator() *validate.ResourceValidator { func resourceIBMSchematicsInventoryCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_inventory", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -144,8 +146,10 @@ func resourceIBMSchematicsInventoryCreate(context context.Context, d *schema.Res inventoryResourceRecord, response, err := schematicsClient.CreateInventoryWithContext(context, createInventoryOptions) if err != nil { - log.Printf("[DEBUG] CreateInventoryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateInventoryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryCreate CreateInventoryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_inventory", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*inventoryResourceRecord.ID) @@ -156,7 +160,9 @@ func resourceIBMSchematicsInventoryCreate(context context.Context, d *schema.Res func resourceIBMSchematicsInventoryRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } inventoryIDSplit := strings.Split(d.Id(), ".") region := inventoryIDSplit[0] @@ -175,40 +181,62 @@ func resourceIBMSchematicsInventoryRead(context context.Context, d *schema.Resou d.SetId("") return nil } - log.Printf("[DEBUG] GetInventoryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetInventoryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead GetInventoryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", inventoryResourceRecord.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", inventoryResourceRecord.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", inventoryResourceRecord.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", inventoryResourceRecord.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("inventories_ini", inventoryResourceRecord.InventoriesIni); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting inventories_ini: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if inventoryResourceRecord.ResourceQueries != nil { if err = d.Set("resource_queries", inventoryResourceRecord.ResourceQueries); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_queries: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("created_at", flex.DateTimeToString(inventoryResourceRecord.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", inventoryResourceRecord.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(inventoryResourceRecord.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", inventoryResourceRecord.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryRead failed with error: %s", err), "ibm_schematics_inventory", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil @@ -217,7 +245,9 @@ func resourceIBMSchematicsInventoryRead(context context.Context, d *schema.Resou func resourceIBMSchematicsInventoryUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_inventory", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } inventoryIDSplit := strings.Split(d.Id(), ".") @@ -265,8 +295,10 @@ func resourceIBMSchematicsInventoryUpdate(context context.Context, d *schema.Res if hasChange { _, response, err := schematicsClient.ReplaceInventoryWithContext(context, updateInventoryOptions) if err != nil { - log.Printf("[DEBUG] UpdateInventoryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateInventoryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryUpdate ReplaceInventoryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_inventory", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -276,7 +308,9 @@ func resourceIBMSchematicsInventoryUpdate(context context.Context, d *schema.Res func resourceIBMSchematicsInventoryDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_inventory", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } inventoryIDSplit := strings.Split(d.Id(), ".") region := inventoryIDSplit[0] @@ -290,8 +324,10 @@ func resourceIBMSchematicsInventoryDelete(context context.Context, d *schema.Res response, err := schematicsClient.DeleteInventoryWithContext(context, deleteInventoryOptions) if err != nil { - log.Printf("[DEBUG] DeleteInventoryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteInventoryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsInventoryDelete DeleteInventoryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_inventory", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_job.go b/ibm/service/schematics/resource_ibm_schematics_job.go index 4893b8b7ae..31665da6b0 100644 --- a/ibm/service/schematics/resource_ibm_schematics_job.go +++ b/ibm/service/schematics/resource_ibm_schematics_job.go @@ -2848,12 +2848,16 @@ func ResourceIBMSchematicsJobValidator() *validate.ResourceValidator { func resourceIBMSchematicsJobCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_job", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobCreate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_job", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamRefreshToken := session.Config.IAMRefreshToken @@ -2938,8 +2942,10 @@ func resourceIBMSchematicsJobCreate(context context.Context, d *schema.ResourceD job, response, err := schematicsClient.CreateJobWithContext(context, createJobOptions) if err != nil { - log.Printf("[DEBUG] CreateJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobCreate CreateJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_job", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*job.ID) @@ -3903,7 +3909,9 @@ func resourceIBMSchematicsJobMapToJobLogSummarySystemJob(jobLogSummarySystemJobM func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } jobIDSplit := strings.Split(d.Id(), ".") region := jobIDSplit[0] @@ -3921,26 +3929,38 @@ func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceDat d.SetId("") return nil } - log.Printf("[DEBUG] GetJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead GetJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_object", job.CommandObject); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_object: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_object_id", job.CommandObjectID); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_object_id: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("command_name", job.CommandName); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if _, ok := d.GetOk("command_parameter"); ok { if err = d.Set("command_parameter", d.Get("command_parameter").(string)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_parameter: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.CommandOptions != nil { if err = d.Set("command_options", job.CommandOptions); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_options: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Inputs != nil { @@ -3950,7 +3970,9 @@ func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceDat jobInputs = append(jobInputs, jobInputsItemMap) } if err = d.Set("job_inputs", jobInputs); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting job_inputs: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Settings != nil { @@ -3960,76 +3982,114 @@ func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceDat jobEnvSettings = append(jobEnvSettings, jobEnvSettingsItemMap) } if err = d.Set("job_env_settings", jobEnvSettings); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting job_env_settings: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Tags != nil { if err = d.Set("tags", job.Tags); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("location", job.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if job.Status != nil { statusMap := resourceIBMSchematicsJobJobStatusToMap(*job.Status) if err = d.Set("status", []map[string]interface{}{statusMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting status: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Data != nil { dataMap := resourceIBMSchematicsJobJobDataToMap(*job.Data) if err = d.Set("data", []map[string]interface{}{dataMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting data: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.Bastion != nil { bastionMap := resourceIBMSchematicsJobBastionResourceDefinitionToMap(*job.Bastion) if err = d.Set("bastion", []map[string]interface{}{bastionMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting bastion: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if job.LogSummary != nil { logSummaryMap := resourceIBMSchematicsJobJobLogSummaryToMap(*job.LogSummary) if err = d.Set("log_summary", []map[string]interface{}{logSummaryMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting log_summary: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("name", job.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", job.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", job.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("submitted_at", flex.DateTimeToString(job.SubmittedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting submitted_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("submitted_by", job.SubmittedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting submitted_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("start_at", flex.DateTimeToString(job.StartAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting start_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("end_at", flex.DateTimeToString(job.EndAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting end_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("duration", job.Duration); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting duration: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("log_store_url", job.LogStoreURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting log_store_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("state_store_url", job.StateStoreURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting state_store_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("results_url", job.ResultsURL); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting results_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(job.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobRead failed with error: %s", err), "ibm_schematics_job", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil @@ -4971,12 +5031,16 @@ func resourceIBMSchematicsJobJobLogSummarySystemJobToMap(jobLogSummarySystemJob func resourceIBMSchematicsJobUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_job", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobUpdate bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_job", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } iamRefreshToken := session.Config.IAMRefreshToken @@ -5061,8 +5125,10 @@ func resourceIBMSchematicsJobUpdate(context context.Context, d *schema.ResourceD _, response, err := schematicsClient.UpdateJobWithContext(context, updateJobOptions) if err != nil { - log.Printf("[DEBUG] UpdateJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobUpdate UpdateJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_job", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return resourceIBMSchematicsJobRead(context, d, meta) @@ -5072,12 +5138,16 @@ func resourceIBMSchematicsJobDelete(context context.Context, d *schema.ResourceD session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobDelete bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_job", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_job", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } jobIDSplit := strings.Split(d.Id(), ".") region := jobIDSplit[0] @@ -5094,8 +5164,10 @@ func resourceIBMSchematicsJobDelete(context context.Context, d *schema.ResourceD response, err := schematicsClient.DeleteJobWithContext(context, deleteJobOptions) if err != nil { - log.Printf("[DEBUG] DeleteJobWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteJobWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsJobDelete DeleteJobWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_job", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_policy.go b/ibm/service/schematics/resource_ibm_schematics_policy.go index 6d065fcfab..d63effbc5d 100644 --- a/ibm/service/schematics/resource_ibm_schematics_policy.go +++ b/ibm/service/schematics/resource_ibm_schematics_policy.go @@ -290,7 +290,9 @@ func ResourceIbmSchematicsPolicyValidator() *validate.ResourceValidator { func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createPolicyOptions := &schematicsv1.CreatePolicyOptions{} @@ -313,7 +315,9 @@ func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.Resour if _, ok := d.GetOk("state"); ok { stateModel, err := resourceIbmSchematicsPolicyMapToUserState(d.Get("state.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate failed: %s", err.Error()), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createPolicyOptions.SetState(stateModel) } @@ -323,14 +327,18 @@ func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.Resour if _, ok := d.GetOk("target"); ok { targetModel, err := resourceIbmSchematicsPolicyMapToPolicyObjects(d.Get("target.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate failed: %s", err.Error()), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createPolicyOptions.SetTarget(targetModel) } if _, ok := d.GetOk("parameter"); ok { parameterModel, err := resourceIbmSchematicsPolicyMapToPolicyParameter(d.Get("parameter.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate failed: %s", err.Error()), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } createPolicyOptions.SetParameter(parameterModel) } @@ -340,7 +348,9 @@ func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.Resour value := e.(map[string]interface{}) scopedResourcesItem, err := resourceIbmSchematicsPolicyMapToScopedResource(value) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate failed: %s", err.Error()), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } scopedResources = append(scopedResources, *scopedResourcesItem) } @@ -349,8 +359,10 @@ func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.Resour policy, response, err := schematicsClient.CreatePolicyWithContext(context, createPolicyOptions) if err != nil { - log.Printf("[DEBUG] CreatePolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreatePolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyCreate CreatePolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policy", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*policy.ID) @@ -361,7 +373,9 @@ func resourceIbmSchematicsPolicyCreate(context context.Context, d *schema.Resour func resourceIbmSchematicsPolicyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } getPolicyOptions := &schematicsv1.GetPolicyOptions{} @@ -374,55 +388,81 @@ func resourceIbmSchematicsPolicyRead(context context.Context, d *schema.Resource d.SetId("") return nil } - log.Printf("[DEBUG] GetPolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetPolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead GetPolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", policy.Name); err != nil { - return diag.FromErr(fmt.Errorf("Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("description", policy.Description); err != nil { - return diag.FromErr(fmt.Errorf("Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", policy.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if policy.Tags != nil { if err = d.Set("tags", policy.Tags); err != nil { - return diag.FromErr(fmt.Errorf("Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("location", policy.Location); err != nil { - return diag.FromErr(fmt.Errorf("Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if policy.State != nil { stateMap, err := resourceIbmSchematicsPolicyUserStateToMap(policy.State) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("state", []map[string]interface{}{stateMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting state: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("kind", policy.Kind); err != nil { - return diag.FromErr(fmt.Errorf("Error setting kind: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if policy.Target != nil { targetMap, err := resourceIbmSchematicsPolicyPolicyObjectsToMap(policy.Target) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("target", []map[string]interface{}{targetMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting target: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if policy.Parameter != nil { parameterMap, err := resourceIbmSchematicsPolicyPolicyParameterToMap(policy.Parameter) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("parameter", []map[string]interface{}{parameterMap}); err != nil { - return diag.FromErr(fmt.Errorf("Error setting parameter: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } scopedResources := []map[string]interface{}{} @@ -430,28 +470,42 @@ func resourceIbmSchematicsPolicyRead(context context.Context, d *schema.Resource for _, scopedResourcesItem := range policy.ScopedResources { scopedResourcesItemMap, err := resourceIbmSchematicsPolicyScopedResourceToMap(&scopedResourcesItem) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed: %s", err.Error()), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } scopedResources = append(scopedResources, scopedResourcesItemMap) } } if err = d.Set("scoped_resources", scopedResources); err != nil { - return diag.FromErr(fmt.Errorf("Error setting scoped_resources: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("crn", policy.Crn); err != nil { - return diag.FromErr(fmt.Errorf("Error setting crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("account", policy.Account); err != nil { - return diag.FromErr(fmt.Errorf("Error setting account: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_at", flex.DateTimeToString(policy.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", policy.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(policy.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyRead failed with error: %s", err), "ibm_schematics_policy", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil @@ -460,7 +514,9 @@ func resourceIbmSchematicsPolicyRead(context context.Context, d *schema.Resource func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updatePolicyOptions := &schematicsv1.UpdatePolicyOptions{} @@ -488,7 +544,9 @@ func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.Resour if d.HasChange("state") { state, err := resourceIbmSchematicsPolicyMapToUserState(d.Get("state.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyUpdate failed: %s", err.Error()), "ibm_schematics_policy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updatePolicyOptions.SetState(state) hasChange = true @@ -500,7 +558,9 @@ func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.Resour if d.HasChange("target") { target, err := resourceIbmSchematicsPolicyMapToPolicyObjects(d.Get("target.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyUpdate failed: %s", err.Error()), "ibm_schematics_policy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updatePolicyOptions.SetTarget(target) hasChange = true @@ -508,7 +568,9 @@ func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.Resour if d.HasChange("parameter") { parameter, err := resourceIbmSchematicsPolicyMapToPolicyParameter(d.Get("parameter.0").(map[string]interface{})) if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyUpdate failed: %s", err.Error()), "ibm_schematics_policy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } updatePolicyOptions.SetParameter(parameter) hasChange = true @@ -521,8 +583,10 @@ func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.Resour if hasChange { _, response, err := schematicsClient.UpdatePolicyWithContext(context, updatePolicyOptions) if err != nil { - log.Printf("[DEBUG] UpdatePolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdatePolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyUpdate UpdatePolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policy", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -532,7 +596,9 @@ func resourceIbmSchematicsPolicyUpdate(context context.Context, d *schema.Resour func resourceIbmSchematicsPolicyDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_policy", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } deletePolicyOptions := &schematicsv1.DeletePolicyOptions{} @@ -541,8 +607,10 @@ func resourceIbmSchematicsPolicyDelete(context context.Context, d *schema.Resour response, err := schematicsClient.DeletePolicyWithContext(context, deletePolicyOptions) if err != nil { - log.Printf("[DEBUG] DeletePolicyWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeletePolicyWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIbmSchematicsPolicyDelete DeletePolicyWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_policy", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_resource_query.go b/ibm/service/schematics/resource_ibm_schematics_resource_query.go index ab9817a1be..65cf4732f9 100644 --- a/ibm/service/schematics/resource_ibm_schematics_resource_query.go +++ b/ibm/service/schematics/resource_ibm_schematics_resource_query.go @@ -137,7 +137,9 @@ func ResourceIBMSchematicsResourceQueryValidator() *validate.ResourceValidator { func resourceIBMSchematicsResourceQueryCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_resource_query", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -166,8 +168,10 @@ func resourceIBMSchematicsResourceQueryCreate(context context.Context, d *schema resourceQueryRecord, response, err := schematicsClient.CreateResourceQueryWithContext(context, createResourceQueryOptions) if err != nil { - log.Printf("[DEBUG] CreateResourceQueryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateResourceQueryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryCreate CreateResourceQueryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_resource_query", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*resourceQueryRecord.ID) @@ -219,7 +223,9 @@ func resourceIBMSchematicsResourceQueryMapToResourceQueryParam(resourceQueryPara func resourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -237,14 +243,20 @@ func resourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.R d.SetId("") return nil } - log.Printf("[DEBUG] GetResourcesQueryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetResourcesQueryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead GetResourcesQueryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("type", resourceQueryRecord.Type); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", resourceQueryRecord.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if resourceQueryRecord.Queries != nil { queries := []map[string]interface{}{} @@ -253,20 +265,30 @@ func resourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.R queries = append(queries, queriesItemMap) } if err = d.Set("queries", queries); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting queries: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("created_at", flex.DateTimeToString(resourceQueryRecord.CreatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("created_by", resourceQueryRecord.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_at", flex.DateTimeToString(resourceQueryRecord.UpdatedAt)); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("updated_by", resourceQueryRecord.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryRead failed with error: %s", err), "ibm_schematics_resource_query", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return nil @@ -313,7 +335,9 @@ func resourceIBMSchematicsResourceQueryResourceQueryParamToMap(resourceQueryPara func resourceIBMSchematicsResourceQueryUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_resource_query", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -342,8 +366,10 @@ func resourceIBMSchematicsResourceQueryUpdate(context context.Context, d *schema _, response, err := schematicsClient.ReplaceResourcesQueryWithContext(context, replaceResourcesQueryOptions) if err != nil { - log.Printf("[DEBUG] ReplaceResourcesQueryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceResourcesQueryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryUpdate ReplaceResourcesQueryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_resource_query", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } return resourceIBMSchematicsResourceQueryRead(context, d, meta) @@ -352,7 +378,9 @@ func resourceIBMSchematicsResourceQueryUpdate(context context.Context, d *schema func resourceIBMSchematicsResourceQueryDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_resource_query", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -366,8 +394,10 @@ func resourceIBMSchematicsResourceQueryDelete(context context.Context, d *schema response, err := schematicsClient.DeleteResourcesQueryWithContext(context, deleteResourcesQueryOptions) if err != nil { - log.Printf("[DEBUG] DeleteResourcesQueryWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteResourcesQueryWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsResourceQueryDelete DeleteResourcesQueryWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_resource_query", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("") diff --git a/ibm/service/schematics/resource_ibm_schematics_workspace.go b/ibm/service/schematics/resource_ibm_schematics_workspace.go index bbd89ddf2f..4d2ac61244 100644 --- a/ibm/service/schematics/resource_ibm_schematics_workspace.go +++ b/ibm/service/schematics/resource_ibm_schematics_workspace.go @@ -592,7 +592,9 @@ func ResourceIBMSchematicsWorkspaceValidator() *validate.ResourceValidator { func resourceIBMSchematicsWorkspaceCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceCreate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if r, ok := d.GetOk("location"); ok { region := r.(string) @@ -753,8 +755,10 @@ func resourceIBMSchematicsWorkspaceCreate(context context.Context, d *schema.Res workspaceResponse, response, err := schematicsClient.CreateWorkspaceWithContext(context, createWorkspaceOptions) if err != nil { - log.Printf("[DEBUG] CreateWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("CreateWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceCreate CreateWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId(*workspaceResponse.ID) @@ -1077,7 +1081,9 @@ func resourceIBMSchematicsWorkspaceMapToWorkspaceStatusUpdateRequest(workspaceSt func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1095,43 +1101,61 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou d.SetId("") return nil } - log.Printf("[DEBUG] GetWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("GetWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead GetWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.AppliedShareddataIds != nil { if err = d.Set("applied_shareddata_ids", workspaceResponse.AppliedShareddataIds); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting applied_shareddata_ids: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.CatalogRef != nil { catalogRefMap := resourceIBMSchematicsWorkspaceCatalogRefToMap(*workspaceResponse.CatalogRef) if err = d.Set("catalog_ref", []map[string]interface{}{catalogRefMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting catalog_ref: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("description", workspaceResponse.Description); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting description: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("location", workspaceResponse.Location); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting location: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("name", workspaceResponse.Name); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("resource_group", workspaceResponse.ResourceGroup); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting resource_group: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if _, ok := d.GetOk("shared_data"); ok { if workspaceResponse.SharedData != nil { sharedDataMap := resourceIBMSchematicsWorkspaceSharedTargetDataResponseToMap(*workspaceResponse.SharedData) if err = d.Set("shared_data", []map[string]interface{}{sharedDataMap}); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading shared_data: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } } if workspaceResponse.Tags != nil { if err = d.Set("tags", workspaceResponse.Tags); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting tags: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.TemplateData != nil { @@ -1141,53 +1165,83 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou templateData = append(templateData, templateDataItemMap) } if err = d.Set("template_env_settings", templateData[0]["env_values"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading env_values: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_folder", templateData[0]["folder"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading folder: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_init_state_file", templateData[0]["init_state_file"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading init_state_file: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_type", templateData[0]["type"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading type: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_uninstall_script_name", templateData[0]["uninstall_script_name"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading uninstall_script_name: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_values", templateData[0]["values"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading values: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } 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)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_inputs", templateData[0]["variablestore"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading variablestore: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("template_ref", workspaceResponse.TemplateRef); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting template_ref: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.TemplateRepo != nil { templateRepoMap := resourceIBMSchematicsWorkspaceTemplateRepoResponseToMap(*workspaceResponse.TemplateRepo) if err = d.Set("template_git_branch", templateRepoMap["branch"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading branch: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_release", templateRepoMap["release"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading release: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_repo_sha_value", templateRepoMap["repo_sha_value"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading repo_sha_value: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_repo_url", templateRepoMap["repo_url"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading repo_url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_url", templateRepoMap["url"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading url: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("template_git_has_uploadedgitrepotar", templateRepoMap["has_uploadedgitrepotar"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading has_uploadedgitrepotar: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } /*if workspaceResponse.Type != nil { @@ -1198,38 +1252,58 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou if workspaceResponse.WorkspaceStatus != nil { workspaceStatusMap := resourceIBMSchematicsWorkspaceWorkspaceStatusResponseToMap(*workspaceResponse.WorkspaceStatus) if err = d.Set("frozen", workspaceStatusMap["frozen"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("frozen_at", workspaceStatusMap["frozen_at"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("frozen_by", workspaceStatusMap["frozen_by"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading frozen_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked", workspaceStatusMap["locked"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked_by", workspaceStatusMap["locked_by"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("locked_time", workspaceStatusMap["locked_time"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading locked_time: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.CreatedAt != nil { if err = d.Set("created_at", workspaceResponse.CreatedAt.String()); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading created_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("created_by", workspaceResponse.CreatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting created_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("crn", workspaceResponse.Crn); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading crn: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.LastHealthCheckAt != nil { if err = d.Set("last_health_check_at", workspaceResponse.LastHealthCheckAt.String()); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading last_health_check_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if workspaceResponse.RuntimeData != nil { @@ -1239,27 +1313,39 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou runtimeData = append(runtimeData, runtimeDataItemMap) } if err = d.Set("runtime_data", runtimeData); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting runtime_data: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("status", workspaceResponse.Status); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting status: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.UpdatedAt != nil { if err = d.Set("updated_at", workspaceResponse.UpdatedAt.String()); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading updated_at: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if err = d.Set("updated_by", workspaceResponse.UpdatedBy); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error setting updated_by: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if workspaceResponse.WorkspaceStatusMsg != nil { workspaceStatusMsgMap := resourceIBMSchematicsWorkspaceWorkspaceStatusMessageToMap(*workspaceResponse.WorkspaceStatusMsg) if err = d.Set("status_code", workspaceStatusMsgMap["status_code"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading status_code: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } if err = d.Set("status_msg", workspaceStatusMsgMap["status_msg"]); err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error reading status_msg: %s", err)) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceRead failed with error: %s", err), "ibm_schematics_workspace", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -1624,7 +1710,9 @@ func resourceIBMSchematicsWorkspaceWorkspaceStatusMessageToMap(workspaceStatusMe func resourceIBMSchematicsWorkspaceUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceUpdate schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1814,16 +1902,20 @@ func resourceIBMSchematicsWorkspaceUpdate(context context.Context, d *schema.Res changed = true _, response, err := schematicsClient.ReplaceWorkspaceWithContext(context, replaceWorkspaceOptions) if err != nil { - log.Printf("[DEBUG] ReplaceWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceUpdate ReplaceWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } if !changed && metadataChange { _, response, err := schematicsClient.UpdateWorkspaceWithContext(context, updateWorkspaceOptions) if err != nil { - log.Printf("[DEBUG] UpdateWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("UpdateWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceUpdate UpdateWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } @@ -1849,8 +1941,10 @@ func resourceIBMSchematicsWorkspaceUpdate(context context.Context, d *schema.Res _, response, err := schematicsClient.ReplaceWorkspaceInputs(replaceWorkspaceInputsOptions) if err != nil { - log.Printf("[DEBUG] ReplaceWorkspaceInputs failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("ReplaceWorkspaceInputs failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceUpdate ReplaceWorkspaceInputs failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } } } @@ -1863,12 +1957,16 @@ func resourceIBMSchematicsWorkspaceUpdate(context context.Context, d *schema.Res func resourceIBMSchematicsWorkspaceDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { schematicsClient, err := meta.(conns.ClientSession).SchematicsV1() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceDelete schematicsClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } session, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return diag.FromErr(err) + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceDelete bluemixClient initialization failed: %s", err.Error()), "ibm_schematics_workspace", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } actionIDSplit := strings.Split(d.Id(), ".") region := actionIDSplit[0] @@ -1885,8 +1983,10 @@ func resourceIBMSchematicsWorkspaceDelete(context context.Context, d *schema.Res _, response, err := schematicsClient.DeleteWorkspaceWithContext(context, deleteWorkspaceOptions) if err != nil { - log.Printf("[DEBUG] DeleteWorkspaceWithContext failed %s\n%s", err, response) - return diag.FromErr(fmt.Errorf("DeleteWorkspaceWithContext failed %s\n%s", err, response)) + + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("resourceIBMSchematicsWorkspaceDelete DeleteWorkspaceWithContext failed with error: %s and response:\n%s", err, response), "ibm_schematics_workspace", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() } d.SetId("")