Skip to content

Commit f25fc2b

Browse files
authored
Add instance and region update in connection token resource (IBM-Cloud#6566)
* update code * update doc
1 parent a676c51 commit f25fc2b

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

ibm/service/backuprecovery/resource_ibm_backup_recovery_connection_registration_token.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,51 @@ func checkDiffResourceIbmBackupRecoveryConnectionRegistrationToken(context conte
7474
func resourceIbmBackupRecoveryConnectionRegistrationTokenCreate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
7575
backupRecoveryClient, err := meta.(conns.ClientSession).BackupRecoveryV1()
7676
if err != nil {
77-
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_backup_recovery_connection_registration_token", "read", "initialize-client")
77+
tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_backup_recovery_connection_registration_token", "create", "initialize-client")
7878
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
7979
return tfErr.GetDiag()
8080
}
8181

82+
endpointType := d.Get("endpoint_type").(string)
83+
instanceId, region := getInstanceIdAndRegion(d)
84+
if instanceId != "" && region != "" {
85+
bmxsession, err := meta.(conns.ClientSession).BluemixSession()
86+
if err != nil {
87+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("unable to get clientSession"), "ibm_backup_recovery_connection_registration_token", "create")
88+
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
89+
return tfErr.GetDiag()
90+
}
91+
backupRecoveryClient = getClientWithInstanceEndpoint(backupRecoveryClient, bmxsession, instanceId, region, endpointType)
92+
}
93+
8294
generateDataSourceConnectionRegistrationTokenOptions := &backuprecoveryv1.GenerateDataSourceConnectionRegistrationTokenOptions{}
8395

8496
generateDataSourceConnectionRegistrationTokenOptions.SetConnectionID(d.Get("connection_id").(string))
8597
generateDataSourceConnectionRegistrationTokenOptions.SetXIBMTenantID(d.Get("x_ibm_tenant_id").(string))
8698

8799
connectionRegistrationTokenString, _, err := backupRecoveryClient.GenerateDataSourceConnectionRegistrationTokenWithContext(context, generateDataSourceConnectionRegistrationTokenOptions)
88100
if err != nil {
89-
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GenerateDataSourceConnectionRegistrationTokenWithContext failed: %s", err.Error()), "ibm_backup_recovery_connection_registration_token", "read")
101+
tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GenerateDataSourceConnectionRegistrationTokenWithContext failed: %s", err.Error()), "ibm_backup_recovery_connection_registration_token", "create")
90102
log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage())
91103
return tfErr.GetDiag()
92104
}
93105

106+
if instanceId != "" {
107+
if err := d.Set("instance_id", instanceId); err != nil {
108+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting instance_id: %s", err), "(Resource) ibm_backup_recovery_connection_registration_token", "create", "set-instance-id").GetDiag()
109+
}
110+
}
111+
if region != "" {
112+
if err := d.Set("region", region); err != nil {
113+
return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting region: %s", err), "(Resource) ibm_backup_recovery_connection_registration_token", "create", "set-region").GetDiag()
114+
}
115+
}
116+
117+
if err = d.Set("endpoint_type", d.Get("endpoint_type").(string)); err != nil {
118+
err = fmt.Errorf("Error setting endpoint_type: %s", err)
119+
return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_backup_recovery_connection_registration_token", "create", "set-endpoint-type").GetDiag()
120+
}
121+
94122
d.SetId(resourceIbmBackupRecoveryConnectionRegistrationTokenID(d))
95123

96124
if !core.IsNil(connectionRegistrationTokenString) {

website/docs/r/backup_recovery_source_registration.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Nested schema for **connections**:
103103
* `connector_group_id` - (Optional, Integer) Specifies the connector group id of connector groups.
104104
* `data_source_connection_id` - (Optional, String) Specifies the id of the connection from where this source is reachable. This should only be set for a source being registered by a tenant user. Also, this is the 'string' of connectionId. This property was added to accommodate for ID values that exceed 2^53 - 1, which is the max value for which JS maintains precision.
105105
* `environment` - (Required, String) Specifies the environment type of the Protection Source.
106-
* Constraints: Allowable values are: `kPhysical`, `kSQL`.
106+
* Constraints: Allowable values are: `kPhysical`, `kSQL`, `kKubernetes`.
107107
* `kubernetes_params` - (Optional, List) Specifies the parameters to register a Kubernetes source.
108108
Nested schema for **kubernetes_params**:
109109
* `auto_protect_config` - (Optional, List) Specifies the parameters to auto protect the source after registration.

0 commit comments

Comments
 (0)