diff --git a/ibm/conns/config.go b/ibm/conns/config.go index f6d6d10491d..3edf7b3d5bf 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -653,7 +653,11 @@ func (session clientSession) ContainerRegistryV1() (*containerregistryv1.Contain // SchematicsAPI provides schematics Service APIs ... func (sess clientSession) SchematicsV1() (*schematicsv1.SchematicsV1, error) { - return sess.schematicsClient, sess.schematicsClientErr + if sess.schematicsClientErr != nil { + return sess.schematicsClient, sess.schematicsClientErr + } + return sess.schematicsClient.Clone(), nil + // return sess.schematicsClient, sess.schematicsClientErr } // FunctionClient ... diff --git a/ibm/service/schematics/data_source_ibm_schematics_action.go b/ibm/service/schematics/data_source_ibm_schematics_action.go index dcfdd5320a7..ad97052fa15 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_action.go +++ b/ibm/service/schematics/data_source_ibm_schematics_action.go @@ -26,11 +26,6 @@ func DataSourceIBMSchematicsAction() *schema.Resource { Required: true, Description: "Action Id. Use GET /actions API to look up the Action Ids in your IBM Cloud account.", }, - "region": { - Type: schema.TypeString, - Optional: true, - Description: "The Region of the workspace.", - }, "name": { Type: schema.TypeString, Computed: true, @@ -43,6 +38,7 @@ func DataSourceIBMSchematicsAction() *schema.Resource { }, "location": { Type: schema.TypeString, + Optional: true, Computed: true, Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -953,10 +949,12 @@ func dataSourceIBMSchematicsActionRead(context context.Context, d *schema.Resour if err != nil { return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getActionOptions := &schematicsv1.GetActionOptions{} diff --git a/ibm/service/schematics/data_source_ibm_schematics_inventory.go b/ibm/service/schematics/data_source_ibm_schematics_inventory.go index c2778d665b7..bbd7746e250 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_inventory.go +++ b/ibm/service/schematics/data_source_ibm_schematics_inventory.go @@ -26,11 +26,6 @@ func DataSourceIBMSchematicsInventory() *schema.Resource { Required: true, Description: "Resource Inventory Id. Use `GET /v2/inventories` API to look up the Resource Inventory definition Ids in your IBM Cloud account.", }, - "region": { - Type: schema.TypeString, - Optional: true, - Description: "The Region of the workspace.", - }, "name": { Type: schema.TypeString, Computed: true, @@ -48,6 +43,7 @@ func DataSourceIBMSchematicsInventory() *schema.Resource { }, "location": { Type: schema.TypeString, + Optional: true, Computed: true, Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -98,10 +94,12 @@ func dataSourceIBMSchematicsInventoryRead(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getInventoryOptions := &schematicsv1.GetInventoryOptions{} diff --git a/ibm/service/schematics/data_source_ibm_schematics_job.go b/ibm/service/schematics/data_source_ibm_schematics_job.go index ba5706a2868..64f35170d57 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_job.go +++ b/ibm/service/schematics/data_source_ibm_schematics_job.go @@ -26,11 +26,6 @@ func DataSourceIBMSchematicsJob() *schema.Resource { Required: true, Description: "Job Id. Use `GET /v2/jobs` API to look up the Job Ids in your IBM Cloud account.", }, - "region": { - Type: schema.TypeString, - Optional: true, - Description: "The Region of the workspace.", - }, "command_object": { Type: schema.TypeString, Computed: true, @@ -322,6 +317,7 @@ func DataSourceIBMSchematicsJob() *schema.Resource { }, "location": { Type: schema.TypeString, + Optional: true, Computed: true, Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -2822,10 +2818,12 @@ func dataSourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceD if err != nil { return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getJobOptions := &schematicsv1.GetJobOptions{} diff --git a/ibm/service/schematics/data_source_ibm_schematics_output.go b/ibm/service/schematics/data_source_ibm_schematics_output.go index af93d573912..e3b4949aaa5 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_output.go +++ b/ibm/service/schematics/data_source_ibm_schematics_output.go @@ -25,7 +25,7 @@ func DataSourceIBMSchematicsOutput() *schema.Resource { Required: true, Description: "The ID of the workspace for which you want to retrieve output values. To find the workspace ID, use the `GET /workspaces` API.", }, - "region": { + "location": { Type: schema.TypeString, Optional: true, Description: "The Region of the workspace.", @@ -62,10 +62,12 @@ func dataSourceIBMSchematicsOutputRead(d *schema.ResourceData, meta interface{}) workspaceID := d.Get("workspace_id").(string) templateID := d.Get("template_id").(string) - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getWorkspaceOutputsOptions := &schematicsv1.GetWorkspaceOutputsOptions{} 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 cd9dfe7aaa0..d9625ba9810 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_resource_query.go +++ b/ibm/service/schematics/data_source_ibm_schematics_resource_query.go @@ -26,7 +26,7 @@ func DataSourceIBMSchematicsResourceQuery() *schema.Resource { Required: true, Description: "Resource query Id. Use `GET /v2/resource_query` API to look up the Resource query definition Ids in your IBM Cloud account.", }, - "region": { + "location": { Type: schema.TypeString, Optional: true, Description: "The Region of the workspace.", @@ -120,10 +120,12 @@ func dataSourceIBMSchematicsResourceQueryRead(context context.Context, d *schema return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getResourcesQueryOptions := &schematicsv1.GetResourcesQueryOptions{} diff --git a/ibm/service/schematics/data_source_ibm_schematics_state.go b/ibm/service/schematics/data_source_ibm_schematics_state.go index b9a160529a2..c66d1145ce9 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_state.go +++ b/ibm/service/schematics/data_source_ibm_schematics_state.go @@ -29,7 +29,7 @@ func DataSourceIBMSchematicsState() *schema.Resource { Required: true, Description: "The ID of the workspace for which you want to retrieve the Terraform statefile URL. To find the workspace ID, use the GET /v1/workspaces API.", }, - "region": { + "location": { Type: schema.TypeString, Optional: true, Description: "The Region of the workspace.", @@ -61,10 +61,12 @@ func dataSourceIBMSchematicsStateRead(context context.Context, d *schema.Resourc if err != nil { return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getWorkspaceTemplateStateOptions := &schematicsv1.GetWorkspaceTemplateStateOptions{} diff --git a/ibm/service/schematics/data_source_ibm_schematics_workspace.go b/ibm/service/schematics/data_source_ibm_schematics_workspace.go index a5b65b21238..c523e18bb03 100644 --- a/ibm/service/schematics/data_source_ibm_schematics_workspace.go +++ b/ibm/service/schematics/data_source_ibm_schematics_workspace.go @@ -26,11 +26,6 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource { Required: true, Description: "The ID of the workspace. To find the workspace ID, use the `GET /v1/workspaces` API.", }, - "region": { - Type: schema.TypeString, - Optional: true, - Description: "The Region of the workspace.", - }, "applied_shareddata_ids": { Type: schema.TypeList, Computed: true, @@ -120,6 +115,7 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource { }, "location": { Type: schema.TypeString, + Optional: true, Computed: true, Description: "The IBM Cloud location where your workspace was provisioned.", }, @@ -560,20 +556,23 @@ func DataSourceIBMSchematicsWorkspace() *schema.Resource { } } -func SchematicsEndpointURL(region, meta interface{}) (string, error) { +func SchematicsEndpointURL(region, meta interface{}) (string, bool, error) { sess, err := meta.(conns.ClientSession).BluemixSession() if err != nil { - return "", err - } - // overide provider region with resource/datasource region argument - // update client with updated region endpoint - schematicsEndpoint := fmt.Sprintf("https://%s.%s", fmt.Sprintf("%s.schematics", region), "cloud.ibm.com") - visibility := sess.Config.Visibility - if visibility == "private" || visibility == "public-and-private" { - schematicsEndpoint = fmt.Sprintf("https://%s.%s", fmt.Sprintf("private-%s.schematics", region), "cloud.ibm.com") + return "", false, err + } + if region != sess.Config.Region { + // overide provider region with resource/datasource region argument + // update client with updated region endpoint + schematicsEndpoint := fmt.Sprintf("https://%s.%s", fmt.Sprintf("%s.schematics", region), "cloud.ibm.com") + visibility := sess.Config.Visibility + if visibility == "private" || visibility == "public-and-private" { + schematicsEndpoint = fmt.Sprintf("https://%s.%s", fmt.Sprintf("private-%s.schematics", region), "cloud.ibm.com") + } + schematicsEndpointURL := conns.EnvFallBack([]string{"IBMCLOUD_SCHEMATICS_API_ENDPOINT"}, schematicsEndpoint) + return schematicsEndpointURL, true, nil } - schematicsEndpointURL := conns.EnvFallBack([]string{"IBMCLOUD_SCHEMATICS_API_ENDPOINT"}, schematicsEndpoint) - return schematicsEndpointURL, nil + return "", false, nil } func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { @@ -581,10 +580,12 @@ func dataSourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - if r, ok := d.GetOk("region"); ok { + if r, ok := d.GetOk("location"); ok { region := r.(string) - schematicsURL, _ := SchematicsEndpointURL(region, meta) - schematicsClient.Service.Options.URL = schematicsURL + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } } getWorkspaceOptions := &schematicsv1.GetWorkspaceOptions{} diff --git a/ibm/service/schematics/resource_ibm_schematics_action.go b/ibm/service/schematics/resource_ibm_schematics_action.go index 3bebb5da79d..5b7efef5f50 100644 --- a/ibm/service/schematics/resource_ibm_schematics_action.go +++ b/ibm/service/schematics/resource_ibm_schematics_action.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -47,6 +48,7 @@ func ResourceIBMSchematicsAction() *schema.Resource { "location": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validate.InvokeValidator("ibm_schematics_action", "location"), Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -979,7 +981,13 @@ func resourceIBMSchematicsActionCreate(context context.Context, d *schema.Resour if err != nil { return diag.FromErr(err) } - + if r, ok := d.GetOk("location"); ok { + region := r.(string) + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } + } createActionOptions := &schematicsv1.CreateActionOptions{} if _, ok := d.GetOk("name"); ok { @@ -1337,7 +1345,12 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } getActionOptions := &schematicsv1.GetActionOptions{} getActionOptions.SetActionID(d.Id()) @@ -1351,7 +1364,6 @@ func resourceIBMSchematicsActionRead(context context.Context, d *schema.Resource log.Printf("[DEBUG] GetActionWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetActionWithContext failed %s\n%s", err, response)) } - if err = d.Set("name", action.Name); err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) } @@ -1781,6 +1793,12 @@ func resourceIBMSchematicsActionUpdate(context context.Context, d *schema.Resour if err != nil { return diag.FromErr(err) } + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } updateActionOptions := &schematicsv1.UpdateActionOptions{} @@ -1928,7 +1946,12 @@ func resourceIBMSchematicsActionDelete(context context.Context, d *schema.Resour if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } deleteActionOptions := &schematicsv1.DeleteActionOptions{} deleteActionOptions.SetActionID(d.Id()) diff --git a/ibm/service/schematics/resource_ibm_schematics_inventory.go b/ibm/service/schematics/resource_ibm_schematics_inventory.go index 668755f415f..77b7e70630b 100644 --- a/ibm/service/schematics/resource_ibm_schematics_inventory.go +++ b/ibm/service/schematics/resource_ibm_schematics_inventory.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -40,6 +41,7 @@ func ResourceIBMSchematicsInventory() *schema.Resource { "location": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validate.InvokeValidator("ibm_schematics_inventory", "location"), Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -112,7 +114,13 @@ func resourceIBMSchematicsInventoryCreate(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - + if r, ok := d.GetOk("location"); ok { + region := r.(string) + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } + } createInventoryOptions := &schematicsv1.CreateInventoryOptions{} if _, ok := d.GetOk("name"); ok { @@ -150,6 +158,12 @@ func resourceIBMSchematicsInventoryRead(context context.Context, d *schema.Resou if err != nil { return diag.FromErr(err) } + inventoryIDSplit := strings.Split(d.Id(), ".") + region := inventoryIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } getInventoryOptions := &schematicsv1.GetInventoryOptions{} @@ -164,7 +178,6 @@ func resourceIBMSchematicsInventoryRead(context context.Context, d *schema.Resou log.Printf("[DEBUG] GetInventoryWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetInventoryWithContext failed %s\n%s", err, response)) } - if err = d.Set("name", inventoryResourceRecord.Name); err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error setting name: %s", err)) } @@ -207,6 +220,12 @@ func resourceIBMSchematicsInventoryUpdate(context context.Context, d *schema.Res return diag.FromErr(err) } + inventoryIDSplit := strings.Split(d.Id(), ".") + region := inventoryIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } updateInventoryOptions := &schematicsv1.ReplaceInventoryOptions{} updateInventoryOptions.SetInventoryID(d.Id()) @@ -259,7 +278,12 @@ func resourceIBMSchematicsInventoryDelete(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - + inventoryIDSplit := strings.Split(d.Id(), ".") + region := inventoryIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } deleteInventoryOptions := &schematicsv1.DeleteInventoryOptions{} deleteInventoryOptions.SetInventoryID(d.Id()) diff --git a/ibm/service/schematics/resource_ibm_schematics_job.go b/ibm/service/schematics/resource_ibm_schematics_job.go index 00d6c1299a5..30f44578f69 100644 --- a/ibm/service/schematics/resource_ibm_schematics_job.go +++ b/ibm/service/schematics/resource_ibm_schematics_job.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -297,6 +298,7 @@ func ResourceIBMSchematicsJob() *schema.Resource { "location": { Type: schema.TypeString, Optional: true, + Computed: true, ValidateFunc: validate.InvokeValidator("ibm_schematics_job", "location"), Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", }, @@ -2856,6 +2858,13 @@ func resourceIBMSchematicsJobCreate(context context.Context, d *schema.ResourceD iamRefreshToken := session.Config.IAMRefreshToken + if r, ok := d.GetOk("location"); ok { + region := r.(string) + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } + } createJobOptions := &schematicsv1.CreateJobOptions{} createJobOptions.SetRefreshToken(iamRefreshToken) @@ -3896,7 +3905,12 @@ func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceDat if err != nil { return diag.FromErr(err) } - + jobIDSplit := strings.Split(d.Id(), ".") + region := jobIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } getJobOptions := &schematicsv1.GetJobOptions{} getJobOptions.SetJobID(d.Id()) @@ -3910,7 +3924,6 @@ func resourceIBMSchematicsJobRead(context context.Context, d *schema.ResourceDat log.Printf("[DEBUG] GetJobWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetJobWithContext failed %s\n%s", err, response)) } - if err = d.Set("command_object", job.CommandObject); err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error setting command_object: %s", err)) } @@ -4967,7 +4980,12 @@ func resourceIBMSchematicsJobUpdate(context context.Context, d *schema.ResourceD } iamRefreshToken := session.Config.IAMRefreshToken - + jobIDSplit := strings.Split(d.Id(), ".") + region := jobIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } updateJobOptions := &schematicsv1.UpdateJobOptions{} updateJobOptions.SetJobID(d.Id()) @@ -5061,7 +5079,12 @@ func resourceIBMSchematicsJobDelete(context context.Context, d *schema.ResourceD if err != nil { return diag.FromErr(err) } - + jobIDSplit := strings.Split(d.Id(), ".") + region := jobIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } deleteJobOptions := &schematicsv1.DeleteJobOptions{} iamRefreshToken := session.Config.IAMRefreshToken diff --git a/ibm/service/schematics/resource_ibm_schematics_resource_query.go b/ibm/service/schematics/resource_ibm_schematics_resource_query.go index 1977cd9e86f..49f783c15f5 100644 --- a/ibm/service/schematics/resource_ibm_schematics_resource_query.go +++ b/ibm/service/schematics/resource_ibm_schematics_resource_query.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -38,6 +39,13 @@ func ResourceIBMSchematicsResourceQuery() *schema.Resource { Optional: true, Description: "Resource query name.", }, + "location": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validate.InvokeValidator("ibm_schematics_resource_query", "location"), + Description: "List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics.", + }, "queries": { Type: schema.TypeList, Optional: true, @@ -114,7 +122,13 @@ func ResourceIBMSchematicsResourceQueryValidator() *validate.ResourceValidator { Optional: true, AllowedValues: "vsi", }, - ) + validate.ValidateSchema{ + Identifier: "location", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Optional: true, + AllowedValues: "us, eu, eu-de, eu-gb, us-east, us-south", + }) resourceValidator := validate.ResourceValidator{ResourceName: "ibm_schematics_resource_query", Schema: validateSchema} return &resourceValidator @@ -125,7 +139,13 @@ func resourceIBMSchematicsResourceQueryCreate(context context.Context, d *schema if err != nil { return diag.FromErr(err) } - + if r, ok := d.GetOk("location"); ok { + region := r.(string) + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } + } createResourceQueryOptions := &schematicsv1.CreateResourceQueryOptions{} if _, ok := d.GetOk("type"); ok { @@ -201,7 +221,12 @@ func resourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.R if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } getResourcesQueryOptions := &schematicsv1.GetResourcesQueryOptions{} getResourcesQueryOptions.SetQueryID(d.Id()) @@ -215,7 +240,6 @@ func resourceIBMSchematicsResourceQueryRead(context context.Context, d *schema.R log.Printf("[DEBUG] GetResourcesQueryWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetResourcesQueryWithContext failed %s\n%s", err, response)) } - if err = d.Set("type", resourceQueryRecord.Type); err != nil { return diag.FromErr(fmt.Errorf("[ERROR] Error setting type: %s", err)) } @@ -291,7 +315,12 @@ func resourceIBMSchematicsResourceQueryUpdate(context context.Context, d *schema if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } replaceResourcesQueryOptions := &schematicsv1.ReplaceResourcesQueryOptions{} replaceResourcesQueryOptions.SetQueryID(d.Id()) @@ -325,7 +354,12 @@ func resourceIBMSchematicsResourceQueryDelete(context context.Context, d *schema if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } deleteResourcesQueryOptions := &schematicsv1.DeleteResourcesQueryOptions{} deleteResourcesQueryOptions.SetQueryID(d.Id()) diff --git a/ibm/service/schematics/resource_ibm_schematics_workspace.go b/ibm/service/schematics/resource_ibm_schematics_workspace.go index b080233a319..c190dcb38b0 100644 --- a/ibm/service/schematics/resource_ibm_schematics_workspace.go +++ b/ibm/service/schematics/resource_ibm_schematics_workspace.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "log" + "strings" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" @@ -105,6 +106,7 @@ func ResourceIBMSchematicsWorkspace() *schema.Resource { "location": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "The location where you want to create your Schematics workspace and run the Schematics jobs. The location that you enter must match the API endpoint that you use. For example, if you use the Frankfurt API endpoint, you must specify `eu-de` as your location. If you use an API endpoint for a geography and you do not specify a location, Schematics determines the location based on availability.", }, "name": { @@ -483,7 +485,13 @@ func resourceIBMSchematicsWorkspaceCreate(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - + if r, ok := d.GetOk("location"); ok { + region := r.(string) + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } + } createWorkspaceOptions := &schematicsv1.CreateWorkspaceOptions{} if _, ok := d.GetOk("applied_shareddata_ids"); ok { @@ -899,7 +907,12 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } getWorkspaceOptions := &schematicsv1.GetWorkspaceOptions{} getWorkspaceOptions.SetWID(d.Id()) @@ -913,7 +926,6 @@ func resourceIBMSchematicsWorkspaceRead(context context.Context, d *schema.Resou log.Printf("[DEBUG] GetWorkspaceWithContext failed %s\n%s", err, response) return diag.FromErr(fmt.Errorf("GetWorkspaceWithContext failed %s\n%s", err, response)) } - 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)) @@ -1435,7 +1447,12 @@ func resourceIBMSchematicsWorkspaceUpdate(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } updateWorkspaceOptions := &schematicsv1.UpdateWorkspaceOptions{} replaceWorkspaceOptions := &schematicsv1.ReplaceWorkspaceOptions{} @@ -1674,7 +1691,12 @@ func resourceIBMSchematicsWorkspaceDelete(context context.Context, d *schema.Res if err != nil { return diag.FromErr(err) } - + actionIDSplit := strings.Split(d.Id(), ".") + region := actionIDSplit[0] + schematicsURL, updatedURL, _ := SchematicsEndpointURL(region, meta) + if updatedURL { + schematicsClient.Service.Options.URL = schematicsURL + } deleteWorkspaceOptions := &schematicsv1.DeleteWorkspaceOptions{} deleteWorkspaceOptions.SetWID(d.Id()) diff --git a/website/docs/d/schematics_action.html.markdown b/website/docs/d/schematics_action.html.markdown index 9ce97637587..699f820ebe7 100644 --- a/website/docs/d/schematics_action.html.markdown +++ b/website/docs/d/schematics_action.html.markdown @@ -23,6 +23,9 @@ Review the argument references that you can specify for your data source. - `action_id` - (Required, String) Action Id. Use GET /actions API to look up the Action Ids in your IBM Cloud account. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de + ## Attribute reference In addition to the argument reference list, you can access the following attribute references after your data source is created. @@ -146,9 +149,6 @@ Nested scheme for **credentials**: * `inventory` - (String) Target inventory record ID, used by the action or ansible playbook. -* `location` - (String) List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. - * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de - * `name` - (String) The unique name of your action. The name can be up to 128 characters long and can include alphanumeric characters, spaces, dashes, and underscores. **Example** you can use the name to stop action. * `playbook_names` - (List) Playbook names retrieved from the respository. diff --git a/website/docs/d/schematics_inventory.html.markdown b/website/docs/d/schematics_inventory.html.markdown index 75ddda40239..0192567d233 100644 --- a/website/docs/d/schematics_inventory.html.markdown +++ b/website/docs/d/schematics_inventory.html.markdown @@ -25,6 +25,9 @@ Review the argument reference that you can specify for your data source. - `inventory_id` - (Required, String) Resource Inventory Id. Use `GET /v2/inventories` API to look up the Resource Inventory definition Ids in your IBM Cloud account. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de + ## Attribute reference In addition to all argument references listed, you can access the following attribute references after your data source is created. @@ -34,8 +37,6 @@ In addition to all argument references listed, you can access the following attr - `description` - (String) The description of your inventory. The description can be up to `2048` characters long in size. - `id` - (String) The inventory ID. - `inventories_ini` - (String) Input inventory of host and host group for the playbook, in the .ini file format. -- `location` - (String) List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. **Note*- this does not limit the location of the IBM Cloud resources, provisioned using Schematics. - - Constraints: Allowable values are: `us-south`, `us-east`, `eu-gb`, `eu-de` - `name` - (String) The unique name of your Inventory. The name can be up to 128 characters long and can include alphanumeric characters, spaces, dashes, and underscores. - `resource_group` - (String) The resource group name for the inventory definition. By default, inventory will be created in Default Resource Group. - `resource_queries` - (List) Input resource queries that is used to dynamically generate the inventory of host and host group for the playbook. diff --git a/website/docs/d/schematics_job.html.markdown b/website/docs/d/schematics_job.html.markdown index 165ea5ca715..5b3bee4d699 100644 --- a/website/docs/d/schematics_job.html.markdown +++ b/website/docs/d/schematics_job.html.markdown @@ -23,6 +23,9 @@ Review the argument reference that you can specify for your data source. * `job_id` - (String) Job Id. Use `GET /v2/jobs` API to look up the Job Ids in your IBM Cloud account. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de + ## Attribute reference In addition to all argument references listed, you can access the following attribute references after your data source is created. @@ -477,8 +480,6 @@ Nested scheme for **job_inputs**: * `source` - (String) Source of this meta-data. * `link` - (String) Reference link to the variable value By default the expression will point to self.value. -* `location` - (String) List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. - * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de * `log_store_url` - (String) Job log store URL. diff --git a/website/docs/d/schematics_output.html.markdown b/website/docs/d/schematics_output.html.markdown index cbc3fff906f..693e7b6efcf 100644 --- a/website/docs/d/schematics_output.html.markdown +++ b/website/docs/d/schematics_output.html.markdown @@ -36,6 +36,8 @@ Review the argument references that you can specify for your data source. - `workspace_id` - (Required, String) The ID of the workspace for which you want to retrieve output values. To find the workspace ID, use the `GET /workspaces` API. - `template_id` - (Required, String) The ID of the template - `output_json` - (Optional, String) The json output in string +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. diff --git a/website/docs/d/schematics_resource_query.html.markdown b/website/docs/d/schematics_resource_query.html.markdown index 0ed4a76655e..3f5b55df46e 100644 --- a/website/docs/d/schematics_resource_query.html.markdown +++ b/website/docs/d/schematics_resource_query.html.markdown @@ -24,6 +24,8 @@ data "ibm_schematics_resource_query" "schematics_resource_query" { Review the argument reference that you can specify for your data source. - `query_id` - (Required, String) Resource query ID. Use `GET /v2/resource_query` API to look up the Resource query definition Ids in your IBM Cloud account. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de ## Attribute reference diff --git a/website/docs/d/schematics_state.html.markdown b/website/docs/d/schematics_state.html.markdown index 251c4fbde91..d73a40c44d4 100644 --- a/website/docs/d/schematics_state.html.markdown +++ b/website/docs/d/schematics_state.html.markdown @@ -23,9 +23,12 @@ data "ibm_schematics_state" "schematics_state" { ## Argument reference Review the argument references that you can specify for your data source. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de - `template_id` - (Required, String) The ID of the Terraform template for which you want to retrieve the Terraform statefile. When you create a workspace, the Terraform template that your workspace points to is assigned a unique ID. To find this ID, use the `GET /v1/workspaces` API and review the `template_data.id` value. - `workspace_id` - (Required, String) The workspace ID for which you want to retrieve the Terraform statefile. To find the workspace ID, use the `GET /v1/workspaces` API. + ## Attribute reference In addition to all argument reference list, you can access the following attribute references after your data source is created. diff --git a/website/docs/d/schematics_workspace.html.markdown b/website/docs/d/schematics_workspace.html.markdown index 89cf9bca917..7b5e7aa29cb 100644 --- a/website/docs/d/schematics_workspace.html.markdown +++ b/website/docs/d/schematics_workspace.html.markdown @@ -23,7 +23,8 @@ data "ibm_schematics_workspace" "schematics_workspace" { Review the argument reference that you can specify for your data source. -* `region` - (Optional, String) The region of the workspace. +* `location` - (Optional,String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. + * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de * `workspace_id` - (Required, Forces new resource, String) The ID of the workspace. To find the workspace ID, use the `GET /v1/workspaces` API. @@ -57,8 +58,6 @@ Nested scheme for **catalog_ref**: * `last_health_check_at` - (String) The timestamp when the last health check was performed by Schematics. -* `location` - (String) The IBM Cloud location where your workspace was provisioned. - * `name` - (String) The name of the workspace. * `resource_group` - (String) The resource group the workspace was provisioned in. diff --git a/website/docs/r/schematics_action.html.markdown b/website/docs/r/schematics_action.html.markdown index dc95dae3aaf..d9969b1d1f9 100644 --- a/website/docs/r/schematics_action.html.markdown +++ b/website/docs/r/schematics_action.html.markdown @@ -128,7 +128,7 @@ Nested scheme for **credentials**: * `link` - (Optional, String) Reference link to the variable value By default the expression will point to self.value. * `description` - (Optional, String) Action description. * `inventory` - (Optional, String) Target inventory record ID, used by the action or ansible playbook. -* `location` - (Optional, String) List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. +* `location` - (Optional, String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de * `name` - (Required, String) The unique name of your action. The name can be up to 128 characters long and can include alphanumeric characters, spaces, dashes, and underscores. **Example** you can use the name to stop action. * `resource_group` - (Optional, String) Resource-group name for an action. By default, action is created in default resource group. diff --git a/website/docs/r/schematics_job.html.markdown b/website/docs/r/schematics_job.html.markdown index eb4a64fd133..49c20e61db3 100644 --- a/website/docs/r/schematics_job.html.markdown +++ b/website/docs/r/schematics_job.html.markdown @@ -458,7 +458,7 @@ Nested scheme for **job_inputs**: * `group_by` - (Optional, String) Display name of the group this variable belongs to. * `source` - (Optional, String) Source of this meta-data. * `link` - (Optional, String) Reference link to the variable value By default the expression will point to self.value. -* `location` - (Optional, String) List of locations supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. +* `location` - (Optional, String) Location supported by IBM Cloud Schematics service. While creating your workspace or action, choose the right region, since it cannot be changed. Note, this does not limit the location of the IBM Cloud resources, provisioned using Schematics. * Constraints: Allowable values are: us-south, us-east, eu-gb, eu-de * `log_summary` - (Optional, List) Job log summary record. Nested scheme for **log_summary**: diff --git a/website/docs/r/schematics_resource_query.html.markdown b/website/docs/r/schematics_resource_query.html.markdown index a27932da69e..8432dd4c67b 100644 --- a/website/docs/r/schematics_resource_query.html.markdown +++ b/website/docs/r/schematics_resource_query.html.markdown @@ -22,6 +22,7 @@ resource "ibm_schematics_resource_query" "schematics_resource_query" { Review the argument reference that you can specify for your resource. - `name` - (Optional, String) Resource query name. +* `location` - (Optional, ForceNew String, String) The region of the workspace. - `queries` - (Optional, List) Nested scheme for **queries**: - `query_type` - (Optional, String) Type of the query(workspaces).