Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO RC SDK v2 migration #5214

Merged
merged 2 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/IBM/eventstreams-go-sdk v1.4.0
github.com/IBM/go-sdk-core/v3 v3.2.4
github.com/IBM/go-sdk-core/v5 v5.16.1
github.com/IBM/ibm-cos-sdk-go v1.10.0
github.com/IBM/ibm-cos-sdk-go-config v1.2.0
github.com/IBM/ibm-cos-sdk-go v1.10.1
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.0.4
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta
github.com/IBM/keyprotect-go-client v0.12.2
Expand Down Expand Up @@ -62,6 +62,7 @@ require (
)

require (
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/mqcloud-go-sdk v0.0.4
github.com/IBM/sarama v1.41.2
k8s.io/utils v0.0.0-20230313181309-38a27ef9d749
Expand Down
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ github.com/IBM/event-notifications-go-admin-sdk v0.4.0 h1:7nqtybv8GNVjuB5QBfx/ke
github.com/IBM/event-notifications-go-admin-sdk v0.4.0/go.mod h1:m6WD+q9AHJhybK929vOK8Kfx4BsKO7AmROKRpR2uQP8=
github.com/IBM/eventstreams-go-sdk v1.4.0 h1:yS/Ns29sBOe8W2tynQmz9HTKqQZ0ckse4Py5Oy/F2rM=
github.com/IBM/eventstreams-go-sdk v1.4.0/go.mod h1:2tuAxaYLctfqfr5jvyqSrxxEQGMwYPm3yJGWSj85YVQ=
github.com/IBM/go-sdk-core/v3 v3.0.0/go.mod h1:JI5NS2+iCoY/D8Oq3JNEZNA7qO42agu6fnaUmDsRcJA=
github.com/IBM/go-sdk-core v1.1.0 h1:pV73lZqr9r1xKb3h08c1uNG3AphwoV5KzUzhS+pfEqY=
github.com/IBM/go-sdk-core v1.1.0/go.mod h1:2pcx9YWsIsZ3I7kH+1amiAkXvLTZtAq9kbxsfXilSoY=
github.com/IBM/go-sdk-core/v3 v3.2.4 h1:WKYJYYKlZnw1y/gM+Qbf5EQVAL9xaoD54+ooJZz/iBQ=
github.com/IBM/go-sdk-core/v3 v3.2.4/go.mod h1:lk9eOzNbNltPf3CBpcg1Ewkhw4qC3u2QCCKDRsUA2M0=
github.com/IBM/go-sdk-core/v5 v5.0.0/go.mod h1:vyNdbFujJtdTj9HbihtvKwwS3k/GKSKpOx9ZIQ6MWDY=
Expand All @@ -142,11 +143,10 @@ github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV
github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2ywAPwW4VJjdI=
github.com/IBM/go-sdk-core/v5 v5.16.1 h1:vAgOxRvaXD5AmgwR7dlstjT1JFE4BA4lPcGsEFZOKGs=
github.com/IBM/go-sdk-core/v5 v5.16.1/go.mod h1:aojBkkq4HXkOYdn7YZ6ve8cjPWHdcB3tt8v0b9Cbac8=
github.com/IBM/ibm-cos-sdk-go v1.3.1/go.mod h1:YLBAYobEA8bD27P7xpMwSQeNQu6W3DNBtBComXrRzRY=
github.com/IBM/ibm-cos-sdk-go v1.10.0 h1:/2VIev2/jBei39OqU2+nSZQnoWJ+KtkiSAIDkqsd7uU=
github.com/IBM/ibm-cos-sdk-go v1.10.0/go.mod h1:C8KRTRaoD3CWPPBOa6FCOpdh0ZMlUjKAAA4i3F+Q/sc=
github.com/IBM/ibm-cos-sdk-go-config v1.2.0 h1:1E93234yZgVS0ntm7eUwVb3h0AAayPGcxEhhizEN1LE=
github.com/IBM/ibm-cos-sdk-go-config v1.2.0/go.mod h1:Wetfgv6m1xyuzpZLQTTLIBsWstxjYa15h+Utj7x53Dk=
github.com/IBM/ibm-cos-sdk-go v1.10.1 h1:vQCsu61OHRVF2lL6ah+m3AmUlhnYGkI1qogukCEFULs=
github.com/IBM/ibm-cos-sdk-go v1.10.1/go.mod h1:zhcgfL2YG5DVaI5R2F6oYO2DYnvwW14vpcpFq+ybhXU=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.0.4 h1:fvy/cMKn/3BngdxaL5dXaSlUuzTANY42VuVQuW0NEYE=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.0.4/go.mod h1:Pam4aWm9Ve/pqAVrPW8nm2yCXq0h9LDeQ1Iacx5g9rU=
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1 h1:T5UwRKKd+BoaPZ7UIlpJrzXzVTUEs8HcxwQ3pCIbORs=
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1/go.mod h1:M2JyuyeWHPtgGNeezr6YqVRuaav2MpY8Ha4QrEYvMoI=
github.com/IBM/ibm-hpcs-uko-sdk v0.0.20-beta h1:P1fdIfKsD9xvJQ5MHIEztPS9yfNf9x+VDTamaYcmqcs=
Expand Down Expand Up @@ -1222,7 +1222,6 @@ github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0/go.mod h1:oUhWkIvk5aDxtKvDDuw8gItl8pKl42LzjC9KZE0HfGg=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
Expand Down
2 changes: 1 addition & 1 deletion ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5"
"github.com/IBM/container-registry-go-sdk/containerregistryv1"
"github.com/IBM/go-sdk-core/v5/core"
cosconfig "github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1"
cosconfig "github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
kp "github.com/IBM/keyprotect-go-client"
"github.com/IBM/mqcloud-go-sdk/mqcloudv1"
cisalertsv1 "github.com/IBM/networking-go-sdk/alertsv1"
Expand Down
2 changes: 1 addition & 1 deletion ibm/flex/structures.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM/cloud-databases-go-sdk/clouddatabasesv5"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/service/s3"
kp "github.com/IBM/keyprotect-go-client"
Expand Down
13 changes: 4 additions & 9 deletions ibm/service/cos/data_source_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"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/ibm-cos-sdk-go-config/resourceconfigurationv1"
rcsdk "github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam"
token "github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam/token"
Expand Down Expand Up @@ -707,16 +707,10 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error
d.Set("s3_endpoint_public", apiEndpoint)
d.Set("s3_endpoint_private", apiEndpointPrivate)
d.Set("s3_endpoint_direct", directApiEndpoint)

getBucketConfigOptions := &resourceconfigurationv1.GetBucketConfigOptions{
Bucket: &bucketName,
}

sess, err := meta.(conns.ClientSession).CosConfigV1API()
if err != nil {
return err
}

if endpointType == "private" {
sess.SetServiceURL("https://config.private.cloud-object-storage.cloud.ibm.com/v1")
}
Expand All @@ -728,10 +722,11 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error
satconfig := fmt.Sprintf("https://config.%s.%s.cloud-object-storage.appdomain.cloud/v1", serviceID, satlc_id)

sess.SetServiceURL(satconfig)

}

