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

Adding changes for COS bucket backup #5794

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ require (
github.com/IBM/go-sdk-core v1.1.0
github.com/IBM/go-sdk-core/v3 v3.2.4
github.com/IBM/go-sdk-core/v5 v5.18.1
github.com/IBM/ibm-cos-sdk-go v1.10.3
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.1.0
github.com/IBM/ibm-cos-sdk-go v1.12.0
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.2.0
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.15.1
Expand Down Expand Up @@ -62,8 +62,8 @@ require (
github.com/pkg/errors v0.9.1
github.com/rook/rook v1.11.4
github.com/softlayer/softlayer-go v1.0.3
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.28.0
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.29.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
k8s.io/api v0.26.3
Expand Down Expand Up @@ -216,12 +216,12 @@ require (
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.25.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
Expand Down
35 changes: 18 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,10 @@ github.com/IBM/go-sdk-core/v5 v5.10.2/go.mod h1:WZPFasUzsKab/2mzt29xPcfruSk5js2y
github.com/IBM/go-sdk-core/v5 v5.17.4/go.mod h1:KsAAI7eStAWwQa4F96MLy+whYSh39JzNjklZRbN/8ns=
github.com/IBM/go-sdk-core/v5 v5.18.1 h1:wdftQO8xejECTWTKF3FGXyW0McKxxDAopH7MKwA187c=
github.com/IBM/go-sdk-core/v5 v5.18.1/go.mod h1:3ywpylZ41WhWPusqtpJZWopYlt2brebcphV7mA2JncU=
github.com/IBM/ibm-cos-sdk-go v1.10.3 h1:YfZSLqMiCrqDPbr3r+amY2sicIXlrd+3L5pok6QRXIQ=
github.com/IBM/ibm-cos-sdk-go v1.10.3/go.mod h1:T9x7pC47DUd5jD/TMFzlvly39P6EdW5wOemA78XEo2g=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.1.0 h1:U7EmXSfv7jtugRpTpOkPUmgS/xiNKtGfKVH3BGyC1hg=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.1.0/go.mod h1:vMQ0DKpyoPk1MstfipPBoLfFxl3HWjzG/wH/UVg/xiU=
github.com/IBM/ibm-cos-sdk-go v1.12.0 h1:Wrk3ve4JS3euhl7XjNFd3RlvPT56199G2/rKaPWpRKU=
github.com/IBM/ibm-cos-sdk-go v1.12.0/go.mod h1:v/VBvFuysZMIX9HcaIrz6a+FLVw9px8fq6XabFwD+E4=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.2.0 h1:H5XSKuOEf+z+506ITq3FSXhFNBaZt7OLpH4OTQGcNXw=
github.com/IBM/ibm-cos-sdk-go-config/v2 v2.2.0/go.mod h1:ci4tI9mIZEtN6cenuVN9RWyNJu8CkWHmYH758K2lVEQ=
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 @@ -1625,8 +1625,9 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tencentcloud/tencentcloud-sdk-go v3.0.171+incompatible h1:K3fcS92NS8cRntIdu8Uqy2ZSePvX73nNhOkKuPGJLXQ=
github.com/tencentcloud/tencentcloud-sdk-go v3.0.171+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4=
Expand Down Expand Up @@ -1790,8 +1791,8 @@ golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ=
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -1918,8 +1919,8 @@ golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/net v0.31.0 h1:68CPQngjLL0r2AlUKiSxtQFKvzRVbnzLwMUn5SzcLHo=
golang.org/x/net v0.31.0/go.mod h1:P4fl1q7dY2hnZFxEk4pPSkDHF+QqjitcnDjUQyMM+pM=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1957,8 +1958,8 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -2070,8 +2071,8 @@ golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -2090,8 +2091,8 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand All @@ -2114,8 +2115,8 @@ golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug=
golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
19 changes: 19 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ var (
CisResourceGroup string
CloudShellAccountID string
CosCRN string
CosBackupPolicyID string
BucketCRN string
BackupVaultName string
ActivityTrackerInstanceCRN string
MetricsMonitoringCRN string
KmsKeyCrn string
BucketName string
CosName string
Ibmid1 string
Expand Down Expand Up @@ -576,6 +579,22 @@ func init() {
BucketCRN = ""
fmt.Println("[WARN] Set the environment variable IBM_COS_Bucket_CRN with a VALID BUCKET CRN for testing ibm_cos_bucket* resources")
}
BackupVaultName = os.Getenv("IBM_COS_Backup_Vault")
if BackupVaultName == "" {
BackupVaultName = ""
fmt.Println("[WARN] Set the environment variable IBM_COS_Backup_Vault with a VALID BACKUP VAULT NAME for testing ibm_cos_backup_vault* resources")
}
KmsKeyCrn = os.Getenv("IBM_KMS_KEY_CRN")
if KmsKeyCrn == "" {
KmsKeyCrn = ""
fmt.Println("[WARN] Set the environment variable IBM_KMS_KEY_CRN with a VALID key crn for a KP/HPCS root key")
}

CosBackupPolicyID = os.Getenv("IBM_COS_Backup_Policy_Id")
if CosBackupPolicyID == "" {
CosBackupPolicyID = ""
fmt.Println("[WARN] Set the environment variable IBM_COS_Backup_Policy_Id with a VALID POLICYS ID for testing ibm_cos_backup_policy* resources")
}
ActivityTrackerInstanceCRN = os.Getenv("IBM_COS_ACTIVITY_TRACKER_CRN")
if ActivityTrackerInstanceCRN == "" {
ActivityTrackerInstanceCRN = ""
Expand Down
4 changes: 4 additions & 0 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ func Provider() *schema.Provider {
"ibm_cr_namespaces": registry.DataIBMContainerRegistryNamespaces(),
"ibm_cloud_shell_account_settings": cloudshell.DataSourceIBMCloudShellAccountSettings(),
"ibm_cos_bucket": cos.DataSourceIBMCosBucket(),
"ibm_cos_backup_vault": cos.DataSourceIBMCosBackupVault(),
"ibm_cos_backup_policy": cos.DataSourceIBMCosBackupPolicy(),
"ibm_cos_bucket_object": cos.DataSourceIBMCosBucketObject(),
"ibm_dns_domain_registration": classicinfrastructure.DataSourceIBMDNSDomainRegistration(),
"ibm_dns_domain": classicinfrastructure.DataSourceIBMDNSDomain(),
Expand Down Expand Up @@ -1139,6 +1141,8 @@ func Provider() *schema.Provider {
"ibm_cos_bucket_object_lock_configuration": cos.ResourceIBMCOSBucketObjectlock(),
"ibm_cos_bucket_website_configuration": cos.ResourceIBMCOSBucketWebsiteConfiguration(),
"ibm_cos_bucket_lifecycle_configuration": cos.ResourceIBMCOSBucketLifecycleConfiguration(),
"ibm_cos_backup_vault": cos.ResourceIBMCOSBackupVault(),
"ibm_cos_backup_policy": cos.ResourceIBMCOSBackupPolicy(),
"ibm_dns_domain": classicinfrastructure.ResourceIBMDNSDomain(),
"ibm_dns_domain_registration_nameservers": classicinfrastructure.ResourceIBMDNSDomainRegistrationNameservers(),
"ibm_dns_secondary": classicinfrastructure.ResourceIBMDNSSecondary(),
Expand Down
82 changes: 82 additions & 0 deletions ibm/service/cos/data_source_ibm_cos_backup_policy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cos

import (
"fmt"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
rc "github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceIBMCosBackupPolicy() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMCosBackupPolicyRead,

Schema: map[string]*schema.Schema{
"bucket_name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the source bucket",
},
"policy_id": {
Type: schema.TypeString,
Required: true,
Description: "Id of the backup policy applied on the source bucket",
},
"policy_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name of the backup policy to be applied on the source bucket.",
},
"target_backup_vault_crn": {
Type: schema.TypeString,
Computed: true,
Description: "The CRN for a COS BackupVault.",
},
"backup_type": {
Type: schema.TypeString,
Computed: true,
Description: "The type of backup to support.",
},
},
}
}

func dataSourceIBMCosBackupPolicyRead(d *schema.ResourceData, meta interface{}) error {
rcClient, err := meta.(conns.ClientSession).CosConfigV1API()
if err != nil {
return err
}
bucketName := d.Get("bucket_name").(string)
policySetID := d.Get("policy_id").(string)
d.Set("policy_id", policySetID)
var policy_name, target_backup_vault_crn string
getBucketBackupPolicyOptions := &rc.GetBackupPolicyOptions{
Bucket: aws.String(bucketName),
PolicyID: aws.String(policySetID),
}

res, _, err := rcClient.GetBackupPolicy(getBucketBackupPolicyOptions)
if err != nil {
return err
}
if res != nil {
if res.PolicyName != nil {
d.Set("policy_name", aws.String(*res.PolicyName))
policy_name = *res.PolicyName
}
if res.TargetBackupVaultCrn != nil {
d.Set("target_backup_vault_crn", aws.String(*res.TargetBackupVaultCrn))
target_backup_vault_crn = *res.TargetBackupVaultCrn
}
if res.BackupType != nil {
d.Set("backup_type", aws.String(*res.BackupType))
}
}
policyID := fmt.Sprintf("%s:%s:%s:target:%s", bucketName, policySetID, policy_name, target_backup_vault_crn)
d.SetId(policyID)
return nil
}
39 changes: 39 additions & 0 deletions ibm/service/cos/data_source_ibm_cos_backup_policy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cos_test

import (
"fmt"
"testing"

acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccIBMCOSBackupPolicyDataSource_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheckCOS(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccIBMCOSBackupPolicyDataSourceConfig_basic_read(acc.BucketName, acc.CosBackupPolicyID),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet("data.ibm_cos_backup_policy.policy", "bucket_name"),
resource.TestCheckResourceAttrSet("data.ibm_cos_backup_policy.policy", "policy_id"),
resource.TestCheckResourceAttr("data.ibm_cos_backup_policy.policy", "backup_type", "continuous"),
),
IBM-diksha marked this conversation as resolved.
Show resolved Hide resolved
},
},
})
}

