diff --git a/ibm/conns/config.go b/ibm/conns/config.go index bec357e470..7fa2eba601 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -135,6 +135,7 @@ import ( "github.com/IBM/platform-services-go-sdk/partnercentersellv1" scc "github.com/IBM/scc-go-sdk/v5/securityandcompliancecenterapiv3" "github.com/IBM/secrets-manager-go-sdk/v2/secretsmanagerv2" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" ) // RetryAPIDelay - retry api delay @@ -327,6 +328,7 @@ type ClientSession interface { VmwareV1() (*vmwarev1.VmwareV1, error) LogsV0() (*logsv0.LogsV0, error) SdsaasV1() (*sdsaasv1.SdsaasV1, error) + DrAutomationServiceV1() (*drautomationservicev1.DrAutomationServiceV1, error) } type clientSession struct { @@ -701,6 +703,10 @@ type clientSession struct { // Global Catalog Management Option globalCatalogClient *globalcatalogv1.GlobalCatalogV1 globalCatalogClientErr error + + // DR Automation + drAutomationServiceClient *drautomationservicev1.DrAutomationServiceV1 + drAutomationServiceClientErr error } // Usage Reports @@ -1044,6 +1050,11 @@ func (sess clientSession) CisSSLClientSession() (*cissslv1.SslCertificateApiV1, return sess.cisSSLClient.Clone(), nil } +// DrAutomation Service +func (session clientSession) DrAutomationServiceV1() (*drautomationservicev1.DrAutomationServiceV1, error) { + return session.drAutomationServiceClient, session.drAutomationServiceClientErr +} + // CIS WAF Packages func (sess clientSession) CisWAFPackageClientSession() (*ciswafpackagev1.WafRulePackagesApiV1, error) { if sess.cisWAFPackageErr != nil { diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index 7f5e66f36e..a891f86b00 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -37,6 +37,7 @@ import ( "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/db2" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/directlink" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/dnsservices" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/enterprise" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/eventnotification" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/eventstreams" @@ -1098,6 +1099,16 @@ func Provider() *schema.Provider { // Logs Router Service "ibm_logs_router_tenants": logsrouting.DataSourceIBMLogsRouterTenants(), "ibm_logs_router_targets": logsrouting.DataSourceIBMLogsRouterTargets(), + + // DR Automation Service + "ibm_pdr_get_dr_summary_response": drautomationservice.DataSourceIBMPdrGetDrSummaryResponse(), + "ibm_pdr_get_powervs_workspace": drautomationservice.DataSourceIBMPdrGetPowervsWorkspace(), + "ibm_pdr_get_event": drautomationservice.DataSourceIBMPdrGetEvent(), + "ibm_pdr_get_events": drautomationservice.DataSourceIBMPdrGetEvents(), + "ibm_pdr_get_dr_locations": drautomationservice.DataSourceIBMPdrGetDrLocations(), + "ibm_pdr_get_machine_types": drautomationservice.DataSourceIBMPdrGetMachineTypes(), + "ibm_pdr_get_managed_vm_list": drautomationservice.DataSourceIBMPdrGetManagedVMList(), + "ibm_pdr_last_operation": drautomationservice.DataSourceIBMPdrLastOperation(), }, ResourcesMap: map[string]*schema.Resource{ @@ -1767,6 +1778,10 @@ func Provider() *schema.Provider { // Logs Router Service "ibm_logs_router_tenant": logsrouting.ResourceIBMLogsRouterTenant(), + + // DR Automation Service + "ibm_pdr_managedr": drautomationservice.ResourceIbmPdrManagedr(), + "ibm_pdr_validate_apikey": drautomationservice.ResourceIBMPdrValidateApikey(), }, ConfigureFunc: providerConfigure, diff --git a/ibm/service/drautomationservice/README.md b/ibm/service/drautomationservice/README.md new file mode 100644 index 0000000000..043be27aa4 --- /dev/null +++ b/ibm/service/drautomationservice/README.md @@ -0,0 +1,11 @@ +# Terraform IBM Provider + +This area is primarily for IBM provider contributors and maintainers. For information on _using_ Terraform and the IBM provider, see the links below. + + +## Handy Links +* [Find out about contributing](../../../CONTRIBUTING.md) to the IBM provider! +* IBM Provider Docs: [Home](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs) +* IBM Provider Docs: [One of the resources](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/pdr_managedr) +* IBM API Docs: [IBM API Docs for ]() +* IBM SDK: [IBM SDK for ](https://github.com/IBM/appconfiguration-go-admin-sdk/tree/master/drautomationservicev1) diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations.go new file mode 100644 index 0000000000..02f7b13019 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations.go @@ -0,0 +1,125 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetDrLocations() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetDrLocationsRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "dr_locations": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of disaster recovery locations available for the service.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Unique identifier of the DR location.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the DR location.", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetDrLocationsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_dr_locations", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getDrLocationsOptions := &drautomationservicev1.GetDrLocationsOptions{} + + getDrLocationsOptions.SetInstanceID(d.Get("instance_id").(string)) + + getDrLocationsResponse, response, err := drAutomationServiceClient.GetDrLocationsWithContext(context, getDrLocationsOptions) + + if err != nil { + detailedMsg := fmt.Sprintf("GetDrLocationsWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetDrLocations failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_dr_locations", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetDrLocationsID(d)) + + if _, ok := d.GetOk("accept_language"); ok { + getDrLocationsOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + + drLocations := []map[string]interface{}{} + for _, drLocationsItem := range getDrLocationsResponse.DrLocations { + drLocationsItemMap, err := DataSourceIBMPdrGetDrLocationsDrLocationToMap(&drLocationsItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_dr_locations", "read", "dr_locations-to-map").GetDiag() + } + drLocations = append(drLocations, drLocationsItemMap) + } + + if err = d.Set("dr_locations", drLocations); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting dr_locations: %s", err), "(Data) ibm_pdr_get_dr_locations", "read", "set-dr_locations").GetDiag() + } + + return nil +} + +// dataSourceIBMPdrGetDrLocationsID returns a reasonable ID for the list. +func dataSourceIBMPdrGetDrLocationsID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func DataSourceIBMPdrGetDrLocationsDrLocationToMap(model *drautomationservicev1.DrLocation) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations_test.go new file mode 100644 index 0000000000..24ca6dc209 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_locations_test.go @@ -0,0 +1,65 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 +*/ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrGetDrLocationsDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetDrLocationsDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_locations.pdr_get_dr_locations_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_locations.pdr_get_dr_locations_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_locations.pdr_get_dr_locations_instance", "dr_locations.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetDrLocationsDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_dr_locations" "pdr_get_dr_locations_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + } + `) +} + + +func TestDataSourceIBMPdrGetDrLocationsDrLocationToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["id"] = "loc123" + model["name"] = "US-East-1" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.DrLocation) + model.ID = core.StringPtr("loc123") + model.Name = core.StringPtr("US-East-1") + + result, err := drautomationservice.DataSourceIBMPdrGetDrLocationsDrLocationToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response.go new file mode 100644 index 0000000000..ff8182714a --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response.go @@ -0,0 +1,367 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetDrSummaryResponse() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetDrSummaryResponseRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "managed_vm_list": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "orchestrator_details": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Contains details about the orchestrator configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "last_updated_orchestrator_deployment_time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Deployment time of primary orchestrator VM.", + }, + "last_updated_standby_orchestrator_deployment_time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Deployment time of StandBy orchestrator VM.", + }, + "latest_orchestrator_time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Latest Orchestrator Time in COS.", + }, + "location_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Location identifier.", + }, + "mfa_enabled": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Multi Factor Authentication Enabled or not.", + }, + "orch_ext_connectivity_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "External connectivity status of the orchestrator.", + }, + "orch_standby_node_addition_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of standby node addition.", + }, + "orchestrator_cluster_message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Message regarding orchestrator cluster status.", + }, + "orchestrator_config_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Configuration status of the orchestrator.", + }, + "orchestrator_group_leader": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Leader node of the orchestrator group.", + }, + "orchestrator_location_type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of orchestrator Location.", + }, + "orchestrator_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the primary orchestrator.", + }, + "orchestrator_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of the primary orchestrator.", + }, + "orchestrator_workspace_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the orchestrator workspace.", + }, + "proxy_ip": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address of the proxy.", + }, + "schematic_workspace_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the schematic workspace.", + }, + "schematic_workspace_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of the schematic workspace.", + }, + "ssh_key_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "SSH key name used for the orchestrator.", + }, + "standby_orchestrator_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the standby orchestrator.", + }, + "standby_orchestrator_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of the standby orchestrator.", + }, + "standby_orchestrator_workspace_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the standby orchestrator workspace.", + }, + "transit_gateway_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the transit gateway.", + }, + "vpc_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the VPC.", + }, + }, + }, + }, + "service_details": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Contains details about the DR automation service.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Cloud Resource Name identifier.", + }, + "deployment_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the deployment.", + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Description of the primary service.", + }, + "is_ksys_ha": &schema.Schema{ + Type: schema.TypeBool, + Computed: true, + Description: "Flag indicating if KSYS HA is enabled.", + }, + "plan_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "plan name.", + }, + "primary_ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address of the primary service.", + }, + "primary_orchestrator_dashboard_url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Primary Orchestrator Dashboard URL.", + }, + "recovery_location": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Location for disaster recovery.", + }, + "resource_group": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Resource group name.", + }, + "standby_description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Description of the standby service.", + }, + "standby_ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address of the standby service.", + }, + "standby_orchestrator_dashboard_url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Standby Orchestrator Dashboard URL.", + }, + "standby_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current status of the standby service.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current status of the primary service.", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetDrSummaryResponseRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_dr_summary_response", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getDrSummaryOptions := &drautomationservicev1.GetDrSummaryOptions{} + + getDrSummaryOptions.SetInstanceID(d.Get("instance_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + getDrSummaryOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + drAutomationGetSummaryResponse, response, err := drAutomationServiceClient.GetDrSummaryWithContext(context, getDrSummaryOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetDrSummaryWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetDrSummaryWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_dr_summary_response", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetDrSummaryResponseID(d)) + + convertedMap := make(map[string]interface{}, len(drAutomationGetSummaryResponse.ManagedVMList)) + for k, v := range drAutomationGetSummaryResponse.ManagedVMList { + convertedMap[k] = v + } + if err = d.Set("managed_vm_list", flex.Flatten(convertedMap)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting managed_vm_list: %s", err), "(Data) ibm_pdr_get_dr_summary_response", "read", "set-managed_vm_list").GetDiag() + } + + orchestratorDetails := []map[string]interface{}{} + orchestratorDetailsMap, err := DataSourceIBMPdrGetDrSummaryResponseOrchestratorDetailsToMap(drAutomationGetSummaryResponse.OrchestratorDetails) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_dr_summary_response", "read", "orchestrator_details-to-map").GetDiag() + } + orchestratorDetails = append(orchestratorDetails, orchestratorDetailsMap) + if err = d.Set("orchestrator_details", orchestratorDetails); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting orchestrator_details: %s", err), "(Data) ibm_pdr_get_dr_summary_response", "read", "set-orchestrator_details").GetDiag() + } + + serviceDetails := []map[string]interface{}{} + serviceDetailsMap, err := DataSourceIBMPdrGetDrSummaryResponseServiceDetailsToMap(drAutomationGetSummaryResponse.ServiceDetails) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_dr_summary_response", "read", "service_details-to-map").GetDiag() + } + serviceDetails = append(serviceDetails, serviceDetailsMap) + if err = d.Set("service_details", serviceDetails); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting service_details: %s", err), "(Data) ibm_pdr_get_dr_summary_response", "read", "set-service_details").GetDiag() + } + + return nil +} + +// dataSourceIBMPdrGetDrSummaryResponseID returns a reasonable ID for the list. +func dataSourceIBMPdrGetDrSummaryResponseID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func DataSourceIBMPdrGetDrSummaryResponseOrchestratorDetailsToMap(model *drautomationservicev1.OrchestratorDetails) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["last_updated_orchestrator_deployment_time"] = model.LastUpdatedOrchestratorDeploymentTime.String() + modelMap["last_updated_standby_orchestrator_deployment_time"] = model.LastUpdatedStandbyOrchestratorDeploymentTime.String() + if model.LatestOrchestratorTime != nil { + modelMap["latest_orchestrator_time"] = model.LatestOrchestratorTime.String() + } + modelMap["location_id"] = *model.LocationID + modelMap["mfa_enabled"] = *model.MfaEnabled + modelMap["orch_ext_connectivity_status"] = *model.OrchExtConnectivityStatus + modelMap["orch_standby_node_addition_status"] = *model.OrchStandbyNodeAdditionStatus + modelMap["orchestrator_cluster_message"] = *model.OrchestratorClusterMessage + modelMap["orchestrator_config_status"] = *model.OrchestratorConfigStatus + modelMap["orchestrator_group_leader"] = *model.OrchestratorGroupLeader + modelMap["orchestrator_location_type"] = *model.OrchestratorLocationType + modelMap["orchestrator_name"] = *model.OrchestratorName + modelMap["orchestrator_status"] = *model.OrchestratorStatus + modelMap["orchestrator_workspace_name"] = *model.OrchestratorWorkspaceName + modelMap["proxy_ip"] = *model.ProxyIP + modelMap["schematic_workspace_name"] = *model.SchematicWorkspaceName + modelMap["schematic_workspace_status"] = *model.SchematicWorkspaceStatus + modelMap["ssh_key_name"] = *model.SSHKeyName + modelMap["standby_orchestrator_name"] = *model.StandbyOrchestratorName + modelMap["standby_orchestrator_status"] = *model.StandbyOrchestratorStatus + modelMap["standby_orchestrator_workspace_name"] = *model.StandbyOrchestratorWorkspaceName + modelMap["transit_gateway_name"] = *model.TransitGatewayName + modelMap["vpc_name"] = *model.VPCName + return modelMap, nil +} + +func DataSourceIBMPdrGetDrSummaryResponseServiceDetailsToMap(model *drautomationservicev1.ServiceDetails) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["crn"] = *model.CRN + modelMap["deployment_name"] = *model.DeploymentName + modelMap["description"] = *model.Description + modelMap["is_ksys_ha"] = *model.IsKsysHa + modelMap["plan_name"] = *model.PlanName + modelMap["primary_ip_address"] = *model.PrimaryIPAddress + modelMap["primary_orchestrator_dashboard_url"] = *model.PrimaryOrchestratorDashboardURL + modelMap["recovery_location"] = *model.RecoveryLocation + modelMap["resource_group"] = *model.ResourceGroup + modelMap["standby_description"] = *model.StandbyDescription + modelMap["standby_ip_address"] = *model.StandbyIPAddress + modelMap["standby_orchestrator_dashboard_url"] = *model.StandbyOrchestratorDashboardURL + modelMap["standby_status"] = *model.StandbyStatus + modelMap["status"] = *model.Status + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response_test.go new file mode 100644 index 0000000000..9633a55c34 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_dr_summary_response_test.go @@ -0,0 +1,151 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + . "github.com/IBM-Cloud/terraform-provider-ibm/ibm/unittest" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func TestAccIBMPdrGetDrSummaryResponseDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetDrSummaryResponseDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_summary_response.pdr_get_dr_summary_response_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_summary_response.pdr_get_dr_summary_response_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_summary_response.pdr_get_dr_summary_response_instance", "managed_vm_list.%"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_summary_response.pdr_get_dr_summary_response_instance", "orchestrator_details.#"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_dr_summary_response.pdr_get_dr_summary_response_instance", "service_details.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetDrSummaryResponseDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_dr_summary_response" "pdr_get_dr_summary_response_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + } + `) +} + +func TestDataSourceIBMPdrGetDrSummaryResponseOrchestratorDetailsToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["last_updated_orchestrator_deployment_time"] = "2025-10-16T09:28:13.696Z" + model["last_updated_standby_orchestrator_deployment_time"] = "2025-10-16T09:28:13.696Z" + model["latest_orchestrator_time"] = "2025-10-16T09:28:13.696Z" + model["location_id"] = "testString" + model["mfa_enabled"] = "testString" + model["orch_ext_connectivity_status"] = "testString" + model["orch_standby_node_addition_status"] = "testString" + model["orchestrator_cluster_message"] = "testString" + model["orchestrator_config_status"] = "testString" + model["orchestrator_group_leader"] = "testString" + model["orchestrator_location_type"] = "testString" + model["orchestrator_name"] = "testString" + model["orchestrator_status"] = "testString" + model["orchestrator_workspace_name"] = "testString" + model["proxy_ip"] = "testString" + model["schematic_workspace_name"] = "testString" + model["schematic_workspace_status"] = "testString" + model["ssh_key_name"] = "testString" + model["standby_orchestrator_name"] = "testString" + model["standby_orchestrator_status"] = "testString" + model["standby_orchestrator_workspace_name"] = "testString" + model["transit_gateway_name"] = "testString" + model["vpc_name"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.OrchestratorDetails) + model.LastUpdatedOrchestratorDeploymentTime = CreateMockDateTime("2025-10-16T09:28:13.696Z") + model.LastUpdatedStandbyOrchestratorDeploymentTime = CreateMockDateTime("2025-10-16T09:28:13.696Z") + model.LatestOrchestratorTime = CreateMockDateTime("2025-10-16T09:28:13.696Z") + model.LocationID = core.StringPtr("testString") + model.MfaEnabled = core.StringPtr("testString") + model.OrchExtConnectivityStatus = core.StringPtr("testString") + model.OrchStandbyNodeAdditionStatus = core.StringPtr("testString") + model.OrchestratorClusterMessage = core.StringPtr("testString") + model.OrchestratorConfigStatus = core.StringPtr("testString") + model.OrchestratorGroupLeader = core.StringPtr("testString") + model.OrchestratorLocationType = core.StringPtr("testString") + model.OrchestratorName = core.StringPtr("testString") + model.OrchestratorStatus = core.StringPtr("testString") + model.OrchestratorWorkspaceName = core.StringPtr("testString") + model.ProxyIP = core.StringPtr("testString") + model.SchematicWorkspaceName = core.StringPtr("testString") + model.SchematicWorkspaceStatus = core.StringPtr("testString") + model.SSHKeyName = core.StringPtr("testString") + model.StandbyOrchestratorName = core.StringPtr("testString") + model.StandbyOrchestratorStatus = core.StringPtr("testString") + model.StandbyOrchestratorWorkspaceName = core.StringPtr("testString") + model.TransitGatewayName = core.StringPtr("testString") + model.VPCName = core.StringPtr("testString") + + result, err := drautomationservice.DataSourceIBMPdrGetDrSummaryResponseOrchestratorDetailsToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMPdrGetDrSummaryResponseServiceDetailsToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["crn"] = "testString" + model["deployment_name"] = "testString" + model["description"] = "testString" + model["is_ksys_ha"] = true + model["plan_name"] = "testString" + model["primary_ip_address"] = "testString" + model["primary_orchestrator_dashboard_url"] = "testString" + model["recovery_location"] = "testString" + model["resource_group"] = "testString" + model["standby_description"] = "testString" + model["standby_ip_address"] = "testString" + model["standby_orchestrator_dashboard_url"] = "testString" + model["standby_status"] = "testString" + model["status"] = "testString" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.ServiceDetails) + model.CRN = core.StringPtr("testString") + model.DeploymentName = core.StringPtr("testString") + model.Description = core.StringPtr("testString") + model.IsKsysHa = core.BoolPtr(true) + model.PlanName = core.StringPtr("testString") + model.PrimaryIPAddress = core.StringPtr("testString") + model.PrimaryOrchestratorDashboardURL = core.StringPtr("testString") + model.RecoveryLocation = core.StringPtr("testString") + model.ResourceGroup = core.StringPtr("testString") + model.StandbyDescription = core.StringPtr("testString") + model.StandbyIPAddress = core.StringPtr("testString") + model.StandbyOrchestratorDashboardURL = core.StringPtr("testString") + model.StandbyStatus = core.StringPtr("testString") + model.Status = core.StringPtr("testString") + + result, err := drautomationservice.DataSourceIBMPdrGetDrSummaryResponseServiceDetailsToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_event.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_event.go new file mode 100644 index 0000000000..227aa103e8 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_event.go @@ -0,0 +1,236 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetEvent() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetEventRead, + + Schema: map[string]*schema.Schema{ + "provision_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "provision id.", + }, + "event_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Event ID.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "action": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of action for this event.", + }, + "api_source": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Source of API when it being executed.", + }, + "level": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Level of the event (notice, info, warning, error).", + }, + "message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The (translated) message of the event.", + }, + "message_data": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "metadata": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "resource": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of resource for this event.", + }, + "time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Time of activity in ISO 8601 - RFC3339.", + }, + "timestamp": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Time of activity in unix epoch.", + }, + "user": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Information about a user associated with an event.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "email": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Email of the User.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the User.", + }, + "user_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "ID of user who created/caused the event.", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetEventRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_event", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getEventOptions := &drautomationservicev1.GetEventOptions{} + + getEventOptions.SetProvisionID(d.Get("provision_id").(string)) + getEventOptions.SetEventID(d.Get("event_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + getEventOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + + event, response, err := drAutomationServiceClient.GetEventWithContext(context, getEventOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetEventWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetEventWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_event", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetEventID(d)) + + if err = d.Set("action", event.Action); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting action: %s", err), "(Data) ibm_pdr_get_event", "read", "set-action").GetDiag() + } + + if !core.IsNil(event.APISource) { + if err = d.Set("api_source", event.APISource); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting api_source: %s", err), "(Data) ibm_pdr_get_event", "read", "set-api_source").GetDiag() + } + } + + if err = d.Set("level", event.Level); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting level: %s", err), "(Data) ibm_pdr_get_event", "read", "set-level").GetDiag() + } + + if err = d.Set("message", event.Message); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting message: %s", err), "(Data) ibm_pdr_get_event", "read", "set-message").GetDiag() + } + + if !core.IsNil(event.MessageData) { + convertedMap := make(map[string]interface{}, len(event.MessageData)) + for k, v := range event.MessageData { + convertedMap[k] = v + } + if err = d.Set("message_data", flex.Flatten(convertedMap)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting message_data: %s", err), "(Data) ibm_pdr_get_event", "read", "set-message_data").GetDiag() + } + } + + if !core.IsNil(event.Metadata) { + convertedMap := make(map[string]interface{}, len(event.Metadata)) + for k, v := range event.Metadata { + convertedMap[k] = v + } + if err = d.Set("metadata", flex.Flatten(convertedMap)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting metadata: %s", err), "(Data) ibm_pdr_get_event", "read", "set-metadata").GetDiag() + } + } + + if err = d.Set("resource", event.Resource); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource: %s", err), "(Data) ibm_pdr_get_event", "read", "set-resource").GetDiag() + } + + if err = d.Set("time", flex.DateTimeToString(event.Time)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting time: %s", err), "(Data) ibm_pdr_get_event", "read", "set-time").GetDiag() + } + + if err = d.Set("timestamp", event.Timestamp); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting timestamp: %s", err), "(Data) ibm_pdr_get_event", "read", "set-timestamp").GetDiag() + } + + if !core.IsNil(event.User) { + user := []map[string]interface{}{} + userMap, err := DataSourceIBMPdrGetEventEventUserToMap(event.User) + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_event", "read", "user-to-map").GetDiag() + } + user = append(user, userMap) + if err = d.Set("user", user); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting user: %s", err), "(Data) ibm_pdr_get_event", "read", "set-user").GetDiag() + } + } + + return nil +} + +// dataSourceIBMPdrGetEventID returns a reasonable ID for the list. +func dataSourceIBMPdrGetEventID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func DataSourceIBMPdrGetEventEventUserToMap(model *drautomationservicev1.EventUser) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Email != nil { + modelMap["email"] = *model.Email + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + modelMap["user_id"] = *model.UserID + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_event_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_event_test.go new file mode 100644 index 0000000000..cbb506c3b4 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_event_test.go @@ -0,0 +1,73 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func TestAccIBMPdrGetEventDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetEventDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "provision_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "event_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "action"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "level"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "message"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "resource"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "time"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_event.pdr_get_event_instance", "timestamp"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetEventDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_event" "pdr_get_event_instance" { + provision_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + event_id = "00116b2a-9326-4024-839e-fb5364b76898" + } + `) +} + +func TestDataSourceIBMPdrGetEventEventUserToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["email"] = "abcuser@ibm.com" + model["name"] = "abcuser" + model["user_id"] = "IBMid-695000abc7E" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.EventUser) + model.Email = core.StringPtr("abcuser@ibm.com") + model.Name = core.StringPtr("abcuser") + model.UserID = core.StringPtr("IBMid-695000abc7E") + + result, err := drautomationservice.DataSourceIBMPdrGetEventEventUserToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_events.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_events.go new file mode 100644 index 0000000000..a35241a59c --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_events.go @@ -0,0 +1,252 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetEvents() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetEventsRead, + + Schema: map[string]*schema.Schema{ + "provision_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "provision id.", + }, + "time": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "(deprecated - use from_time) A time in either ISO 8601 or unix epoch format.", + }, + "from_time": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "A from query time in either ISO 8601 or unix epoch format.", + }, + "to_time": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "A to query time in either ISO 8601 or unix epoch format.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "event": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Events.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "action": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of action for this event.", + }, + "api_source": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Source of API when it being executed.", + }, + "event_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "ID of the Activity.", + }, + "level": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Level of the event (notice, info, warning, error).", + }, + "message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The (translated) message of the event.", + }, + "message_data": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "metadata": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go).", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + "resource": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Type of resource for this event.", + }, + "time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Time of activity in ISO 8601 - RFC3339.", + }, + "timestamp": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Time of activity in unix epoch.", + }, + "user": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Information about a user associated with an event.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "email": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Email of the User.", + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the User.", + }, + "user_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "ID of user who created/caused the event.", + }, + }, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetEventsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_events", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + listEventsOptions := &drautomationservicev1.ListEventsOptions{} + + listEventsOptions.SetProvisionID(d.Get("provision_id").(string)) + if _, ok := d.GetOk("time"); ok { + listEventsOptions.SetTime(d.Get("time").(string)) + } + if _, ok := d.GetOk("from_time"); ok { + listEventsOptions.SetFromTime(d.Get("from_time").(string)) + } + if _, ok := d.GetOk("to_time"); ok { + listEventsOptions.SetToTime(d.Get("to_time").(string)) + } + if _, ok := d.GetOk("accept_language"); ok { + listEventsOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + eventCollection, response, err := drAutomationServiceClient.ListEventsWithContext(context, listEventsOptions) + if err != nil { + detailedMsg := fmt.Sprintf("ListEventsWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "ListEventsWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_events", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetEventsID(d)) + + event := []map[string]interface{}{} + for _, eventItem := range eventCollection.Event { + eventItemMap, err := DataSourceIBMPdrGetEventsEventToMap(&eventItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_events", "read", "event-to-map").GetDiag() + } + event = append(event, eventItemMap) + } + if err = d.Set("event", event); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting event: %s", err), "(Data) ibm_pdr_get_events", "read", "set-event").GetDiag() + } + + return nil +} + +// dataSourceIBMPdrGetEventsID returns a reasonable ID for the list. +func dataSourceIBMPdrGetEventsID(d *schema.ResourceData) string { + return d.Get("provision_id").(string) +} + +func DataSourceIBMPdrGetEventsEventToMap(model *drautomationservicev1.Event) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + modelMap["action"] = *model.Action + if model.APISource != nil { + modelMap["api_source"] = *model.APISource + } + modelMap["event_id"] = *model.EventID + modelMap["level"] = *model.Level + modelMap["message"] = *model.Message + if model.MessageData != nil { + messageData := make(map[string]interface{}) + for k, v := range model.MessageData { + messageData[k] = flex.Stringify(v) + } + modelMap["message_data"] = messageData + } + if model.Metadata != nil { + metadata := make(map[string]interface{}) + for k, v := range model.Metadata { + metadata[k] = flex.Stringify(v) + } + modelMap["metadata"] = metadata + } + modelMap["resource"] = *model.Resource + modelMap["time"] = model.Time.String() + modelMap["timestamp"] = *model.Timestamp + if model.User != nil { + userMap, err := DataSourceIBMPdrGetEventsEventUserToMap(model.User) + if err != nil { + return modelMap, err + } + modelMap["user"] = []map[string]interface{}{userMap} + } + return modelMap, nil +} + +func DataSourceIBMPdrGetEventsEventUserToMap(model *drautomationservicev1.EventUser) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Email != nil { + modelMap["email"] = *model.Email + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + modelMap["user_id"] = *model.UserID + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_events_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_events_test.go new file mode 100644 index 0000000000..8f7144936e --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_events_test.go @@ -0,0 +1,116 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + . "github.com/IBM-Cloud/terraform-provider-ibm/ibm/unittest" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func TestAccIBMPdrGetEventsDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetEventsDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_events.pdr_get_events_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_events.pdr_get_events_instance", "provision_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_events.pdr_get_events_instance", "event.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetEventsDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_events" "pdr_get_events_instance" { + provision_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + time = "2025-06-19T23:59:59Z" + from_time = "2025-06-19T00:00:00Z" + to_time = "2025-06-19T23:59:59Z" + } + `) +} + +func TestDataSourceIBMPdrGetEventsEventToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + eventUserModel := make(map[string]interface{}) + eventUserModel["email"] = "abcuser@ibm.com" + eventUserModel["name"] = "abcuser" + eventUserModel["user_id"] = "IBMid-695000abc7E" + + model := make(map[string]interface{}) + model["action"] = "create" + model["api_source"] = "dr-automation-api" + model["event_id"] = "1cecfe43-43cd-4b1b-86be-30c2d3d2a25f" + model["level"] = "info" + model["message"] = "Service Instance created successfully" + model["message_data"] = map[string]interface{}{"anyKey": "anyValue"} + model["metadata"] = map[string]interface{}{"anyKey": "anyValue"} + model["resource"] = "ProvisionID" + model["time"] = "2025-06-23T07:12:49.840Z" + model["timestamp"] = "1750662769" + model["user"] = []map[string]interface{}{eventUserModel} + + assert.Equal(t, result, model) + } + + eventUserModel := new(drautomationservicev1.EventUser) + eventUserModel.Email = core.StringPtr("abcuser@ibm.com") + eventUserModel.Name = core.StringPtr("abcuser") + eventUserModel.UserID = core.StringPtr("IBMid-695000abc7E") + + model := new(drautomationservicev1.Event) + model.Action = core.StringPtr("create") + model.APISource = core.StringPtr("dr-automation-api") + model.EventID = core.StringPtr("1cecfe43-43cd-4b1b-86be-30c2d3d2a25f") + model.Level = core.StringPtr("info") + model.Message = core.StringPtr("Service Instance created successfully") + model.MessageData = map[string]interface{}{"anyKey": "anyValue"} + model.Metadata = map[string]interface{}{"anyKey": "anyValue"} + model.Resource = core.StringPtr("ProvisionID") + model.Time = CreateMockDateTime("2025-06-23T07:12:49.840Z") + model.Timestamp = core.StringPtr("1750662769") + model.User = eventUserModel + + result, err := drautomationservice.DataSourceIBMPdrGetEventsEventToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMPdrGetEventsEventUserToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["email"] = "abcuser@ibm.com" + model["name"] = "abcuser" + model["user_id"] = "IBMid-695000abc7E" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.EventUser) + model.Email = core.StringPtr("abcuser@ibm.com") + model.Name = core.StringPtr("abcuser") + model.UserID = core.StringPtr("IBMid-695000abc7E") + + result, err := drautomationservice.DataSourceIBMPdrGetEventsEventUserToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs.go new file mode 100644 index 0000000000..374086f778 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs.go @@ -0,0 +1,95 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetGrsLocationPairs() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetGrsLocationPairsRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "location_pairs": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A map of GRS location pairs where each key is a primary location and the value is its paired location.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetGrsLocationPairsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_grs_location_pairs", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getDrGrsLocationPairOptions := &drautomationservicev1.GetDrGrsLocationPairOptions{} + + getDrGrsLocationPairOptions.SetInstanceID(d.Get("instance_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + getDrGrsLocationPairOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + + getGrsLocationPairResponse, response, err := drAutomationServiceClient.GetDrGrsLocationPairWithContext(context, getDrGrsLocationPairOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetDrGrsLocationPairWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetDrGrsLocationPairWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_grs_location_pairs", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetGrsLocationPairsID(d)) + + if !core.IsNil(getGrsLocationPairResponse.LocationPairs) { + if err = d.Set("location_pairs", getGrsLocationPairResponse.LocationPairs); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting location_pairs: %s", err), "(Data) ibm_pdr_get_grs_location_pairs", "read", "set-location_pairs").GetDiag() + } + } + + return nil +} + +// dataSourceIBMPdrGetGrsLocationPairsID returns a reasonable ID for the list. +func dataSourceIBMPdrGetGrsLocationPairsID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs_test.go new file mode 100644 index 0000000000..31b68d9730 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_grs_location_pairs_test.go @@ -0,0 +1,41 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrGetGrsLocationPairsDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetGrsLocationPairsDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_grs_location_pairs.pdr_get_grs_location_pairs_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_grs_location_pairs.pdr_get_grs_location_pairs_instance", "instance_id"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetGrsLocationPairsDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_grs_location_pairs" "pdr_get_grs_location_pairs_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + } + `) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types.go new file mode 100644 index 0000000000..1ee30e449f --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types.go @@ -0,0 +1,148 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetMachineTypes() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetMachineTypesRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "primary_workspace_name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Primary Workspace Name.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "standby_workspace_name": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "Standby Workspace Name.", + }, + "workspaces": { + Type: schema.TypeList, + Computed: true, + Description: "List of workspaces with their machine types.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Computed: true, + }, + "machine_types": { + Type: schema.TypeList, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetMachineTypesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_machine_types", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getMachineTypeOptions := &drautomationservicev1.GetMachineTypeOptions{} + + getMachineTypeOptions.SetInstanceID(d.Get("instance_id").(string)) + getMachineTypeOptions.SetPrimaryWorkspaceName(d.Get("primary_workspace_name").(string)) + + if _, ok := d.GetOk("standby_workspace_name"); ok { + getMachineTypeOptions.SetStandbyWorkspaceName(d.Get("standby_workspace_name").(string)) + } + if _, ok := d.GetOk("accept_language"); ok { + getMachineTypeOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + + machineTypesByWorkspace, response, err := drAutomationServiceClient.GetMachineTypeWithContext(context, getMachineTypeOptions) + fmt.Println("machineTypesByWorkspace", machineTypesByWorkspace) + fmt.Println("============================================================") + fmt.Println("response:", response) + fmt.Println("============================================================") + if err != nil { + detailedMsg := fmt.Sprintf("GetMachineTypeWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetMachineTypeWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_machine_types", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetMachineTypesID(d)) + + if !core.IsNil(machineTypesByWorkspace.Workspaces) { + var workspacesList []map[string]interface{} + for name, types := range machineTypesByWorkspace.Workspaces { + entry := map[string]interface{}{ + "name": name, + "machine_types": convertToInterfaceList(types), + } + workspacesList = append(workspacesList, entry) + } + + if err := d.Set("workspaces", workspacesList); err != nil { + return flex.DiscriminatedTerraformErrorf( + err, fmt.Sprintf("Error setting workspaces: %s", err), + "(Data) ibm_pdr_get_machine_types", "read", "set-workspaces", + ).GetDiag() + } + } + + return nil +} + +// dataSourceIBMPdrGetMachineTypesID returns a reasonable ID for the list. +func dataSourceIBMPdrGetMachineTypesID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func convertToInterfaceList(items []string) []interface{} { + if items == nil { + return nil + } + + interfaceList := make([]interface{}, len(items)) + for i, v := range items { + interfaceList[i] = v + } + return interfaceList +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types_test.go new file mode 100644 index 0000000000..784fa40066 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_machine_types_test.go @@ -0,0 +1,44 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrGetMachineTypesDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetMachineTypesDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_machine_types.pdr_get_machine_types_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_machine_types.pdr_get_machine_types_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_machine_types.pdr_get_machine_types_instance", "primary_workspace_name"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetMachineTypesDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_machine_types" "pdr_get_machine_types_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + primary_workspace_name = "Test-workspace-wdc06" + standby_workspace_name = "Test-workspace-wdc07" + } + `) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list.go new file mode 100644 index 0000000000..83fe4bdab5 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list.go @@ -0,0 +1,128 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetManagedVMList() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetManagedVMListRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "managed_vms": &schema.Schema{ + Type: schema.TypeMap, + Computed: true, + Description: "A map where the key is the VM ID and the value is the corresponding ManagedVmDetails object.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetManagedVMListRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_managed_vm_list", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getDrManagedVMOptions := &drautomationservicev1.GetDrManagedVMOptions{} + + getDrManagedVMOptions.SetInstanceID(d.Get("instance_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + getDrManagedVMOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + + managedVMMapResponse, response, err := drAutomationServiceClient.GetDrManagedVMWithContext(context, getDrManagedVMOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetDrManagedVMWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetDrManagedVMWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_managed_vm_list", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetManagedVMListID(d)) + + if !core.IsNil(managedVMMapResponse.ManagedVms) { + convertedMap := make(map[string]interface{}, len(managedVMMapResponse.ManagedVms)) + for k, v := range managedVMMapResponse.ManagedVms { + convertedMap[k] = v + } + if err = d.Set("managed_vms", flex.Flatten(convertedMap)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting managed_vms: %s", err), "(Data) ibm_pdr_get_managed_vm_list", "read", "set-managed_vms").GetDiag() + } + } + + return nil +} + +// dataSourceIBMPdrGetManagedVMListID returns a reasonable ID for the list. +func dataSourceIBMPdrGetManagedVMListID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func DataSourceIBMPdrGetManagedVMListManagedVMDetailsToMap(model *drautomationservicev1.ManagedVMDetails) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Core != nil { + modelMap["core"] = *model.Core + } + if model.DrAverageTime != nil { + modelMap["dr_average_time"] = *model.DrAverageTime + } + if model.DrRegion != nil { + modelMap["dr_region"] = *model.DrRegion + } + if model.Memory != nil { + modelMap["memory"] = *model.Memory + } + if model.Region != nil { + modelMap["region"] = *model.Region + } + if model.VMName != nil { + modelMap["vm_name"] = *model.VMName + } + if model.WorkgroupName != nil { + modelMap["workgroup_name"] = *model.WorkgroupName + } + if model.WorkspaceName != nil { + modelMap["workspace_name"] = *model.WorkspaceName + } + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list_test.go new file mode 100644 index 0000000000..157c901ccd --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_managed_vm_list_test.go @@ -0,0 +1,75 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func TestAccIBMPdrGetManagedVMListDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetManagedVMListDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_managed_vm_list.pdr_get_managed_vm_list_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_managed_vm_list.pdr_get_managed_vm_list_instance", "instance_id"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetManagedVMListDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_managed_vm_list" "pdr_get_managed_vm_list_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + } + `) +} + +func TestDataSourceIBMPdrGetManagedVMListManagedVMDetailsToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["core"] = "0.50" + model["dr_average_time"] = "10" + model["dr_region"] = "nyc02" + model["memory"] = "4" + model["region"] = "lon04" + model["vm_name"] = "example_vm" + model["workgroup_name"] = "Example_Workgroup" + model["workspace_name"] = "Example_Workspace" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.ManagedVMDetails) + model.Core = core.StringPtr("0.50") + model.DrAverageTime = core.StringPtr("10") + model.DrRegion = core.StringPtr("nyc02") + model.Memory = core.StringPtr("4") + model.Region = core.StringPtr("lon04") + model.VMName = core.StringPtr("example_vm") + model.WorkgroupName = core.StringPtr("Example_Workgroup") + model.WorkspaceName = core.StringPtr("Example_Workspace") + + result, err := drautomationservice.DataSourceIBMPdrGetManagedVMListManagedVMDetailsToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace.go new file mode 100644 index 0000000000..a066efe81f --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace.go @@ -0,0 +1,340 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrGetPowervsWorkspace() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrGetPowervsWorkspaceRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "location_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Location ID value.", + }, + "dr_standby_workspace_description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Description of Standby Workspace.", + }, + "dr_standby_workspaces": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of standby disaster recovery workspaces.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "details": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Detailed information of the standby DR workspace.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Cloud Resource Name (CRN) of the DR workspace.", + }, + }, + }, + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Unique identifier of the standby workspace.", + }, + "location": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Location information of the standby workspace.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The region identifier of the DR location.", + }, + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The type of location (e.g., data-center, cloud-region).", + }, + "url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL endpoint to access the DR location.", + }, + }, + }, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the standby workspace.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current status of the standby workspace.", + }, + }, + }, + }, + "dr_workspace_description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Description of Workspace.", + }, + "dr_workspaces": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of primary disaster recovery workspaces.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "default": &schema.Schema{ + Type: schema.TypeBool, + Computed: true, + Description: "Indicates if this is the default DR workspace.", + }, + "details": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Detailed information about the DR workspace.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Cloud Resource Name (CRN) of the DR workspace.", + }, + }, + }, + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Unique identifier of the DR workspace.", + }, + "location": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "Location information of the DR workspace.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "region": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The region identifier of the DR location.", + }, + "type": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The type of location (e.g., data-center, cloud-region).", + }, + "url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The URL endpoint to access the DR location.", + }, + }, + }, + }, + "name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the DR workspace.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current status of the DR workspace.", + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMPdrGetPowervsWorkspaceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_powervs_workspace", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getPowervsWorkspacesOptions := &drautomationservicev1.GetPowervsWorkspacesOptions{} + + getPowervsWorkspacesOptions.SetInstanceID(d.Get("instance_id").(string)) + getPowervsWorkspacesOptions.SetLocationID(d.Get("location_id").(string)) + + drData, response, err := drAutomationServiceClient.GetPowervsWorkspacesWithContext(context, getPowervsWorkspacesOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetPowervsWorkspacesWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetPowervsWorkspacesWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_get_powervs_workspace", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrGetPowervsWorkspaceID(d)) + + if !core.IsNil(drData.DrStandbyWorkspaceDescription) { + if err = d.Set("dr_standby_workspace_description", flex.Stringify(drData.DrStandbyWorkspaceDescription)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting dr_standby_workspace_description: %s", err), "(Data) ibm_pdr_get_powervs_workspace", "read", "set-dr_standby_workspace_description").GetDiag() + } + } + + drStandbyWorkspaces := []map[string]interface{}{} + for _, drStandbyWorkspacesItem := range drData.DrStandbyWorkspaces { + drStandbyWorkspacesItemMap, err := DataSourceIBMPdrGetPowervsWorkspaceDrStandbyWorkspaceToMap(&drStandbyWorkspacesItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_powervs_workspace", "read", "dr_standby_workspaces-to-map").GetDiag() + } + drStandbyWorkspaces = append(drStandbyWorkspaces, drStandbyWorkspacesItemMap) + } + if err = d.Set("dr_standby_workspaces", drStandbyWorkspaces); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting dr_standby_workspaces: %s", err), "(Data) ibm_pdr_get_powervs_workspace", "read", "set-dr_standby_workspaces").GetDiag() + } + + if !core.IsNil(drData.DrWorkspaceDescription) { + if err = d.Set("dr_workspace_description", flex.Stringify(drData.DrWorkspaceDescription)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting dr_workspace_description: %s", err), "(Data) ibm_pdr_get_powervs_workspace", "read", "set-dr_workspace_description").GetDiag() + } + } + + drWorkspaces := []map[string]interface{}{} + for _, drWorkspacesItem := range drData.DrWorkspaces { + drWorkspacesItemMap, err := DataSourceIBMPdrGetPowervsWorkspaceDrWorkspaceToMap(&drWorkspacesItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_get_powervs_workspace", "read", "dr_workspaces-to-map").GetDiag() + } + drWorkspaces = append(drWorkspaces, drWorkspacesItemMap) + } + if err = d.Set("dr_workspaces", drWorkspaces); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting dr_workspaces: %s", err), "(Data) ibm_pdr_get_powervs_workspace", "read", "set-dr_workspaces").GetDiag() + } + + return nil +} + +// dataSourceIBMPdrGetPowervsWorkspaceID returns a reasonable ID for the list. +func dataSourceIBMPdrGetPowervsWorkspaceID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} + +func DataSourceIBMPdrGetPowervsWorkspaceDrStandbyWorkspaceToMap(model *drautomationservicev1.DrStandbyWorkspace) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Details != nil { + detailsMap, err := DataSourceIBMPdrGetPowervsWorkspaceDetailsDrToMap(model.Details) + if err != nil { + return modelMap, err + } + modelMap["details"] = []map[string]interface{}{detailsMap} + } + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.Location != nil { + locationMap, err := DataSourceIBMPdrGetPowervsWorkspaceLocationDrToMap(model.Location) + if err != nil { + return modelMap, err + } + modelMap["location"] = []map[string]interface{}{locationMap} + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.Status != nil { + modelMap["status"] = *model.Status + } + return modelMap, nil +} + +func DataSourceIBMPdrGetPowervsWorkspaceDetailsDrToMap(model *drautomationservicev1.DetailsDr) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.CRN != nil { + modelMap["crn"] = *model.CRN + } + return modelMap, nil +} + +func DataSourceIBMPdrGetPowervsWorkspaceLocationDrToMap(model *drautomationservicev1.LocationDr) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Region != nil { + modelMap["region"] = *model.Region + } + if model.Type != nil { + modelMap["type"] = *model.Type + } + if model.URL != nil { + modelMap["url"] = *model.URL + } + return modelMap, nil +} + +func DataSourceIBMPdrGetPowervsWorkspaceDrWorkspaceToMap(model *drautomationservicev1.DrWorkspace) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Default != nil { + modelMap["default"] = *model.Default + } + if model.Details != nil { + detailsMap, err := DataSourceIBMPdrGetPowervsWorkspaceDetailsDrToMap(model.Details) + if err != nil { + return modelMap, err + } + modelMap["details"] = []map[string]interface{}{detailsMap} + } + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.Location != nil { + locationMap, err := DataSourceIBMPdrGetPowervsWorkspaceLocationDrToMap(model.Location) + if err != nil { + return modelMap, err + } + modelMap["location"] = []map[string]interface{}{locationMap} + } + if model.Name != nil { + modelMap["name"] = *model.Name + } + if model.Status != nil { + modelMap["status"] = *model.Status + } + return modelMap, nil +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace_test.go new file mode 100644 index 0000000000..958a4cf34e --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_get_powervs_workspace_test.go @@ -0,0 +1,169 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 +*/ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/drautomationservice" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/stretchr/testify/assert" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrGetPowervsWorkspaceDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrGetPowervsWorkspaceDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_powervs_workspace.pdr_get_powervs_workspace_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_powervs_workspace.pdr_get_powervs_workspace_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_powervs_workspace.pdr_get_powervs_workspace_instance", "location_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_powervs_workspace.pdr_get_powervs_workspace_instance", "dr_standby_workspaces.#"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_get_powervs_workspace.pdr_get_powervs_workspace_instance", "dr_workspaces.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrGetPowervsWorkspaceDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_get_powervs_workspace" "pdr_get_powervs_workspace_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + location_id = "location_id" + If-None-Match = "If-None-Match" + } + `) +} + + +func TestDataSourceIBMPdrGetPowervsWorkspaceDrStandbyWorkspaceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + detailsDrModel := make(map[string]interface{}) + detailsDrModel["crn"] = "crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::" + + locationDrModel := make(map[string]interface{}) + locationDrModel["region"] = "lon06" + locationDrModel["type"] = "data-center" + locationDrModel["url"] = "https://lon.power-iaas.cloud.ibm.com" + + model := make(map[string]interface{}) + model["details"] = []map[string]interface{}{detailsDrModel} + model["id"] = "testString" + model["location"] = []map[string]interface{}{locationDrModel} + model["name"] = "testString" + model["status"] = "testString" + + assert.Equal(t, result, model) + } + + detailsDrModel := new(drautomationservicev1.DetailsDr) + detailsDrModel.CRN = core.StringPtr("crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::") + + locationDrModel := new(drautomationservicev1.LocationDr) + locationDrModel.Region = core.StringPtr("lon06") + locationDrModel.Type = core.StringPtr("data-center") + locationDrModel.URL = core.StringPtr("https://lon.power-iaas.cloud.ibm.com") + + model := new(drautomationservicev1.DrStandbyWorkspace) + model.Details = detailsDrModel + model.ID = core.StringPtr("testString") + model.Location = locationDrModel + model.Name = core.StringPtr("testString") + model.Status = core.StringPtr("testString") + + result, err := drautomationservice.DataSourceIBMPdrGetPowervsWorkspaceDrStandbyWorkspaceToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMPdrGetPowervsWorkspaceDetailsDrToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["crn"] = "crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.DetailsDr) + model.CRN = core.StringPtr("crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::") + + result, err := drautomationservice.DataSourceIBMPdrGetPowervsWorkspaceDetailsDrToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMPdrGetPowervsWorkspaceLocationDrToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["region"] = "lon06" + model["type"] = "data-center" + model["url"] = "https://lon.power-iaas.cloud.ibm.com" + + assert.Equal(t, result, model) + } + + model := new(drautomationservicev1.LocationDr) + model.Region = core.StringPtr("lon06") + model.Type = core.StringPtr("data-center") + model.URL = core.StringPtr("https://lon.power-iaas.cloud.ibm.com") + + result, err := drautomationservice.DataSourceIBMPdrGetPowervsWorkspaceLocationDrToMap(model) + assert.Nil(t, err) + checkResult(result) +} + +func TestDataSourceIBMPdrGetPowervsWorkspaceDrWorkspaceToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + detailsDrModel := make(map[string]interface{}) + detailsDrModel["crn"] = "crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::" + + locationDrModel := make(map[string]interface{}) + locationDrModel["region"] = "lon06" + locationDrModel["type"] = "data-center" + locationDrModel["url"] = "https://lon.power-iaas.cloud.ibm.com" + + model := make(map[string]interface{}) + model["default"] = true + model["details"] = []map[string]interface{}{detailsDrModel} + model["id"] = "testString" + model["location"] = []map[string]interface{}{locationDrModel} + model["name"] = "testString" + model["status"] = "active" + + assert.Equal(t, result, model) + } + + detailsDrModel := new(drautomationservicev1.DetailsDr) + detailsDrModel.CRN = core.StringPtr("crn:v1:bluemix:public:power-iaas:lon06:a/094f4214c75941f991da601b001df1fe:b6297e60-d0fe-4e24-8b15-276cf0645737::") + + locationDrModel := new(drautomationservicev1.LocationDr) + locationDrModel.Region = core.StringPtr("lon06") + locationDrModel.Type = core.StringPtr("data-center") + locationDrModel.URL = core.StringPtr("https://lon.power-iaas.cloud.ibm.com") + + model := new(drautomationservicev1.DrWorkspace) + model.Default = core.BoolPtr(true) + model.Details = detailsDrModel + model.ID = core.StringPtr("testString") + model.Location = locationDrModel + model.Name = core.StringPtr("testString") + model.Status = core.StringPtr("active") + + result, err := drautomationservice.DataSourceIBMPdrGetPowervsWorkspaceDrWorkspaceToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation.go b/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation.go new file mode 100644 index 0000000000..ad04fa16d4 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation.go @@ -0,0 +1,266 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func DataSourceIBMPdrLastOperation() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMPdrLastOperationRead, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "crn": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Cloud Resource Name (CRN) of the service instance.", + }, + "deployment_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the service instance deployment.", + }, + "is_ksys_ha": &schema.Schema{ + Type: schema.TypeBool, + Computed: true, + Description: "Indicates whether high availability (HA) is enabled for the orchestrator.", + }, + "last_updated_orchestrator_deployment_time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Deployment time of primary orchestrator VM.", + }, + "last_updated_standby_orchestrator_deployment_time": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Deployment time of StandBy orchestrator VM.", + }, + "mfa_enabled": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Multiple Factor Authentication Enabled or not.", + }, + "orch_ext_connectivity_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of standby node addition to the orchestrator cluster.", + }, + "orch_standby_node_addtion_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Health or informational message about the orchestrator cluster.", + }, + "orchestrator_cluster_message": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current status of the primary orchestrator VM.", + }, + "orchestrator_config_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Configuration status of the orchestrator cluster.", + }, + "plan_name": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Name of the Plan.", + }, + "primary_description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Detailed status message for the primary orchestrator VM.", + }, + "primary_ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address of the primary orchestrator VM.", + }, + "primary_orchestrator_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Configuration status of the orchestrator cluster.", + }, + "recovery_location": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Disaster recovery location associated with the instance.", + }, + "resource_group": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Resource group to which the service instance belongs.", + }, + "standby_description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Detailed status message for the standby orchestrator VM.", + }, + "standby_ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "IP address of the standby orchestrator VM.", + }, + "standby_status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Current state of the standby orchestrator VM.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Overall status of the service instance.", + }, + }, + } +} + +func dataSourceIBMPdrLastOperationRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_pdr_last_operation", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getLastOperationOptions := &drautomationservicev1.GetLastOperationOptions{} + + getLastOperationOptions.SetInstanceID(d.Get("instance_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + getLastOperationOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + // if _, ok := d.GetOk("if_none_match"); ok { + // getLastOperationOptions.SetIfNoneMatch(d.Get("if_none_match").(string)) + // } + + serviceInstanceStatus, response, err := drAutomationServiceClient.GetLastOperationWithContext(context, getLastOperationOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetLastOperationWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetLastOperationWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "(Data) ibm_pdr_last_operation", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMPdrLastOperationID(d)) + + if err = d.Set("crn", serviceInstanceStatus.CRN); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting crn: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-crn").GetDiag() + } + + if err = d.Set("deployment_name", serviceInstanceStatus.DeploymentName); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting deployment_name: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-deployment_name").GetDiag() + } + + if err = d.Set("is_ksys_ha", serviceInstanceStatus.IsKsysHa); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting is_ksys_ha: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-is_ksys_ha").GetDiag() + } + + if err = d.Set("last_updated_orchestrator_deployment_time", flex.DateTimeToString(serviceInstanceStatus.LastUpdatedOrchestratorDeploymentTime)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting last_updated_orchestrator_deployment_time: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-last_updated_orchestrator_deployment_time").GetDiag() + } + + if err = d.Set("last_updated_standby_orchestrator_deployment_time", flex.DateTimeToString(serviceInstanceStatus.LastUpdatedStandbyOrchestratorDeploymentTime)); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting last_updated_standby_orchestrator_deployment_time: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-last_updated_standby_orchestrator_deployment_time").GetDiag() + } + + if err = d.Set("mfa_enabled", serviceInstanceStatus.MfaEnabled); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting mfa_enabled: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-mfa_enabled").GetDiag() + } + + if !core.IsNil(serviceInstanceStatus.OrchExtConnectivityStatus) { + if err = d.Set("orch_ext_connectivity_status", serviceInstanceStatus.OrchExtConnectivityStatus); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting orch_ext_connectivity_status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-orch_ext_connectivity_status").GetDiag() + } + } + + if err = d.Set("orch_standby_node_addtion_status", serviceInstanceStatus.OrchStandbyNodeAddtionStatus); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting orch_standby_node_addtion_status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-orch_standby_node_addtion_status").GetDiag() + } + + if err = d.Set("orchestrator_cluster_message", serviceInstanceStatus.OrchestratorClusterMessage); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting orchestrator_cluster_message: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-orchestrator_cluster_message").GetDiag() + } + + if err = d.Set("orchestrator_config_status", serviceInstanceStatus.OrchestratorConfigStatus); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting orchestrator_config_status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-orchestrator_config_status").GetDiag() + } + + if err = d.Set("plan_name", serviceInstanceStatus.PlanName); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting plan_name: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-plan_name").GetDiag() + } + + if err = d.Set("primary_description", serviceInstanceStatus.PrimaryDescription); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting primary_description: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-primary_description").GetDiag() + } + + if err = d.Set("primary_ip_address", serviceInstanceStatus.PrimaryIPAddress); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting primary_ip_address: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-primary_ip_address").GetDiag() + } + + if err = d.Set("primary_orchestrator_status", serviceInstanceStatus.PrimaryOrchestratorStatus); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting primary_orchestrator_status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-primary_orchestrator_status").GetDiag() + } + + if err = d.Set("recovery_location", serviceInstanceStatus.RecoveryLocation); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting recovery_location: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-recovery_location").GetDiag() + } + + if err = d.Set("resource_group", serviceInstanceStatus.ResourceGroup); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting resource_group: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-resource_group").GetDiag() + } + + if err = d.Set("standby_description", serviceInstanceStatus.StandbyDescription); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting standby_description: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-standby_description").GetDiag() + } + + if err = d.Set("standby_ip_address", serviceInstanceStatus.StandbyIPAddress); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting standby_ip_address: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-standby_ip_address").GetDiag() + } + + if err = d.Set("standby_status", serviceInstanceStatus.StandbyStatus); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting standby_status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-standby_status").GetDiag() + } + + if err = d.Set("status", serviceInstanceStatus.Status); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting status: %s", err), "(Data) ibm_pdr_last_operation", "read", "set-status").GetDiag() + } + + return nil +} + +// dataSourceIBMPdrLastOperationID returns a reasonable ID for the list. +func dataSourceIBMPdrLastOperationID(d *schema.ResourceData) string { + return d.Get("instance_id").(string) +} diff --git a/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation_test.go b/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation_test.go new file mode 100644 index 0000000000..c6eaeab333 --- /dev/null +++ b/ibm/service/drautomationservice/data_source_ibm_pdr_last_operation_test.go @@ -0,0 +1,61 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 +*/ + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrLastOperationDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrLastOperationDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "instance_id"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "crn"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "deployment_name"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "is_ksys_ha"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "last_updated_orchestrator_deployment_time"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "last_updated_standby_orchestrator_deployment_time"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "mfa_enabled"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "orch_standby_node_addtion_status"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "orchestrator_cluster_message"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "orchestrator_config_status"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "plan_name"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "primary_description"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "primary_ip_address"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "primary_orchestrator_status"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "recovery_location"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "resource_group"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "standby_description"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "standby_ip_address"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "standby_status"), + resource.TestCheckResourceAttrSet("data.ibm_pdr_last_operation.pdr_last_operation_instance", "status"), + ), + }, + }, + }) +} + +func testAccCheckIBMPdrLastOperationDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_pdr_last_operation" "pdr_last_operation_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + } + `) +} + diff --git a/ibm/service/drautomationservice/resource_ibm_pdr_managedr.go b/ibm/service/drautomationservice/resource_ibm_pdr_managedr.go new file mode 100644 index 0000000000..cd54aa5cd2 --- /dev/null +++ b/ibm/service/drautomationservice/resource_ibm_pdr_managedr.go @@ -0,0 +1,546 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func ResourceIbmPdrManagedr() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceIbmPdrManagedrCreate, + ReadContext: resourceIbmPdrManagedrRead, + DeleteContext: resourceIbmPdrManagedrDelete, + Importer: &schema.ResourceImporter{}, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "instance id of instance to provision.", + }, + "stand_by_redeploy": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) { + v := val.(string) + allowed := []string{"true", "false"} + for _, a := range allowed { + if v == a { + return + } + } + errs = append(errs, fmt.Errorf("%q must be one of %v, got: %s", key, allowed, v)) + return + }, + Description: "Flag to indicate if standby should be redeployed (must be \"true\" or \"false\").", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "The language requested for the return document.", + }, + "accepts_incomplete": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + ForceNew: true, + Description: "A value of true indicates that both the IBM Cloud platform and the requesting client support asynchronous deprovisioning.", + }, + "dashboard_url": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "URL to the dashboard for managing the DR service instance in IBM Cloud.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "The CRN (Cloud Resource Name) of the DR service instance.", + }, + "etag": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + ForceNew: true, + }, + "action": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "api_key": { + Type: schema.TypeString, + Sensitive: true, + ForceNew: true, + Optional: true, + }, + "orchestrator_ha": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "guid": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "location_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "machine_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "orchestrator_location_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "orchestrator_name": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "orchestrator_password": { + Type: schema.TypeString, + Sensitive: true, + ForceNew: true, + Optional: true, + }, + "orchestrator_workspace_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "orchestrator_workspace_location": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "region_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "resource_instance": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + }, + "secondary_workspace_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "secret": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "secret_group": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ssh_key_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "ssh_public_key": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "standby_machine_type": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "standby_orchestrator_name": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "standby_orchestrator_workspace_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "standby_orchestrator_workspace_location": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "standby_tier": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "tier": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + }, + } +} + +func ResourceIbmPdrManagedrValidator() *validate.ResourceValidator { + validateSchema := make([]validate.ValidateSchema, 0) + validateSchema = append(validateSchema, + validate.ValidateSchema{ + Identifier: "stand_by_redeploy", + ValidateFunctionIdentifier: validate.ValidateAllowedStringValue, + Type: validate.TypeString, + Required: true, + AllowedValues: "false, true", + }, + ) + + resourceValidator := validate.ResourceValidator{ResourceName: "ibm_pdr_managedr", Schema: validateSchema} + return &resourceValidator +} + +func resourceIbmPdrManagedrCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_managedr", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + createManageDrOptions := &drautomationservicev1.CreateManageDrOptions{} + + createManageDrOptions.SetInstanceID(d.Get("instance_id").(string)) + createManageDrOptions.SetStandByRedeploy(d.Get("stand_by_redeploy").(string)) + if _, ok := d.GetOk("action"); ok { + createManageDrOptions.SetAction(d.Get("action").(string)) + } + if _, ok := d.GetOk("api_key"); ok { + createManageDrOptions.SetAPIKey(d.Get("api_key").(string)) + } + if v, ok := d.GetOk("orchestrator_ha"); ok { + enableHA := v.(bool) + createManageDrOptions.OrchestratorHa = core.BoolPtr(enableHA) + } + if _, ok := d.GetOk("guid"); ok { + createManageDrOptions.SetGUID(d.Get("guid").(string)) + } + if _, ok := d.GetOk("location_id"); ok { + createManageDrOptions.SetLocationID(d.Get("location_id").(string)) + } + if _, ok := d.GetOk("machine_type"); ok { + createManageDrOptions.SetMachineType(d.Get("machine_type").(string)) + } + if _, ok := d.GetOk("orchestrator_location_type"); ok { + createManageDrOptions.SetOrchestratorLocationType(d.Get("orchestrator_location_type").(string)) + } + if _, ok := d.GetOk("orchestrator_name"); ok { + createManageDrOptions.SetOrchestratorName(d.Get("orchestrator_name").(string)) + } + if _, ok := d.GetOk("orchestrator_password"); ok { + createManageDrOptions.SetOrchestratorPassword(d.Get("orchestrator_password").(string)) + } + if _, ok := d.GetOk("orchestrator_workspace_id"); ok { + createManageDrOptions.SetOrchestratorWorkspaceID(d.Get("orchestrator_workspace_id").(string)) + } + if _, ok := d.GetOk("orchestrator_workspace_location"); ok { + createManageDrOptions.SetOrchestratorWorkspaceLocation(d.Get("orchestrator_workspace_location").(string)) + } + if _, ok := d.GetOk("region_id"); ok { + createManageDrOptions.SetRegionID(d.Get("region_id").(string)) + } + if _, ok := d.GetOk("resource_instance"); ok { + createManageDrOptions.SetResourceInstance(d.Get("resource_instance").(string)) + } + if _, ok := d.GetOk("secondary_workspace_id"); ok { + createManageDrOptions.SetSecondaryWorkspaceID(d.Get("secondary_workspace_id").(string)) + } + if _, ok := d.GetOk("secret"); ok { + createManageDrOptions.SetSecret(d.Get("secret").(string)) + } + if _, ok := d.GetOk("secret_group"); ok { + createManageDrOptions.SetSecretGroup(d.Get("secret_group").(string)) + } + if _, ok := d.GetOk("ssh_key_name"); ok { + createManageDrOptions.SetSSHKeyName(d.Get("ssh_key_name").(string)) + } + if _, ok := d.GetOk("standby_machine_type"); ok { + createManageDrOptions.SetStandbyMachineType(d.Get("standby_machine_type").(string)) + } + if _, ok := d.GetOk("standby_orchestrator_name"); ok { + createManageDrOptions.SetStandbyOrchestratorName(d.Get("standby_orchestrator_name").(string)) + } + if _, ok := d.GetOk("standby_orchestrator_workspace_id"); ok { + createManageDrOptions.SetStandbyOrchestratorWorkspaceID(d.Get("standby_orchestrator_workspace_id").(string)) + } + if _, ok := d.GetOk("standby_orchestrator_workspace_location"); ok { + createManageDrOptions.SetStandbyOrchestratorWorkspaceLocation(d.Get("standby_orchestrator_workspace_location").(string)) + } + if _, ok := d.GetOk("standby_tier"); ok { + createManageDrOptions.SetStandbyTier(d.Get("standby_tier").(string)) + } + if _, ok := d.GetOk("tier"); ok { + createManageDrOptions.SetTier(d.Get("tier").(string)) + } + if _, ok := d.GetOk("accept_language"); ok { + createManageDrOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + // if _, ok := d.GetOk("if_none_match"); ok { + // createManageDrOptions.SetIfNoneMatch(d.Get("if_none_match").(string)) + // } + if _, ok := d.GetOk("accepts_incomplete"); ok { + createManageDrOptions.SetAcceptsIncomplete(d.Get("accepts_incomplete").(bool)) + } + + serviceInstanceManageDr, response, err := drAutomationServiceClient.CreateManageDrWithContext(context, createManageDrOptions) + if err != nil { + detailedMsg := fmt.Sprintf("CreateManageDrWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "CreateManageDrWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "ibm_pdr_managedr", "create") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(fmt.Sprintf("%s", *serviceInstanceManageDr.ID)) + // Step 2: Poll Last Operation status every 5 minutes until Active or Fail + instanceID := *createManageDrOptions.InstanceID + const ( + pollInterval = 1 * time.Minute + maxWaitTime = 75 * time.Minute // optional, can extend as needed + ) + timeout := time.After(maxWaitTime) + ticker := time.NewTicker(pollInterval) + // defer ticker.Stop() + + log.Printf("[INFO] Started polling last operation status for instance %s every %s", instanceID, pollInterval) + enableha, _ := d.GetOk("orchestrator_ha") + + if !enableha.(bool) { + for { + select { + case <-timeout: + errMsg := fmt.Sprintf("Timeout exceeded while waiting for Manage DR to become Active (instance_id: %s)", instanceID) + tfErr := flex.TerraformErrorf(fmt.Errorf("%s", errMsg), errMsg, "ibm_pdr_managedr", "create") + log.Printf("[ERROR] %s", errMsg) + ticker.Stop() + return tfErr.GetDiag() + + case <-ticker.C: + status, _, _, statusErr, errormessage := checkLastOperationStatus(context, drAutomationServiceClient, instanceID) + if statusErr != nil { + tfErr := flex.TerraformErrorf(statusErr, fmt.Sprintf("GetLastOperation failed: %s", statusErr.Error()), "ibm_pdr_managedr", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + ticker.Stop() + return tfErr.GetDiag() + } + + log.Printf("[INFO] Current Last Operation status for instance %s: %s", instanceID, status) + + switch strings.ToLower(status) { + case "active": + log.Printf("[INFO] Manage DR operation completed successfully for instance %s", instanceID) + ticker.Stop() + return resourceIbmPdrManagedrRead(context, d, meta) + + case "fail", "failed", "error": + errMsg := fmt.Sprintf("Manage DR operation failed for instance %s (status: %s) and error message: %s", instanceID, status, errormessage) + tfErr := flex.TerraformErrorf(fmt.Errorf("%s", errMsg), errMsg, "ibm_pdr_managedr", "create") + + log.Printf("[ERROR] %s", errMsg) + ticker.Stop() + return tfErr.GetDiag() + + default: + log.Printf("[DEBUG] Manage DR still in progress (status: %s)... retrying in %v", status, pollInterval) + } + } + } + } else { + for { + select { + case <-timeout: + errMsg := fmt.Sprintf("Timeout exceeded while waiting for Manage DR to become Active (instance_id: %s)", instanceID) + tfErr := flex.TerraformErrorf(fmt.Errorf("%s", errMsg), errMsg, "ibm_pdr_managedr", "create") + log.Printf("[ERROR] %s", errMsg) + ticker.Stop() + return tfErr.GetDiag() + + case <-ticker.C: + status, _, standbyStatus, statusErr, errormessage := checkLastOperationStatus(context, drAutomationServiceClient, instanceID) + if statusErr != nil { + tfErr := flex.TerraformErrorf(statusErr, fmt.Sprintf("GetLastOperation failed: %s", statusErr.Error()), "ibm_pdr_managedr", "create") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + ticker.Stop() + return tfErr.GetDiag() + } + + log.Printf("[INFO] Current Last Operation status for instance %s: %s", instanceID, status) + + switch strings.ToLower(status) { + case "active": + if strings.ToLower(standbyStatus) == "active" { + log.Printf("[INFO] Manage DR operation completed successfully for instance %s (both primary and standby active)", instanceID) + ticker.Stop() + return resourceIbmPdrManagedrRead(context, d, meta) + } + if strings.ToLower(standbyStatus) == "failed" { + log.Printf("[INFO] Standby Orchestrator Failed for instance %s", instanceID) + ticker.Stop() + return resourceIbmPdrManagedrRead(context, d, meta) + } + + // If standby still initializing + log.Printf("[INFO] Manage DR overall status is Active, but standby orchestrator still in progress (status: %s). Retrying in %v...", + standbyStatus, pollInterval) + continue + + case "fail", "failed", "error": + errMsg := fmt.Sprintf("Manage DR operation failed for instance %s (status: %s) and error message: %s", instanceID, status, errormessage) + tfErr := flex.TerraformErrorf(fmt.Errorf("%s", errMsg), errMsg, "ibm_pdr_managedr", "create") + + log.Printf("[ERROR] %s", errMsg) + ticker.Stop() + return tfErr.GetDiag() + + default: + log.Printf("[DEBUG] Manage DR still in progress (status: %s)... retrying in %v", status, pollInterval) + } + } + } + } + + // return resourceIbmPdrManagedrRead(context, d, meta) + +} + +func resourceIbmPdrManagedrRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_managedr", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getManageDrOptions := &drautomationservicev1.GetManageDrOptions{} + + instanceID := d.Get("instance_id").(string) + + log.Printf("[DEBUG] Read operation using instance ID from resource: %s", instanceID) + + getManageDrOptions.SetInstanceID(instanceID) + + // if _, ok := d.GetOk("accept_language"); ok { + // getManageDrOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + // } + // if _, ok := d.GetOk("if_none_match"); ok { + // getManageDrOptions.SetIfNoneMatch(d.Get("if_none_match").(string)) + // } + + serviceInstanceManageDr, response, err := drAutomationServiceClient.GetManageDrWithContext(context, getManageDrOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetManageDrWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetManageDrWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "ibm_pdr_managedr", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + if !core.IsNil(serviceInstanceManageDr.DashboardURL) { + if err = d.Set("dashboard_url", serviceInstanceManageDr.DashboardURL); err != nil { + err = fmt.Errorf("Error setting dashboard_url: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_managedr", "read", "set-dashboard_url").GetDiag() + } + } + if !core.IsNil(serviceInstanceManageDr.ID) { + if err = d.Set("instance_id", serviceInstanceManageDr.ID); err != nil { + err = fmt.Errorf("Error setting instance_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_managedr", "read", "set-instance_id").GetDiag() + } + } + if err = d.Set("etag", response.Headers.Get("Etag")); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting etag: %s", err), "ibm_pdr_managedr", "read", "set-etag").GetDiag() + } + + return nil +} + +func resourceIbmPdrManagedrDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // This resource does not support a "delete" operation. + d.SetId("") + return nil +} + +func checkLastOperationStatus(ctx context.Context, client *drautomationservicev1.DrAutomationServiceV1, instanceID string) (string, string, string, error, error) { + opts := &drautomationservicev1.GetLastOperationOptions{} + opts.SetInstanceID(instanceID) + + statusResponse, _, err := client.GetLastOperationWithContext(ctx, opts) + if err != nil { + return "", "", "", err, nil + } + + if statusResponse.Status == nil { + return *statusResponse.Status, "", "", fmt.Errorf("received nil status for instance %s", instanceID), nil + } + + status := strings.ToLower(*statusResponse.Status) + primaryStatus := strings.ToLower(*statusResponse.PrimaryOrchestratorStatus) + standbyStatus := strings.ToLower(*statusResponse.StandbyStatus) + + // --- Custom error logic based on your conditions --- + if status == "failed" { + switch { + case primaryStatus == "failed" && standbyStatus == "failed": + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("%s \n %s", *statusResponse.PrimaryDescription, *statusResponse.StandbyDescription) + case primaryStatus == "failed" && (standbyStatus == "" || standbyStatus == "na"): + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("%s", *statusResponse.PrimaryDescription) + case primaryStatus == "active" && (standbyStatus != "" || standbyStatus == "failed"): + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("%s \n %s", *statusResponse.PrimaryDescription, *statusResponse.StandbyDescription) + case primaryStatus == "failed": + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("primary orchestrator failed for instance %s", instanceID) + case standbyStatus == "failed": + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("standby orchestrator failed for instance %s", instanceID) + default: + return status, primaryStatus, standbyStatus, nil, fmt.Errorf("operation failed for instance %s with unknown cause", instanceID) + } + } + + return *statusResponse.Status, primaryStatus, standbyStatus, nil, nil +} diff --git a/ibm/service/drautomationservice/resource_ibm_pdr_managedr_test.go b/ibm/service/drautomationservice/resource_ibm_pdr_managedr_test.go new file mode 100644 index 0000000000..e0a95decd0 --- /dev/null +++ b/ibm/service/drautomationservice/resource_ibm_pdr_managedr_test.go @@ -0,0 +1,156 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" +) + +func TestAccIBMPdrManagedrBasic(t *testing.T) { + var conf drautomationservicev1.ServiceInstanceManageDr + instanceID := fmt.Sprintf("tf_instance_id_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrManagedrConfigBasic(instanceID), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPdrManagedrExists("ibm_pdr_managedr.pdr_managedr_instance", conf), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "instance_id", instanceID), + ), + }, + }, + }) +} + +func TestAccIBMPdrManagedrAllArgs(t *testing.T) { + var conf drautomationservicev1.ServiceInstanceManageDr + instanceID := fmt.Sprintf("tf_instance_id_%d", acctest.RandIntRange(10, 100)) + standByRedeploy := fmt.Sprintf("tf_stand_by_redeploy_%d", acctest.RandIntRange(10, 100)) + acceptLanguage := fmt.Sprintf("tf_accept_language_%d", acctest.RandIntRange(10, 100)) + ifNoneMatch := fmt.Sprintf("tf_if_none_match_%d", acctest.RandIntRange(10, 100)) + acceptsIncomplete := "true" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrManagedrConfig(instanceID, standByRedeploy, acceptLanguage, ifNoneMatch, acceptsIncomplete), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPdrManagedrExists("ibm_pdr_managedr.pdr_managedr_instance", conf), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "instance_id", instanceID), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "stand_by_redeploy", standByRedeploy), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "accept_language", acceptLanguage), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "if_none_match", ifNoneMatch), + resource.TestCheckResourceAttr("ibm_pdr_managedr.pdr_managedr_instance", "accepts_incomplete", acceptsIncomplete), + ), + }, + resource.TestStep{ + ResourceName: "ibm_pdr_managedr.pdr_managedr", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckIBMPdrManagedrConfigBasic(instanceID string) string { + return fmt.Sprintf(` + resource "ibm_pdr_managedr" "pdr_managedr_instance" { + instance_id = "%s" + } + `, instanceID) +} + +func testAccCheckIBMPdrManagedrConfig(instanceID string, standByRedeploy string, acceptLanguage string, ifNoneMatch string, acceptsIncomplete string) string { + return fmt.Sprintf(` + + resource "ibm_pdr_managedr" "pdr_managedr_instance" { + instance_id = "%s" + stand_by_redeploy = "%s" + accept_language = "%s" + if_none_match = "%s" + accepts_incomplete = %s + } + `, instanceID, standByRedeploy, acceptLanguage, ifNoneMatch, acceptsIncomplete) +} + +func testAccCheckIBMPdrManagedrExists(n string, obj drautomationservicev1.ServiceInstanceManageDr) resource.TestCheckFunc { + + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + drAutomationServiceClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + return err + } + + getManageDrOptions := &drautomationservicev1.GetManageDrOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getManageDrOptions.SetInstanceID(parts[0]) + getManageDrOptions.SetInstanceID(parts[1]) + + serviceInstanceManageDr, _, err := drAutomationServiceClient.GetManageDr(getManageDrOptions) + if err != nil { + return err + } + + obj = *serviceInstanceManageDr + return nil + } +} + +func testAccCheckIBMPdrManagedrDestroy(s *terraform.State) error { + drAutomationServiceClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_pdr_managedr" { + continue + } + + getManageDrOptions := &drautomationservicev1.GetManageDrOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getManageDrOptions.SetInstanceID(parts[0]) + getManageDrOptions.SetInstanceID(parts[1]) + + // Try to find the key + _, response, err := drAutomationServiceClient.GetManageDr(getManageDrOptions) + + if err == nil { + return fmt.Errorf("pdr_managedr still exists: %s", rs.Primary.ID) + } else if response.StatusCode != 404 { + return fmt.Errorf("Error checking for pdr_managedr (%s) has been destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} diff --git a/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey.go b/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey.go new file mode 100644 index 0000000000..944a550b49 --- /dev/null +++ b/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey.go @@ -0,0 +1,212 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.105.0-3c13b041-20250605-193116 + */ + +package drautomationservice + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func ResourceIBMPdrValidateApikey() *schema.Resource { + return &schema.Resource{ + CreateContext: resourceIBMPdrValidateApikeyCreate, + ReadContext: resourceIBMPdrValidateApikeyRead, + UpdateContext: resourceIBMPdrValidateApikeyUpdate, + DeleteContext: resourceIBMPdrValidateApikeyDelete, + Importer: &schema.ResourceImporter{}, + + Schema: map[string]*schema.Schema{ + "instance_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "instance id of instance to provision.", + }, + "accept_language": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Description: "The language requested for the return document.", + }, + "api_key": &schema.Schema{ + Type: schema.TypeString, + Required: true, + // ForceNew: true, + Sensitive: true, + Description: "api key", + }, + "description": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Validation result message.", + }, + "status": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Status of the API key.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Unique identifier of the API key.", + }, + "etag": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func resourceIBMPdrValidateApikeyCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "create", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + createApikeyOptions := &drautomationservicev1.CreateApikeyOptions{} + + createApikeyOptions.SetInstanceID(d.Get("instance_id").(string)) + createApikeyOptions.SetAPIKey(d.Get("api_key").(string)) + + validationKeyResponse, response, err := drAutomationServiceClient.CreateApikeyWithContext(context, createApikeyOptions) + if err != nil { + detailedMsg := fmt.Sprintf("CreateApikeyWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "CreateApikeyWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "ibm_pdr_validate_apikey", "create") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + d.SetId(fmt.Sprintf("%s/%s", *createApikeyOptions.InstanceID, *validationKeyResponse.ID)) + + return resourceIBMPdrValidateApikeyRead(context, d, meta) +} + +func resourceIBMPdrValidateApikeyRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getApikeyOptions := &drautomationservicev1.GetApikeyOptions{} + + getApikeyOptions.SetInstanceID(d.Get("instance_id").(string)) + // if _, ok := d.GetOk("accept_language"); ok { + // getApikeyOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + // } + // if _, ok := d.GetOk("if_none_match"); ok { + // getApikeyOptions.SetIfNoneMatch(d.Get("if_none_match").(string)) + // } + + validationKeyResponse, response, err := drAutomationServiceClient.GetApikeyWithContext(context, getApikeyOptions) + if err != nil { + detailedMsg := fmt.Sprintf("GetApikeyWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "GetApikeyWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + if response.StatusCode == 404 { + d.SetId("") + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "ibm_pdr_validate_apikey", "read") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + if !core.IsNil(validationKeyResponse.Description) { + if err = d.Set("description", validationKeyResponse.Description); err != nil { + err = fmt.Errorf("Error setting description: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "read", "set-description").GetDiag() + } + } + if !core.IsNil(validationKeyResponse.Status) { + if err = d.Set("status", validationKeyResponse.Status); err != nil { + err = fmt.Errorf("Error setting status: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "read", "set-status").GetDiag() + } + } + if !core.IsNil(validationKeyResponse.ID) { + if err = d.Set("instance_id", validationKeyResponse.ID); err != nil { + err = fmt.Errorf("Error setting instance_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "read", "set-instance_id").GetDiag() + } + } + if err = d.Set("etag", response.Headers.Get("Etag")); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting etag: %s", err), "ibm_pdr_validate_apikey", "read", "set-etag").GetDiag() + } + + return nil +} + +func resourceIBMPdrValidateApikeyUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + drAutomationServiceClient, err := meta.(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_pdr_validate_apikey", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + updateApikeyOptions := &drautomationservicev1.UpdateApikeyOptions{} + + updateApikeyOptions.SetInstanceID(d.Get("instance_id").(string)) + if _, ok := d.GetOk("accept_language"); ok { + updateApikeyOptions.SetAcceptLanguage(d.Get("accept_language").(string)) + } + // if _, ok := d.GetOk("if_none_match"); ok { + // updateApikeyOptions.SetIfNoneMatch(d.Get("if_none_match").(string)) + // } + updateApikeyOptions.SetAPIKey(d.Get("api_key").(string)) + + _, response, err := drAutomationServiceClient.UpdateApikeyWithContext(context, updateApikeyOptions) + if err != nil { + detailedMsg := fmt.Sprintf("UpdateApikeyWithContext failed: %s", err.Error()) + // Include HTTP status & raw body if available + if response != nil { + detailedMsg = fmt.Sprintf( + "UpdateApikeyWithContext failed: %s (status: %d, response: %s)", + err.Error(), response.StatusCode, response.Result, + ) + } + if response.StatusCode == 404 { + d.SetId("") + } + tfErr := flex.TerraformErrorf(err, detailedMsg, "ibm_pdr_validate_apikey", "update") + log.Printf("[ERROR] %s", detailedMsg) + return tfErr.GetDiag() + } + + return resourceIBMPdrValidateApikeyRead(context, d, meta) +} + +func resourceIBMPdrValidateApikeyDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + // This resource does not support a "delete" operation. + d.SetId("") + return nil +} diff --git a/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey_test.go b/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey_test.go new file mode 100644 index 0000000000..67ec0629a8 --- /dev/null +++ b/ibm/service/drautomationservice/resource_ibm_pdr_validate_apikey_test.go @@ -0,0 +1,162 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package drautomationservice_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/acctest" + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.ibm.com/DRAutomation/dra-go-sdk/drautomationservicev1" +) + +func TestAccIBMPdrValidateApikeyBasic(t *testing.T) { + var conf drautomationservicev1.ValidationKeyResponse + instanceID := fmt.Sprintf("tf_instance_id_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPdrValidateApikeyDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrValidateApikeyConfigBasic(instanceID), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPdrValidateApikeyExists("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", conf), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "instance_id", instanceID), + ), + }, + }, + }) +} + +func TestAccIBMPdrValidateApikeyAllArgs(t *testing.T) { + var conf drautomationservicev1.ValidationKeyResponse + instanceID := fmt.Sprintf("tf_instance_id_%d", acctest.RandIntRange(10, 100)) + acceptLanguage := fmt.Sprintf("tf_accept_language_%d", acctest.RandIntRange(10, 100)) + ifNoneMatch := fmt.Sprintf("tf_if_none_match_%d", acctest.RandIntRange(10, 100)) + acceptLanguageUpdate := fmt.Sprintf("tf_accept_language_%d", acctest.RandIntRange(10, 100)) + ifNoneMatchUpdate := fmt.Sprintf("tf_if_none_match_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMPdrValidateApikeyDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMPdrValidateApikeyConfig(instanceID, acceptLanguage, ifNoneMatch), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMPdrValidateApikeyExists("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", conf), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "instance_id", instanceID), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "accept_language", acceptLanguage), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "if_none_match", ifNoneMatch), + ), + }, + resource.TestStep{ + Config: testAccCheckIBMPdrValidateApikeyConfig(instanceID, acceptLanguageUpdate, ifNoneMatchUpdate), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "instance_id", instanceID), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "accept_language", acceptLanguageUpdate), + resource.TestCheckResourceAttr("ibm_pdr_validate_apikey.pdr_validate_apikey_instance", "if_none_match", ifNoneMatchUpdate), + ), + }, + resource.TestStep{ + ResourceName: "ibm_pdr_validate_apikey.pdr_validate_apikey", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckIBMPdrValidateApikeyConfigBasic(instanceID string) string { + return fmt.Sprintf(` + resource "ibm_pdr_validate_apikey" "pdr_validate_apikey_instance" { + instance_id = "%s" + } + `, instanceID) +} + +func testAccCheckIBMPdrValidateApikeyConfig(instanceID string, acceptLanguage string, ifNoneMatch string) string { + return fmt.Sprintf(` + + resource "ibm_pdr_validate_apikey" "pdr_validate_apikey_instance" { + instance_id = "%s" + accept_language = "%s" + if_none_match = "%s" + } + `, instanceID, acceptLanguage, ifNoneMatch) +} + +func testAccCheckIBMPdrValidateApikeyExists(n string, obj drautomationservicev1.ValidationKeyResponse) resource.TestCheckFunc { + + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + drAutomationServiceClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + return err + } + + getApikeyOptions := &drautomationservicev1.GetApikeyOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getApikeyOptions.SetInstanceID(parts[0]) + getApikeyOptions.SetInstanceID(parts[1]) + + validationKeyResponse, _, err := drAutomationServiceClient.GetApikey(getApikeyOptions) + if err != nil { + return err + } + + obj = *validationKeyResponse + return nil + } +} + +func testAccCheckIBMPdrValidateApikeyDestroy(s *terraform.State) error { + drAutomationServiceClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).DrAutomationServiceV1() + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_pdr_validate_apikey" { + continue + } + + getApikeyOptions := &drautomationservicev1.GetApikeyOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getApikeyOptions.SetInstanceID(parts[0]) + getApikeyOptions.SetInstanceID(parts[1]) + + // Try to find the key + _, response, err := drAutomationServiceClient.GetApikey(getApikeyOptions) + + if err == nil { + return fmt.Errorf("pdr_validate_apikey still exists: %s", rs.Primary.ID) + } else if response.StatusCode != 404 { + return fmt.Errorf("Error checking for pdr_validate_apikey (%s) has been destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} diff --git a/website/docs/d/pdr_get_deployment_status.html.markdown b/website/docs/d/pdr_get_deployment_status.html.markdown new file mode 100755 index 0000000000..2d48fc1b3c --- /dev/null +++ b/website/docs/d/pdr_get_deployment_status.html.markdown @@ -0,0 +1,45 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_deployment_status" +description: |- + Get information about pdr_get_deployment_status +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_deployment_status + +Provides a read-only data source to retrieve information about pdr_get_deployment_status. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_deployment_status" "pdr_get_deployment_status" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_deployment_status. +* `orch_ext_connectivity_status` - (String) External connectivity status of the orchestrator cluster. +* `orch_standby_node_addition_status` - (String) Status of the standby node addition process. +* `orchestrator_cluster_message` - (String) Cluster status message. +* `orchestrator_cluster_type` - (String) Type of orchestrator cluster. +* `orchestrator_config_status` - (String) Configuration status of the orchestrator. +* `orchestrator_group_leader` - (String) Name of the orchestrator acting as the cluster leader. +* `orchestrator_name` - (String) Name of the primary orchestrator. +* `orchestrator_status` - (String) Status of the primary orchestrator. +* `schematic_workspace_name` - (String) Name of the schematic workspace. +* `schematic_workspace_status` - (String) Status of the schematic workspace. +* `ssh_key_name` - (String) Name of the SSH key associated with the orchestrator. +* `standby_orchestrator_name` - (String) Name of the standby orchestrator. +* `standby_orchestrator_status` - (String) Status of the standby orchestrator. + diff --git a/website/docs/d/pdr_get_dr_locations.html.markdown b/website/docs/d/pdr_get_dr_locations.html.markdown new file mode 100644 index 0000000000..83b441f489 --- /dev/null +++ b/website/docs/d/pdr_get_dr_locations.html.markdown @@ -0,0 +1,37 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_dr_locations" +description: |- + Get information about pdr_get_dr_locations +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_dr_locations + +Provides a read-only data source to retrieve information about pdr_get_dr_locations. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_dr_locations" "pdr_get_dr_locations" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_dr_locations. +* `dr_locations` - (List) List of disaster recovery locations available for the service. +Nested schema for **dr_locations**: + * `id` - (String) Unique identifier of the DR location. + * `name` - (String) Name of the DR location. + diff --git a/website/docs/d/pdr_get_dr_summary_response.html.markdown b/website/docs/d/pdr_get_dr_summary_response.html.markdown new file mode 100755 index 0000000000..7a9771a664 --- /dev/null +++ b/website/docs/d/pdr_get_dr_summary_response.html.markdown @@ -0,0 +1,75 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_dr_summary_response" +description: |- + Get information about pdr_get_dr_summary_response +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_dr_summary_response + +Provides a read-only data source to retrieve information about a pdr_get_dr_summary_response. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_dr_summary_response" "pdr_get_dr_summary_response" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_dr_summary_response. +* `managed_vm_list` - (Map) A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go). +* `orchestrator_details` - (List) Contains details about the orchestrator configuration. +Nested schema for **orchestrator_details**: + * `last_updated_orchestrator_deployment_time` - (String) Deployment time of primary orchestrator VM. + * `last_updated_standby_orchestrator_deployment_time` - (String) Deployment time of StandBy orchestrator VM. + * `latest_orchestrator_time` - (String) Latest Orchestrator Time in COS. + * `location_id` - (String) Location identifier. + * `mfa_enabled` - (String) Multi Factor Authentication Enabled or not. + * `orch_ext_connectivity_status` - (String) External connectivity status of the orchestrator. + * `orch_standby_node_addition_status` - (String) Status of standby node addition. + * `orchestrator_cluster_message` - (String) Message regarding orchestrator cluster status. + * `orchestrator_config_status` - (String) Configuration status of the orchestrator. + * `orchestrator_group_leader` - (String) Leader node of the orchestrator group. + * `orchestrator_location_type` - (String) Type of orchestrator Location. + * `orchestrator_name` - (String) Name of the primary orchestrator. + * `orchestrator_status` - (String) Status of the primary orchestrator. + * `orchestrator_workspace_name` - (String) Name of the orchestrator workspace. + * `proxy_ip` - (String) IP address of the proxy. + * `schematic_workspace_name` - (String) Name of the schematic workspace. + * `schematic_workspace_status` - (String) Status of the schematic workspace. + * `ssh_key_name` - (String) SSH key name used for the orchestrator. + * `standby_orchestrator_name` - (String) Name of the standby orchestrator. + * `standby_orchestrator_status` - (String) Status of the standby orchestrator. + * `standby_orchestrator_workspace_name` - (String) Name of the standby orchestrator workspace. + * `transit_gateway_name` - (String) Name of the transit gateway. + * `vpc_name` - (String) Name of the VPC. +* `service_details` - (List) Contains details about the DR automation service. +Nested schema for **service_details**: + * `crn` - (String) Cloud Resource Name identifier. + * `deployment_name` - (String) Name of the deployment. + * `description` - (String) Description of the primary service. + * `is_ksys_ha` - (Boolean) Flag indicating if KSYS HA is enabled. + * `plan_name` - (String) plan name. + * `primary_ip_address` - (String) IP address of the primary service. + * `primary_orchestrator_dashboard_url` - (String) Primary Orchestrator Dashboard URL. + * `recovery_location` - (String) Location for disaster recovery. + * `resource_group` - (String) Resource group name. + * `standby_description` - (String) Description of the standby service. + * `standby_ip_address` - (String) IP address of the standby service. + * `standby_orchestrator_dashboard_url` - (String) Standby Orchestrator Dashboard URL. + * `standby_status` - (String) Current status of the standby service. + * `status` - (String) Current status of the primary service. + diff --git a/website/docs/d/pdr_get_event.html.markdown b/website/docs/d/pdr_get_event.html.markdown new file mode 100755 index 0000000000..c9fdc20168 --- /dev/null +++ b/website/docs/d/pdr_get_event.html.markdown @@ -0,0 +1,50 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_event" +description: |- + Get information about pdr_get_event +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_event + +Provides a read-only data source to retrieve information about a pdr_get_event. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_event" "pdr_get_event" { + event_id = "00116b2a-9326-4024-839e-fb5364b76898" + provision_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `event_id` - (Required, Forces new resource, String) Event ID. +* `provision_id` - (Required, Forces new resource, String) provision id. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_event. +* `action` - (String) Type of action for this event. +* `api_source` - (String) Source of API when it being executed. +* `level` - (String) Level of the event (notice, info, warning, error). + * Constraints: Allowable values are: `notice`, `info`, `warning`, `error`. +* `message` - (String) The (translated) message of the event. +* `message_data` - (Map) A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go). +* `metadata` - (Map) A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go). +* `resource` - (String) Type of resource for this event. +* `time` - (String) Time of activity in ISO 8601 - RFC3339. +* `timestamp` - (String) Time of activity in unix epoch. +* `user` - (List) Information about a user associated with an event. +Nested schema for **user**: + * `email` - (String) Email of the User. + * `name` - (String) Name of the User. + * `user_id` - (String) ID of user who created/caused the event. + diff --git a/website/docs/d/pdr_get_events.html.markdown b/website/docs/d/pdr_get_events.html.markdown new file mode 100755 index 0000000000..151468a0eb --- /dev/null +++ b/website/docs/d/pdr_get_events.html.markdown @@ -0,0 +1,57 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_events" +description: |- + Get information about pdr_get_events +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_events + +Provides a read-only data source to retrieve information about pdr_get_events. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_events" "pdr_get_events" { + from_time = "2025-06-19T00:00:00Z" + provision_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + time = "2025-06-19T23:59:59Z" + to_time = "2025-06-19T23:59:59Z" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `from_time` - (Optional, String) A from query time in either ISO 8601 or unix epoch format. +* `provision_id` - (Required, Forces new resource, String) provision id. +* `time` - (Optional, String) (deprecated - use from_time) A time in either ISO 8601 or unix epoch format. +* `to_time` - (Optional, String) A to query time in either ISO 8601 or unix epoch format. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_events. +* `event` - (List) Events. +Nested schema for **event**: + * `action` - (String) Type of action for this event. + * `api_source` - (String) Source of API when it being executed. + * `event_id` - (String) ID of the Activity. + * `level` - (String) Level of the event (notice, info, warning, error). + * Constraints: Allowable values are: `notice`, `info`, `warning`, `error`. + * `message` - (String) The (translated) message of the event. + * `message_data` - (Map) A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go). + * `metadata` - (Map) A flexible schema placeholder to allow any JSON value (aligns with interface{} in Go). + * `resource` - (String) Type of resource for this event. + * `time` - (String) Time of activity in ISO 8601 - RFC3339. + * `timestamp` - (String) Time of activity in unix epoch. + * `user` - (List) Information about a user associated with an event. + Nested schema for **user**: + * `email` - (String) Email of the User. + * `name` - (String) Name of the User. + * `user_id` - (String) ID of user who created/caused the event. + diff --git a/website/docs/d/pdr_get_grs_location_pairs.html.markdown b/website/docs/d/pdr_get_grs_location_pairs.html.markdown new file mode 100644 index 0000000000..e74c092a83 --- /dev/null +++ b/website/docs/d/pdr_get_grs_location_pairs.html.markdown @@ -0,0 +1,34 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_grs_location_pairs" +description: |- + Get information about pdr_get_grs_location_pairs +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_grs_location_pairs + +Provides a read-only data source to retrieve information about pdr_get_grs_location_pairs. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_grs_location_pairs" "pdr_get_grs_location_pairs" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_grs_location_pairs. +* `location_pairs` - (Map) A map of GRS location pairs where each key is a primary location and the value is its paired location. + diff --git a/website/docs/d/pdr_get_machine_types.html.markdown b/website/docs/d/pdr_get_machine_types.html.markdown new file mode 100755 index 0000000000..7d389ccadb --- /dev/null +++ b/website/docs/d/pdr_get_machine_types.html.markdown @@ -0,0 +1,38 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_machine_types" +description: |- + Get information about pdr_get_machine_types +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_machine_types + +Provides a read-only data source to retrieve information about pdr_get_machine_types. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_machine_types" "pdr_get_machine_types" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + primary_workspace_name = "Test-workspace-wdc06" + standby_workspace_name = "Test-workspace-wdc07" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `primary_workspace_name` - (Required, String) Primary Workspace Name. +* `standby_workspace_name` - (Optional, String) Standby Workspace Name. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_machine_types. +* `workspaces` - (Map) Map of workspace IDs to lists of machine types. + diff --git a/website/docs/d/pdr_get_managed_vm_list.html.markdown b/website/docs/d/pdr_get_managed_vm_list.html.markdown new file mode 100755 index 0000000000..364540d90c --- /dev/null +++ b/website/docs/d/pdr_get_managed_vm_list.html.markdown @@ -0,0 +1,34 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_managed_vm_list" +description: |- + Get information about pdr_get_managed_vm_list +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_managed_vm_list + +Provides a read-only data source to retrieve information about a pdr_get_managed_vm_list. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_managed_vm_list" "pdr_get_managed_vm_list" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_managed_vm_list. +* `managed_vms` - (Map) A map where the key is the VM ID and the value is the corresponding ManagedVmDetails object. + diff --git a/website/docs/d/pdr_get_powervs_workspace.html.markdown b/website/docs/d/pdr_get_powervs_workspace.html.markdown new file mode 100644 index 0000000000..d990f8782c --- /dev/null +++ b/website/docs/d/pdr_get_powervs_workspace.html.markdown @@ -0,0 +1,63 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_get_powervs_workspace" +description: |- + Get information about pdr_get_powervs_workspace +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_get_powervs_workspace + +Provides a read-only data source to retrieve information about a pdr_get_powervs_workspace. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_get_powervs_workspace" "pdr_get_powervs_workspace" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + location_id = "location_id" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `location_id` - (Required, String) Location ID value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_get_powervs_workspace. +* `dr_standby_workspace_description` - (String) Description of Standby Workspace. +* `dr_standby_workspaces` - (List) List of standby disaster recovery workspaces. +Nested schema for **dr_standby_workspaces**: + * `details` - (List) Detailed information of the standby DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the standby workspace. + * `location` - (List) Location information of the standby workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the standby workspace. + * `status` - (String) Current status of the standby workspace. +* `dr_workspace_description` - (String) Description of Workspace. +* `dr_workspaces` - (List) List of primary disaster recovery workspaces. +Nested schema for **dr_workspaces**: + * `default` - (Boolean) Indicates if this is the default DR workspace. + * `details` - (List) Detailed information about the DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the DR workspace. + * `location` - (List) Location information of the DR workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the DR workspace. + * `status` - (String) Current status of the DR workspace. + diff --git a/website/docs/d/pdr_last_operation.html.markdown b/website/docs/d/pdr_last_operation.html.markdown new file mode 100755 index 0000000000..ea6bdc2cbb --- /dev/null +++ b/website/docs/d/pdr_last_operation.html.markdown @@ -0,0 +1,53 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_last_operation" +description: |- + Get information about pdr_last_operation +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_last_operation + +Provides a read-only data source to retrieve information about a pdr_last_operation. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_last_operation" "pdr_last_operation" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_last_operation. +* `crn` - (String) Cloud Resource Name (CRN) of the service instance. +* `deployment_name` - (String) Name of the service instance deployment. +* `is_ksys_ha` - (Boolean) Indicates whether high availability (HA) is enabled for the orchestrator. +* `last_updated_orchestrator_deployment_time` - (String) Deployment time of primary orchestrator VM. +* `last_updated_standby_orchestrator_deployment_time` - (String) Deployment time of StandBy orchestrator VM. +* `mfa_enabled` - (String) Multiple Factor Authentication Enabled or not. +* `orch_ext_connectivity_status` - (String) Status of standby node addition to the orchestrator cluster. +* `orch_standby_node_addtion_status` - (String) Health or informational message about the orchestrator cluster. +* `orchestrator_cluster_message` - (String) Current status of the primary orchestrator VM. +* `orchestrator_config_status` - (String) Configuration status of the orchestrator cluster. +* `plan_name` - (String) Name of the Plan. +* `primary_description` - (String) Detailed status message for the primary orchestrator VM. +* `primary_ip_address` - (String) IP address of the primary orchestrator VM. +* `primary_orchestrator_status` - (String) Configuration status of the orchestrator cluster. +* `recovery_location` - (String) Disaster recovery location associated with the instance. +* `resource_group` - (String) Resource group to which the service instance belongs. +* `standby_description` - (String) Detailed status message for the standby orchestrator VM. +* `standby_ip_address` - (String) IP address of the standby orchestrator VM. +* `standby_status` - (String) Current state of the standby orchestrator VM. +* `status` - (String) Overall status of the service instance. + diff --git a/website/docs/d/pdr_schematic_workspaces.html.markdown b/website/docs/d/pdr_schematic_workspaces.html.markdown new file mode 100644 index 0000000000..d3306a3f1e --- /dev/null +++ b/website/docs/d/pdr_schematic_workspaces.html.markdown @@ -0,0 +1,45 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_schematic_workspaces" +description: |- + Get information about pdr_schematic_workspaces +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_schematic_workspaces + +Provides a read-only data source to retrieve information about pdr_schematic_workspaces. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_schematic_workspaces" "pdr_schematic_workspaces" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_schematic_workspaces. +* `workspaces` - (List) List of Schematics workspaces associated with the DR automation service instance. +Nested schema for **workspaces**: + * `catalog_ref` - (List) Reference to a catalog item associated with the DR automation workspace. + Nested schema for **catalog_ref**: + * `item_name` - (String) Name of the catalog item that defines the resource or configuration. + * `created_at` - (String) Timestamp when the Schematics workspace was created, in ISO 8601 format (UTC). + * `created_by` - (String) CRN of the user or service that created the Schematics workspace. + * `crn` - (String) Cloud Resource Name (CRN) of the Schematics workspace. + * `description` - (String) Detailed description of the Schematics workspace. + * `id` - (String) Unique identifier of the Schematics workspace. + * `location` - (String) Region where the Schematics workspace is hosted. + * `name` - (String) Human-readable name of the Schematics workspace. + * `status` - (String) Current lifecycle status of the Schematics workspace. + diff --git a/website/docs/d/pdr_validate_clustertype.html.markdown b/website/docs/d/pdr_validate_clustertype.html.markdown new file mode 100755 index 0000000000..4c53cc122f --- /dev/null +++ b/website/docs/d/pdr_validate_clustertype.html.markdown @@ -0,0 +1,37 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_validate_clustertype" +description: |- + Get information about pdr_validate_clustertype +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_validate_clustertype + +Provides a read-only data source to retrieve information about a pdr_validate_clustertype. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_validate_clustertype" "pdr_validate_clustertype" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + orchestrator_cluster_type = "on-premises" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `orchestrator_cluster_type` - (Required, String) orchestrator cluster type value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_validate_clustertype. +* `description` - (String) Human-readable message explaining the cluster type validation result. +* `status` - (String) Status of the cluster type validation (for example, valid, invalid, or error). + diff --git a/website/docs/d/pdr_validate_proxyip.html.markdown b/website/docs/d/pdr_validate_proxyip.html.markdown new file mode 100755 index 0000000000..c1d6e6cad8 --- /dev/null +++ b/website/docs/d/pdr_validate_proxyip.html.markdown @@ -0,0 +1,42 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_validate_proxyip" +description: |- + Get information about pdr_validate_proxyip +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_validate_proxyip + +Provides a read-only data source to retrieve information about a pdr_validate_proxyip. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_validate_proxyip" "pdr_validate_proxyip" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + proxyip = "10.30.40.5:3128" + vpc_id = "r006-2f3b3ab9-2149-49cc-83a1-30a5d93d59b2" + vpc_location = "us-south" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `proxyip` - (Required, String) proxyip value. +* `vpc_id` - (Required, String) vpc id value. +* `vpc_location` - (Required, String) vpc location value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_validate_proxyip. +* `description` - (String) Human-readable message explaining the proxy IP validation result. +* `status` - (String) Status of the proxy IP validation (for example, valid, invalid, or error). +* `warning` - (Boolean) Indicates whether the proxy IP is valid but has an advisory (e.g., not in reserved IPs). + * Constraints: The default value is `false`. + diff --git a/website/docs/d/pdr_validate_workspace.html.markdown b/website/docs/d/pdr_validate_workspace.html.markdown new file mode 100755 index 0000000000..2e944e5249 --- /dev/null +++ b/website/docs/d/pdr_validate_workspace.html.markdown @@ -0,0 +1,40 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_validate_workspace" +description: |- + Get information about pdr_validate_workspace +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_validate_workspace + +Provides a read-only data source to retrieve information about a pdr_validate_workspace. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_validate_workspace" "pdr_validate_workspace" { + crn = "crn:v1:bluemix:public:power-iaas:dal10:a/094f4214c75941f991da601b001df1fe:75cbf05b-78f6-406e-afe7-a904f646d798::" + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + location_url = "https://us-south.power-iaas.cloud.ibm.com" + workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `crn` - (Required, String) crn value. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `location_url` - (Required, String) schematic_workspace_id value. +* `workspace_id` - (Required, String) standBy workspaceID value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_validate_workspace. +* `description` - (String) Human-readable message describing the validation result. +* `status` - (String) Status of the workspace validation (for example, Valid, Invalid, or Pending). + diff --git a/website/docs/d/pdr_workspace_custom_vpc.html.markdown b/website/docs/d/pdr_workspace_custom_vpc.html.markdown new file mode 100644 index 0000000000..a2a92af91d --- /dev/null +++ b/website/docs/d/pdr_workspace_custom_vpc.html.markdown @@ -0,0 +1,66 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_workspace_custom_vpc" +description: |- + Get information about pdr_workspace_custom_vpc +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_workspace_custom_vpc + +Provides a read-only data source to retrieve information about a pdr_workspace_custom_vpc. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_workspace_custom_vpc" "pdr_workspace_custom_vpc" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + location_id = "location_id" + tg_id = "925a7b81-a826-4d0a-8ef9-7496e9dc58bc" + vpc_id = "r006-2f3b3ab9-2149-49cc-83a1-30a5d93d59b2" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `location_id` - (Required, String) Location ID value. +* `tg_id` - (Required, String) transit gateway id value. +* `vpc_id` - (Required, String) vpc id value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_workspace_custom_vpc. +* `dr_standby_workspaces` - (List) List of standby disaster recovery workspaces. +Nested schema for **dr_standby_workspaces**: + * `details` - (List) Detailed information of the standby DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the standby workspace. + * `location` - (List) Location information of the standby workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the standby workspace. + * `status` - (String) Current status of the standby workspace. +* `dr_workspaces` - (List) List of primary disaster recovery workspaces. +Nested schema for **dr_workspaces**: + * `default` - (Boolean) Indicates if this is the default DR workspace. + * `details` - (List) Detailed information about the DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the DR workspace. + * `location` - (List) Location information of the DR workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the DR workspace. + * `status` - (String) Current status of the DR workspace. + diff --git a/website/docs/d/pdr_workspace_schematic.html.markdown b/website/docs/d/pdr_workspace_schematic.html.markdown new file mode 100644 index 0000000000..731c62bd76 --- /dev/null +++ b/website/docs/d/pdr_workspace_schematic.html.markdown @@ -0,0 +1,65 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_workspace_schematic" +description: |- + Get information about pdr_workspace_schematic +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_workspace_schematic + +Provides a read-only data source to retrieve information about a pdr_workspace_schematic. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_pdr_workspace_schematic" "pdr_workspace_schematic" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" + location_id = "location_id" + schematic_id = "us-south.workspace.projects-service.3ae96a02" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `location_id` - (Required, String) Location ID value. +* `schematic_id` - (Required, String) Schematic ID value. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the pdr_workspace_schematic. +* `dr_standby_workspace_description` - (String) Description of Standby Workspace. +* `dr_standby_workspaces` - (List) List of standby disaster recovery workspaces. +Nested schema for **dr_standby_workspaces**: + * `details` - (List) Detailed information of the standby DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the standby workspace. + * `location` - (List) Location information of the standby workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the standby workspace. + * `status` - (String) Current status of the standby workspace. +* `dr_workspace_description` - (String) Description of Workspace. +* `dr_workspaces` - (List) List of primary disaster recovery workspaces. +Nested schema for **dr_workspaces**: + * `default` - (Boolean) Indicates if this is the default DR workspace. + * `details` - (List) Detailed information about the DR workspace. + Nested schema for **details**: + * `crn` - (String) Cloud Resource Name (CRN) of the DR workspace. + * `id` - (String) Unique identifier of the DR workspace. + * `location` - (List) Location information of the DR workspace. + Nested schema for **location**: + * `region` - (String) The region identifier of the DR location. + * `type` - (String) The type of location (e.g., data-center, cloud-region). + * `url` - (String) The URL endpoint to access the DR location. + * `name` - (String) Name of the DR workspace. + * `status` - (String) Current status of the DR workspace. + diff --git a/website/docs/r/pdr_managedr.html.markdown b/website/docs/r/pdr_managedr.html.markdown new file mode 100755 index 0000000000..bdfcbc28ec --- /dev/null +++ b/website/docs/r/pdr_managedr.html.markdown @@ -0,0 +1,240 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_managedr" +description: |- + Manages pdr_managedr. +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_managedr + +Create, update, and delete pdr_managedrs with this resource. + +## Example Usage + +```hcl +resource "ibm_pdr_managedr" "pdr_managedr_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this resource. + +* `accept_language` - (Optional, Forces new resource, String) The language requested for the return document. +* `accepts_incomplete` - (Optional, Forces new resource, Boolean) A value of true indicates that both the IBM Cloud platform and the requesting client support asynchronous deprovisioning. + * Constraints: The default value is `true`. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. +* `stand_by_redeploy` - (Optional, Forces new resource, String) Flag to indicate if standby should be redeployed (must be "true" or "false"). + +## Attribute Reference + +After your resource is created, you can read values from the listed arguments and the following attributes. + +* `id` - The unique identifier of the pdr_managedr. +* `dashboard_url` - (String) URL to the dashboard for managing the DR service instance in IBM Cloud. +* `instance_id` - (String) The CRN (Cloud Resource Name) of the DR service instance. + +* `etag` - ETag identifier for pdr_managedr. + +## Import + +You can import the `ibm_pdr_managedr` resource by using `id`. +The `id` property can be formed from `instance_id`, and `instance_id` in the following format: + +
+<instance_id>/<instance_id>
+
+* `instance_id`: A string in the format `crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::`. instance id of instance to provision. +* `instance_id`: A string in the format `crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::`. The CRN (Cloud Resource Name) of the DR service instance. + +# Syntax +
+$ terraform import ibm_pdr_managedr.pdr_managedr <instance_id>/<instance_id>
+
+ + + +# ================================================================================================== + # HA Cases +# ================================================================================================== +# Case 1: ManageDR with HA + schematic id + sshkey +# provider "ibm" { +# region = "us-south" +# } + +# resource "ibm_power_vs_ssh_key" "vijaykey" { +# name = "vijaykey" +# public_key = file("~/.ssh/id_rsa.pub") +# } + +# resource "ibm_drautomation_service_instance" "ha_dr_instance" { + # name = "service1234" + # crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" + # enable_flag = false + # dr_location_id = "dal10" + # dr_orchestrator_name = "drautomationprimary7a" + # dr_orchestrator_password = "Password1234567" + # dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" + # machine_type = "s922" + # orchestrator_cluster_type = "off-premises" + # schematic_workspace_id = "us-south.workspace.projects-service.3ae96a02" + # ssh_key_name = ibm_power_vs_ssh_key.vijaykey.name + # standby_machine_type = "s922" + # standby_orchestrator_name = "drautomationstandby7a" + # standby_orchestrator_workspace_id = "71027b79-0e31-44f6-a499-63eca1a66feb" + # tier = "tier1" +# } + +# ================================================================================================ + +# Case 2: ManageDR with HA + custom VPC + sshkey + +# resource "ibm_drautomation_service_instance" "ha_dr_instance" { + # name = "service1234" + # crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" + # enable_flag = false + # dr_location_id = "dal10" + # dr_orchestrator_name = "drautomationprimary7a" + # dr_orchestrator_password = "Password1234567" + # dr_orchestrator_workspace_id = "75cbf05904f646d798" + # machine_type = "s922" + # orchestrator_cluster_type = "off-premises" + # ssh_key_name = ibm_power_vs_ssh_key.vijaykey.name + # standby_machine_type = "s922" + # standby_orchestrator_name = "drautomationstandby7a" + # standby_orchestrator_workspace_id = "71027b79-0e31-44f6-a499-63eca1a66feb" + # tier = "tier1" +# } + +# ================================================================================================== + +# Case 3: ManageDR with HA + schematic id + secrets + +# resource "ibm_drautomation_service_instance" "ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Consider using a variable or secret reference +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# schematic_workspace_id = "us-south.workspace.projects-service.3ae96a02" +# secret_group = "secret_group id" +# secret = "secret id" +# region_id = "us-south" +# guid = "gu id" +# standby_machine_type = "s922" +# standby_orchestrator_name = "drautomationstandby7a" +# standby_orchestrator_workspace_id = "71027b79-0e31-44f6-a499-63eca1a66feb" +# tier = "tier1" +# } + +# ================================================================================================== + +# Case 4: ManageDR with HA + custom VPC + secrets + +# resource "ibm_drautomation_service_instance" "ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Use a variable or secret reference in production +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# secret_group = "secret_group id" +# secret = "secret id" +# region_id = "us-south" +# guid = "gu id" +# standby_machine_type = "s922" +# standby_orchestrator_name = "drautomationstandby7a" +# standby_orchestrator_workspace_id = "71027b79-0e31-44f6-a499-63eca1a66feb" +# tier = "tier1" +# } + +# ================================================================================================== + # Non-HA Cases +# ================================================================================================== + +# Case 1: ManageDR without HA + schematic id + sshkey +# resource "ibm_drautomation_service_instance" "non_ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Use a variable or secret reference in production +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# schematic_workspace_id = "us-south.workspace.projects-service.3ae96a02" +# ssh_key_name = ibm_power_vs_ssh_key.vijaykey.name +# tier = "tier1" +# } + +# ================================================================================================== + +# Case 2: ManageDR without HA + custom VPC + sshkey +# resource "ibm_drautomation_service_instance" "non_ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Use a variable or secret reference in production +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# ssh_key_name = ibm_power_vs_ssh_key.vijaykey.name +# tier = "tier1" +# } + +# ================================================================================================== + +# Case 3: ManageDR without HA + schematic id + secrets +# resource "ibm_drautomation_service_instance" "non_ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false# +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Use a variable or secret reference in production +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# schematic_workspace_id = "us-south.workspace.projects-service.3ae96a02" +# secret_group = "secret_group id" +# secret = "secret id" +# region_id = "us-south" +# guid = "gu id" +# tier = "tier1" +# } + +# ================================================================================================== + +# Case 4: ManageDR without HA + custom VPC + secrets +# resource "ibm_drautomation_service_instance" "non_ha_dr_instance" { +# name = "service1234" +# crn = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf7::" +# enable_flag = false# +# dr_location_id = "dal10" +# dr_orchestrator_name = "drautomationprimary7a" +# dr_orchestrator_password = "Password1234567" # Use a variable or secret reference in production +# dr_orchestrator_workspace_id = "75cbf05b-78f6-406e-afe7-a904f646d798" +# machine_type = "s922" +# orchestrator_cluster_type = "off-premises" +# secret_group = "secret_group id" +# secret = "secret id" +# region_id = "us-south" +# guid = "gu id" +# tier = "tier1" +# } + + +# ================================================================================ + diff --git a/website/docs/r/pdr_validate_apikey.html.markdown b/website/docs/r/pdr_validate_apikey.html.markdown new file mode 100755 index 0000000000..73ed665afe --- /dev/null +++ b/website/docs/r/pdr_validate_apikey.html.markdown @@ -0,0 +1,53 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_pdr_validate_apikey" +description: |- + Manages pdr_validate_apikey. +subcategory: "DrAutomation Service" +--- + +# ibm_pdr_validate_apikey + +Create, update, and delete pdr_validate_apikeys with this resource. + +## Example Usage + +```hcl +resource "ibm_pdr_validate_apikey" "pdr_validate_apikey_instance" { + instance_id = "crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::" +} +``` + +## Argument Reference + +You can specify the following arguments for this resource. + +* `accept_language` - (Optional, String) The language requested for the return document. +* `instance_id` - (Required, Forces new resource, String) instance id of instance to provision. + +## Attribute Reference + +After your resource is created, you can read values from the listed arguments and the following attributes. + +* `id` - The unique identifier of the pdr_validate_apikey. +* `description` - (String) Validation result message. +* `instance_id` - (String) Unique identifier of the API key. +* `status` - (String) Status of the API key. + +* `etag` - ETag identifier for pdr_validate_apikey. + +## Import + +You can import the `ibm_pdr_validate_apikey` resource by using `id`. +The `id` property can be formed from `instance_id`, and `instance_id` in the following format: + +
+<instance_id>/<instance_id>
+
+* `instance_id`: A string in the format `crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::`. instance id of instance to provision. +* `instance_id`: A string in the format `crn:v1:staging:public:power-dr-automation:global:a/a123456fb04ceebfb4a9fd38c22334455:123456d3-1122-3344-b67d-4389b44b7bf9::`. Unique identifier of the API key. + +# Syntax +
+$ terraform import ibm_pdr_validate_apikey.pdr_validate_apikey <instance_id>/<instance_id>
+