From 381154fce69f1d8bfb2b887c3ce87ae74e35dac1 Mon Sep 17 00:00:00 2001 From: kavya498 Date: Wed, 30 Dec 2020 18:06:16 +0530 Subject: [PATCH] Support #2118: KS APIkey Reset --- go.mod | 2 +- go.sum | 17 +---- ibm/data_source_ibm_container_cluster.go | 24 +++++- ibm/data_source_ibm_container_vpc_cluster.go | 32 ++++++++ ibm/provider.go | 1 + ibm/resource_ibm_container_api_key_reset.go | 76 +++++++++++++++++++ ibm/structures.go | 17 +++-- .../docs/d/container_cluster.html.markdown | 3 + .../d/container_vpc_cluster.html.markdown | 5 +- .../r/container_api_key_Reset.html.markdown | 39 ++++++++++ website/ibm.erb | 3 + 11 files changed, 193 insertions(+), 26 deletions(-) create mode 100644 ibm/resource_ibm_container_api_key_reset.go create mode 100644 website/docs/r/container_api_key_Reset.html.markdown diff --git a/go.mod b/go.mod index 19ee6dd758..40b654945d 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.12 require ( github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75 // indirect - github.com/IBM-Cloud/bluemix-go v0.0.0-20201222104207-ac387d69450c + github.com/IBM-Cloud/bluemix-go v0.0.0-20201230053147-e03f93e5013a github.com/IBM-Cloud/power-go-client v1.0.53 github.com/IBM/apigateway-go-sdk v0.0.0-20200414212859-416e5948678a github.com/IBM/go-sdk-core v1.1.0 diff --git a/go.sum b/go.sum index 27ec7715ef..ff9a30830f 100644 --- a/go.sum +++ b/go.sum @@ -28,8 +28,8 @@ github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75/go.mod h1:4/6eNcqZ09 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4= -github.com/IBM-Cloud/bluemix-go v0.0.0-20201222104207-ac387d69450c h1:iuHCP1LnLY5mWCeByCoTv+JU+PkMcK7c7pY+CEg4qYo= -github.com/IBM-Cloud/bluemix-go v0.0.0-20201222104207-ac387d69450c/go.mod h1:gPJbH1etcDj7qS/hBRiLuYW9CY0bRcostSKusa51xR0= +github.com/IBM-Cloud/bluemix-go v0.0.0-20201230053147-e03f93e5013a h1:Lg81dp8Ohj/I6evkdWTEOZo4/DCuXtkXL03OykiZ2Co= +github.com/IBM-Cloud/bluemix-go v0.0.0-20201230053147-e03f93e5013a/go.mod h1:gPJbH1etcDj7qS/hBRiLuYW9CY0bRcostSKusa51xR0= github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs= github.com/IBM-Cloud/power-go-client v1.0.53 h1:v29RRy5S3z950rgOXGEHab4h0LI9L8/8qot30JjmQXs= github.com/IBM-Cloud/power-go-client v1.0.53/go.mod h1:+mOxjyLeLIloR4EMHTpiDbN+FilZpiVHTwu5eqi+cbI= @@ -65,7 +65,6 @@ github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 h1:VauE2GcJNZFun2O github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5/go.mod h1:gxOHeajFfvGQh/fxlC8oOKBe23xnnJTif00IFFbiT+o= github.com/Shopify/sarama v1.26.4 h1:+17TxUq/PJEAfZAll0T7XJjSgQWCpaQSoki/x5yN8o8= github.com/Shopify/sarama v1.26.4/go.mod h1:NbSGBSSndYaIhRcBtY9V0U7AyH+x71bG668AuWys/yU= -github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292/go.mod h1:KYCjqMOeHpNuTOiFQU6WEcTG7poCJrUs0YgyHNtn1no= github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw= @@ -158,7 +157,6 @@ github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/form3tech-oss/jwt-go v3.2.1+incompatible h1:xdtqez379uWVJ9P3qQMX8W+F/nqsTdUvyMZB36tnacA= github.com/form3tech-oss/jwt-go v3.2.1+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= -github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw= github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g= github.com/frankban/quicktest v1.7.2/go.mod h1:jaStnuzAqU1AJdCO0l53JDCJrVDKcS03DbaAcR7Ks/o= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -243,7 +241,6 @@ github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= -github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho= github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= @@ -275,7 +272,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1 h1:qGJ6qTW+x6xX/my+8YUVl4WNpX9B7+/l2tRsHGZ7f2s= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= github.com/golang/protobuf v1.1.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -319,7 +315,6 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI= github.com/hashicorp/aws-sdk-go-base v0.4.0/go.mod h1:eRhlz3c4nhqxFZJAahJEFL7gh6Jyj5rQmQc7F9eHFyQ= github.com/hashicorp/consul v0.0.0-20171026175957-610f3c86a089/go.mod h1:mFrjN1mfidgJfYP1xrJCF+AfRhr6Eaqhb2+sfyn/OOI= @@ -402,7 +397,6 @@ github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeY github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/joyent/triton-go v0.0.0-20180313100802-d8f9c0314926/go.mod h1:U+RSyWxWd04xTqnuOQxnai7XGS2PrPY2cfGoDKtMHjA= @@ -422,11 +416,9 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxv github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= @@ -534,7 +526,6 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI= @@ -582,7 +573,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/svanharmelen/jsonapi v0.0.0-20180618144545-0c0828c3f16d/go.mod h1:BSTlc8jOjh0niykqEGVXOLXdi9o0r0kR8tCYiMvjFgw= github.com/tencentcloud/tencentcloud-sdk-go v3.0.82+incompatible/go.mod h1:0PfYow01SHPMhKY31xa+EFz2RStxIqj6JFAJS+IkCi4= @@ -792,7 +782,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= @@ -801,7 +790,6 @@ gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8 gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= gopkg.in/go-playground/validator.v9 v9.31.0 h1:bmXmP2RSNtFES+bn4uYuHT7iJFJv7Vj+an+ZQdDaD1M= gopkg.in/go-playground/validator.v9 v9.31.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWdVbfP1avr/N00E2vyQ= -gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= gopkg.in/ini.v1 v1.42.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/jcmturner/aescts.v1 v1.0.1 h1:cVVZBK2b1zY26haWB4vbBiZrfFQnfbTVrE3xZq6hrEw= @@ -823,7 +811,6 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= diff --git a/ibm/data_source_ibm_container_cluster.go b/ibm/data_source_ibm_container_cluster.go index 597f1a0cec..c81011762b 100644 --- a/ibm/data_source_ibm_container_cluster.go +++ b/ibm/data_source_ibm_container_cluster.go @@ -290,7 +290,21 @@ func dataSourceIBMContainerCluster() *schema.Resource { Optional: true, Description: "If set to false bounded services won't be listed.", }, - + "api_key_id": { + Type: schema.TypeString, + Computed: true, + Description: "ID of APIkey", + }, + "api_key_owner_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the key owner", + }, + "api_key_owner_email": { + Type: schema.TypeString, + Computed: true, + Description: "email id of the key owner", + }, ResourceControllerURL: { Type: schema.TypeString, Computed: true, @@ -414,6 +428,14 @@ func dataSourceIBMContainerClusterRead(d *schema.ResourceData, meta interface{}) return err } d.Set(ResourceControllerURL, controller+"/kubernetes/clusters") + apikeyAPI := csClient.Apikeys() + apikeyConfig, err := apikeyAPI.GetApiKeyInfo(name, targetEnv) + if err != nil { + return err + } + d.Set("api_key_id", apikeyConfig.ID) + d.Set("api_key_owner_name", apikeyConfig.Name) + d.Set("api_key_owner_email", apikeyConfig.Email) d.Set(ResourceName, clusterFields.Name) d.Set(ResourceCRN, clusterFields.CRN) d.Set(ResourceStatus, clusterFields.State) diff --git a/ibm/data_source_ibm_container_vpc_cluster.go b/ibm/data_source_ibm_container_vpc_cluster.go index 92eb0b36eb..00d6d43a51 100644 --- a/ibm/data_source_ibm_container_vpc_cluster.go +++ b/ibm/data_source_ibm_container_vpc_cluster.go @@ -223,6 +223,21 @@ func dataSourceIBMContainerVPCCluster() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + "api_key_id": { + Type: schema.TypeString, + Computed: true, + Description: "ID of APIkey", + }, + "api_key_owner_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the key owner", + }, + "api_key_owner_email": { + Type: schema.TypeString, + Computed: true, + Description: "email id of the key owner", + }, ResourceControllerURL: { Type: schema.TypeString, @@ -345,6 +360,23 @@ func dataSourceIBMContainerClusterVPCRead(d *schema.ResourceData, meta interface if err != nil { return err } + csClientv1, err := meta.(ClientSession).ContainerAPI() + if err != nil { + return err + } + apikeyAPI := csClientv1.Apikeys() + v1targetEnv, err := getClusterTargetHeader(d, meta) + if err != nil { + return err + } + apikeyConfig, err := apikeyAPI.GetApiKeyInfo(clusterID, v1targetEnv) + if err != nil { + + return err + } + d.Set("api_key_id", apikeyConfig.ID) + d.Set("api_key_owner_name", apikeyConfig.Name) + d.Set("api_key_owner_email", apikeyConfig.Email) d.Set(ResourceControllerURL, controller+"/kubernetes/clusters") d.Set(ResourceName, cls.Name) d.Set(ResourceCRN, cls.CRN) diff --git a/ibm/provider.go b/ibm/provider.go index 32004c15ab..5c571bee31 100644 --- a/ibm/provider.go +++ b/ibm/provider.go @@ -372,6 +372,7 @@ func Provider() terraform.ResourceProvider { "ibm_compute_vm_instance": resourceIBMComputeVmInstance(), "ibm_container_addons": resourceIBMContainerAddOns(), "ibm_container_alb": resourceIBMContainerALB(), + "ibm_container_api_key_reset": resourceIBMContainerAPIKeyReset(), "ibm_container_vpc_alb": resourceIBMContainerVpcALB(), "ibm_container_vpc_worker_pool": resourceIBMContainerVpcWorkerPool(), "ibm_container_vpc_cluster": resourceIBMContainerVpcCluster(), diff --git a/ibm/resource_ibm_container_api_key_reset.go b/ibm/resource_ibm_container_api_key_reset.go new file mode 100644 index 0000000000..f1595f2364 --- /dev/null +++ b/ibm/resource_ibm_container_api_key_reset.go @@ -0,0 +1,76 @@ +package ibm + +import ( + "fmt" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +func resourceIBMContainerAPIKeyReset() *schema.Resource { + return &schema.Resource{ + Create: resourceIBMContainerAPIKeyResetUpdate, + Read: resourceIBMContainerAPIKeyResetRead, + Update: resourceIBMContainerAPIKeyResetUpdate, + Delete: resourceIBMContainerAPIKeyResetdelete, + + Schema: map[string]*schema.Schema{ + "region": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Region which api key has to be reset", + }, + "resource_group_id": { + Type: schema.TypeString, + ForceNew: true, + Optional: true, + Description: "ID of Resource Group", + }, + "reset_api_key": { + Type: schema.TypeInt, + Optional: true, + Description: "Determines if apikey has to be reset or not", + Default: 1, + }, + }, + } +} + +func resourceIBMContainerAPIKeyResetUpdate(d *schema.ResourceData, meta interface{}) error { + + if d.HasChange("reset_api_key") { + apikeyClient, err := meta.(ClientSession).ContainerAPI() + if err != nil { + return err + } + apikeyAPI := apikeyClient.Apikeys() + region := d.Get("region").(string) + targetEnv, err := getClusterTargetHeader(d, meta) + if err != nil { + return err + } + targetEnv.Region = region + err = apikeyAPI.ResetApiKey(targetEnv) + if err != nil { + return err + } + if targetEnv.ResourceGroup == "" { + defaultRg, err := defaultResourceGroup(meta) + if err != nil { + return err + } + targetEnv.ResourceGroup = defaultRg + } + + d.SetId(fmt.Sprintf("%s/%s", region, targetEnv.ResourceGroup)) + } + + return nil +} +func resourceIBMContainerAPIKeyResetRead(d *schema.ResourceData, meta interface{}) error { + return nil +} +func resourceIBMContainerAPIKeyResetdelete(d *schema.ResourceData, meta interface{}) error { + d.SetId("") + return nil +} diff --git a/ibm/structures.go b/ibm/structures.go index eb10f328d1..ed70ad25a7 100644 --- a/ibm/structures.go +++ b/ibm/structures.go @@ -11,6 +11,14 @@ import ( "strconv" "strings" + "github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1" + "github.com/IBM/ibm-cos-sdk-go/service/s3" + kp "github.com/IBM/keyprotect-go-client" + "github.com/apache/openwhisk-client-go/whisk" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/softlayer/softlayer-go/datatypes" + "github.com/softlayer/softlayer-go/sl" + "github.com/IBM-Cloud/bluemix-go/api/container/containerv1" "github.com/IBM-Cloud/bluemix-go/api/container/containerv2" "github.com/IBM-Cloud/bluemix-go/api/iampap/iampapv1" @@ -23,13 +31,6 @@ import ( "github.com/IBM-Cloud/bluemix-go/api/schematics" "github.com/IBM-Cloud/bluemix-go/api/usermanagement/usermanagementv2" "github.com/IBM-Cloud/bluemix-go/models" - "github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1" - "github.com/IBM/ibm-cos-sdk-go/service/s3" - kp "github.com/IBM/keyprotect-go-client" - "github.com/apache/openwhisk-client-go/whisk" - "github.com/hashicorp/terraform-plugin-sdk/helper/schema" - "github.com/softlayer/softlayer-go/datatypes" - "github.com/softlayer/softlayer-go/sl" ) const ( @@ -1797,7 +1798,7 @@ func defaultResourceGroup(meta interface{}) (string, error) { return "", err } if len(grpList) <= 0 { - return "", fmt.Errorf("The targeted resource group could not be found. Make sure you have required permissions to access the resource group.") + return "", fmt.Errorf("The default resource group could not be found. Make sure you have required permissions to access the resource group.") } return grpList[0].ID, nil } diff --git a/website/docs/d/container_cluster.html.markdown b/website/docs/d/container_cluster.html.markdown index 1a215456a4..33b9ae9f94 100644 --- a/website/docs/d/container_cluster.html.markdown +++ b/website/docs/d/container_cluster.html.markdown @@ -81,3 +81,6 @@ The following attributes are exported: * `public_service_endpoint` - Is public service endpoint enabled to make the master publicly accessible. * `private_service_endpoint` - Is private service endpoint enabled to make the master privately accessible. * `crn` - CRN of the instance. +* `api_key_id` - ID of APIkey. +* `api_key_owner_name` - "Name of the key owner. +* `api_key_owner_email` - Email id of the key owner diff --git a/website/docs/d/container_vpc_cluster.html.markdown b/website/docs/d/container_vpc_cluster.html.markdown index af6288f846..f631ce2ebd 100644 --- a/website/docs/d/container_vpc_cluster.html.markdown +++ b/website/docs/d/container_vpc_cluster.html.markdown @@ -66,4 +66,7 @@ The following attributes are exported: * `master_url` - Url of the master * `status` - Status of cluster master. * `health` - Health of cluster master -* `kube_version` - The Kubernetes version, including at least the major.minor version.To see available versions, run 'ibmcloud ks versions'. \ No newline at end of file +* `kube_version` - The Kubernetes version, including at least the major.minor version.To see available versions, run 'ibmcloud ks versions'. +* `api_key_id` - ID of APIkey. +* `api_key_owner_name` - "Name of the key owner. +* `api_key_owner_email` - Email id of the key owner \ No newline at end of file diff --git a/website/docs/r/container_api_key_Reset.html.markdown b/website/docs/r/container_api_key_Reset.html.markdown new file mode 100644 index 0000000000..ba33163fd2 --- /dev/null +++ b/website/docs/r/container_api_key_Reset.html.markdown @@ -0,0 +1,39 @@ +--- +layout: "ibm" +page_title: "IBM: container_api_key_reset" +sidebar_current: "docs-ibm-resource-container-api-key-reset" +description: |- + Resets Kubernetes API Key. +--- + +# ibm\_container_api_key_reset + +Resets Kubernetes API Key + +## Example Usage + +In the following example, you can reset kubernetes api key: + +```hcl +resource "ibm_container_api_key_reset" "reset" { + region ="us-east" + resource_group_id = "766f3584b2c840ee96d856bc04551da8" + reset_api_key=2 + +} + +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Required, Forces new resource, string) The region in which api key has to be reset. +* `resource_group_id` - (Optional, Forces new resource, string) The ID of the resource group. You can retrieve the value from data source `ibm_resource_group`. If not provided defaults to default resource group. +* `reset_api_key` - (Optional, int) Default: 1. This attribute determines if the apikey has to be reset or not. Inorder to avoid state dependencies this attribute has been added. To reset apikey on same region and resource_group_id this attribute has to be incremented. + +## Attribute Reference + +The following attributes are exported: + +* `id` - The Resource ID. Id is a combination of `/` \ No newline at end of file diff --git a/website/ibm.erb b/website/ibm.erb index b1224a3436..464a909866 100644 --- a/website/ibm.erb +++ b/website/ibm.erb @@ -658,6 +658,9 @@ > container_alb_cert + > + container_api_key_reset + > container_bind_service