func testAccIBMCOSBackupPolicyDataSourceConfig_basic_read(name string, policy_id string) string {
return fmt.Sprintf(`

data "ibm_cos_backup_policy" "policy" {
bucket_name = "%s"
policy_id = "%s"
}`, name, policy_id)
}
90 changes: 90 additions & 0 deletions ibm/service/cos/data_source_ibm_cos_backup_vault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright IBM Corp. 2017, 2021 All Rights Reserved.
// Licensed under the Mozilla Public License v2.0

package cos

import (
"fmt"
"strings"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
rc "github.com/IBM/ibm-cos-sdk-go-config/v2/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceIBMCosBackupVault() *schema.Resource {
return &schema.Resource{
Read: dataSourceIBMCosBackupVaultRead,

Schema: map[string]*schema.Schema{
"backup_vault_name": {
Type: schema.TypeString,
Required: true,
},
"service_instance_id": {
Type: schema.TypeString,
Required: true,
},
"region": {
Type: schema.TypeString,
Required: true,
},
"activity_tracking_management_events": {
Type: schema.TypeBool,
Computed: true,
},
"metrics_monitoring_usage_metrics": {
Type: schema.TypeBool,
Computed: true,
},
"kms_key_crn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceIBMCosBackupVaultRead(d *schema.ResourceData, meta interface{}) error {
rcClient, err := meta.(conns.ClientSession).CosConfigV1API()
if err != nil {
return err
}
backupVaultName := d.Get("backup_vault_name").(string)
instanceCRN := d.Get("service_instance_id").(string)
region := d.Get("region").(string)
getBucketBackupVaultOptions := &rc.GetBackupVaultOptions{
BackupVaultName: aws.String(backupVaultName),
}

d.Set("service_instance_id", instanceCRN)
d.Set("region", region)
res, _, err := rcClient.GetBackupVault(getBucketBackupVaultOptions)
if err != nil {
return err
}

vaultID := fmt.Sprintf("%s:%s:%s:meta:%s", strings.Replace(instanceCRN, "::", "", -1), "backup-vault", backupVaultName, region)
d.SetId(vaultID)
if res != nil {
if res.ActivityTracking != nil {
if res.ActivityTracking.ManagementEvents != nil {
d.Set("activity_tracking_management_events", *res.ActivityTracking.ManagementEvents)
}
} else {
d.Set("activity_tracking_management_events", nil)
}
if res.MetricsMonitoring != nil {
d.Set("metrics_monitoring_usage_metrics", *res.MetricsMonitoring.UsageMetricsEnabled)
} else {
d.Set("metrics_monitoring_usage_metrics", nil)
}
if res.SseKpCustomerRootKeyCrn != nil {
d.Set("kms_key_crn", aws.String(*res.SseKpCustomerRootKeyCrn))
}

}

return nil
}
Loading
Loading