Skip to content

Commit 31d1d19

Browse files
authored
Support Schematics replatform for COS resources (IBM-Cloud#6504)
1 parent fbe9b51 commit 31d1d19

6 files changed

+52
-5
lines changed

ibm/service/cos/resource_ibm_cos_bucket.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"log"
10+
"os"
1011
"regexp"
1112
"strings"
1213
"time"
@@ -1791,7 +1792,13 @@ func parseBucketId(id string, info string) string {
17911792
if info == "endpointType" {
17921793
s := strings.Split(meta, ":")
17931794
if len(s) > 2 {
1794-
return strings.Split(meta, ":")[2]
1795+
eType := strings.Split(meta, ":")[2]
1796+
// This changes is only for Schematics
1797+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
1798+
if eType != "" && eType == "private" && schET != "" {
1799+
return schET
1800+
}
1801+
return eType
17951802
}
17961803
return ""
17971804

ibm/service/cos/resource_ibm_cos_bucket_lifecycle_configuration.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
// "encoding/json"
55
"context"
66
"fmt"
7+
"os"
78
"strings"
89
"time"
910

@@ -649,7 +650,13 @@ func parseLifecycleId(id string, info string) string {
649650
return strings.Split(meta, ":")[0]
650651
}
651652
if info == "endpointType" {
652-
return strings.Split(meta, ":")[1]
653+
eType := strings.Split(meta, ":")[1]
654+
// This changes is only for Schematics
655+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
656+
if eType != "" && eType == "private" && schET != "" {
657+
return schET
658+
}
659+
return eType
653660
}
654661
if info == "keyName" {
655662
return strings.Split(meta, ":key:")[1]

ibm/service/cos/resource_ibm_cos_bucket_object.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ func resourceIBMCOSBucketObjectRead(ctx context.Context, d *schema.ResourceData,
262262
bucketLocation := parseObjectId(objectID, "bucketLocation")
263263
instanceCRN := parseObjectId(objectID, "instanceCRN")
264264
endpointType := d.Get("endpoint_type").(string)
265+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
266+
if endpointType != "" && endpointType == "private" && schET != "" {
267+
endpointType = schET
268+
}
265269

266270
d.Set("bucket_crn", bucketCRN)
267271
d.Set("bucket_location", bucketLocation)
@@ -353,6 +357,10 @@ func resourceIBMCOSBucketObjectUpdate(ctx context.Context, d *schema.ResourceDat
353357
objectKey := d.Get("key").(string)
354358
bucketLocation := d.Get("bucket_location").(string)
355359
endpointType := d.Get("endpoint_type").(string)
360+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
361+
if endpointType != "" && endpointType == "private" && schET != "" {
362+
endpointType = schET
363+
}
356364
bxSession, err := m.(conns.ClientSession).BluemixSession()
357365
if err != nil {
358366
return diag.FromErr(err)
@@ -452,6 +460,10 @@ func resourceIBMCOSBucketObjectDelete(ctx context.Context, d *schema.ResourceDat
452460

453461
bucketLocation := d.Get("bucket_location").(string)
454462
endpointType := d.Get("endpoint_type").(string)
463+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
464+
if endpointType != "" && endpointType == "private" && schET != "" {
465+
endpointType = schET
466+
}
455467

456468
bxSession, err := m.(conns.ClientSession).BluemixSession()
457469
if err != nil {

ibm/service/cos/resource_ibm_cos_bucket_objectlock_configuration.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cos
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67
"time"
78

@@ -260,7 +261,13 @@ func parseObjectLockId(id string, info string) string {
260261
return strings.Split(meta, ":")[0]
261262
}
262263
if info == "endpointType" {
263-
return strings.Split(meta, ":")[1]
264+
eType := strings.Split(meta, ":")[1]
265+
// This changes is only for Schematics
266+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
267+
if eType != "" && eType == "private" && schET != "" {
268+
return schET
269+
}
270+
return eType
264271
}
265272
if info == "keyName" {
266273
return strings.Split(meta, ":key:")[1]

ibm/service/cos/resource_ibm_cos_bucket_website_configuration.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cos
33
import (
44
"encoding/json"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -494,7 +495,13 @@ func parseWebsiteId(id string, info string) string {
494495
return strings.Split(meta, ":")[0]
495496
}
496497
if info == "endpointType" {
497-
return strings.Split(meta, ":")[1]
498+
eType := strings.Split(meta, ":")[1]
499+
// This changes is only for Schematics
500+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
501+
if eType != "" && eType == "private" && schET != "" {
502+
return schET
503+
}
504+
return eType
498505
}
499506
if info == "keyName" {
500507
return strings.Split(meta, ":key:")[1]

ibm/service/cos/resource_ibm_cos_replication_configuration.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cos
33
import (
44
"bytes"
55
"fmt"
6+
"os"
67
"strings"
78
"time"
89

@@ -328,7 +329,13 @@ func parseBucketReplId(id string, info string) string {
328329
return strings.Split(meta, ":")[0]
329330
}
330331
if info == "endpointType" {
331-
return strings.Split(meta, ":")[1]
332+
eType := strings.Split(meta, ":")[1]
333+
// This changes is only for Schematics
334+
schET := os.Getenv("IBMCLOUD_ENV_SCH_COS_ENDPOINT_OVERRIDE")
335+
if eType != "" && eType == "private" && schET != "" {
336+
return schET
337+
}
338+
return eType
332339
}
333340

334341
return parseBucketId(bucketCRN, info)

0 commit comments

Comments
 (0)