bucketPtr, response, err := sess.GetBucketConfig(getBucketConfigOptions)
getOptions := new(rcsdk.GetBucketConfigOptions)
getOptions.SetBucket(bucketName)
bucketPtr, response, err := sess.GetBucketConfig(getOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error in getting bucket info rule: %s\n%s", err, response)
}
Expand Down
48 changes: 27 additions & 21 deletions ibm/service/cos/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"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/ibm-cos-sdk-go-config/resourceconfigurationv1"
"github.com/IBM/go-sdk-core/core"
rcsdk "github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam"
token "github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam/token"
Expand Down Expand Up @@ -936,19 +937,18 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
}

hasChanged := false
updateBucketConfigOptions := &resourceconfigurationv1.UpdateBucketConfigOptions{}

//BucketName
bucketName = d.Get("bucket_name").(string)
updateBucketConfigOptions.Bucket = &bucketName

bucketPatchModel := new(rcsdk.BucketPatch)
if d.HasChange("hard_quota") {
hasChanged = true
updateBucketConfigOptions.HardQuota = aws.Int64(int64(d.Get("hard_quota").(int)))
bucketPatchModel.HardQuota = core.Int64Ptr(int64(d.Get("hard_quota").(int)))

}

if d.HasChange("allowed_ip") {
firewall := &resourceconfigurationv1.Firewall{}
firewall := &rcsdk.Firewall{}
var ips = make([]string, 0)
if ip, ok := d.GetOk("allowed_ip"); ok && ip != nil {
for _, i := range ip.([]interface{}) {
Expand All @@ -959,11 +959,11 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
firewall.AllowedIp = []string{}
}
hasChanged = true
updateBucketConfigOptions.Firewall = firewall
bucketPatchModel.Firewall = firewall
}

if d.HasChange("activity_tracking") {
activityTracker := &resourceconfigurationv1.ActivityTracking{}
activityTracker := &rcsdk.ActivityTracking{}
if activity, ok := d.GetOk("activity_tracking"); ok {
activitylist := activity.([]interface{})
for _, l := range activitylist {
Expand All @@ -987,11 +987,12 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
}
}
hasChanged = true
updateBucketConfigOptions.ActivityTracking = activityTracker
bucketPatchModel.ActivityTracking = activityTracker

}

if d.HasChange("metrics_monitoring") {
metricsMonitor := &resourceconfigurationv1.MetricsMonitoring{}
metricsMonitoring := &rcsdk.MetricsMonitoring{}
if metrics, ok := d.GetOk("metrics_monitoring"); ok {
metricslist := metrics.([]interface{})
for _, l := range metricslist {
Expand All @@ -1000,24 +1001,32 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
//metrics enabled - as its optional check for existence
if metricsSet := metricsMap["usage_metrics_enabled"]; metricsSet != nil {
metrics := metricsSet.(bool)
metricsMonitor.UsageMetricsEnabled = &metrics
metricsMonitoring.UsageMetricsEnabled = &metrics
}
// request metrics enabled - as its optional check for existence
if metricsSet := metricsMap["request_metrics_enabled"]; metricsSet != nil {
metrics := metricsSet.(bool)
metricsMonitor.RequestMetricsEnabled = &metrics
metricsMonitoring.RequestMetricsEnabled = &metrics
}
//crn - Required field
crn := metricsMap["metrics_monitoring_crn"].(string)
metricsMonitor.MetricsMonitoringCrn = &crn
metricsMonitoring.MetricsMonitoringCrn = &crn
}
}
hasChanged = true
updateBucketConfigOptions.MetricsMonitoring = metricsMonitor
bucketPatchModel.MetricsMonitoring = metricsMonitoring

}

if hasChanged {
response, err := sess.UpdateBucketConfig(updateBucketConfigOptions)
bucketPatchModelAsPatch, asPatchErr := bucketPatchModel.AsPatch()
if asPatchErr != nil {
return fmt.Errorf("[ERROR] Error Update COS Bucket: %s\n%s", err, bucketPatchModelAsPatch)
}
setOptions := new(rcsdk.UpdateBucketConfigOptions)
setOptions.SetBucket(bucketName)
setOptions.BucketPatch = bucketPatchModelAsPatch
response, err := sess.UpdateBucketConfig(setOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error Update COS Bucket: %s\n%s", err, response)
}
Expand Down Expand Up @@ -1145,11 +1154,6 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
if endpointType != "" {
d.Set("endpoint_type", endpointType)
}

getBucketConfigOptions := &resourceconfigurationv1.GetBucketConfigOptions{
Bucket: &bucketName,
}

sess, err := meta.(conns.ClientSession).CosConfigV1API()
if err != nil {
return err
Expand All @@ -1168,7 +1172,9 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
sess.SetServiceURL(satconfig)
}

bucketPtr, response, err := sess.GetBucketConfig(getBucketConfigOptions)
getOptions := new(rcsdk.GetBucketConfigOptions)
getOptions.SetBucket(bucketName)
bucketPtr, response, err := sess.GetBucketConfig(getOptions)
if err != nil {
return fmt.Errorf("[ERROR] Error in getting bucket info rule: %s\n%s", err, response)
}
Expand Down
Loading