diff --git a/CHANGELOG.md b/CHANGELOG.md index 10f30f46..7a508cc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## v0.43.1 + +- Function: workaround for Iron.io race condition #375 + ## v0.43.0 - MDM: ServiceAction data sources #327 diff --git a/docs/data-sources/blr_bucket.md b/docs/data-sources/blr_bucket.md new file mode 100644 index 00000000..d8626051 --- /dev/null +++ b/docs/data-sources/blr_bucket.md @@ -0,0 +1,35 @@ +--- +subcategory: "Blob Repository (BLR)" +--- + +# hsdp_blr_bucket + +Retrieve details on a Blob Repository Bucket resource + +## Example Usage + +```hcl +data "hsdp_blr_bucket" "store" { + name = "bucket-store-1" +} + +output "bucket_id" { + value = data.hsdp_connect_mdm_bucket.store.id +} +``` + +## Argument Reference + +The following arguments are available: + +* `name` - (Required) The name of the bucket to look up + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID reference of the service action (format: `Bucket/${GUID}`) +* `guid` - The GUID of the bucket +* `cdn_enabled` - CDN enabled or not +* `cache_control_age` - Cache control age settings +* `cors_config_json` - The Bucket CORS configuration in JSON diff --git a/docs/resources/blr_blob_store_policy.md b/docs/resources/blr_blob_store_policy.md new file mode 100644 index 00000000..f77119d7 --- /dev/null +++ b/docs/resources/blr_blob_store_policy.md @@ -0,0 +1,40 @@ +--- +subcategory: "Blob Repository (BLR)" +page_title: "HSDP: hsdp_blr_blob_store_policy" +description: |- + Manages HSDP Connect Blob Store Repository Policies +--- + +# hsdp_blr_blob_store_policy + +Create and manage Blob Repository Policies + +## Example Usage + +```hcl +resource "hsdp_blr_blob_store_policy" "policy" { + statement { + effect = "Allow" + action = ["GET", "PUT", "DELETE"] + principal = ["prn:hsdp:iam:${data.hsdp_iam_org.myorg.id}:${hsdp_connect_mdm_proposition.first.guid}:User/*"] + resource = ["${hsdp_blr_bucket.store.name}/*"] + } +} +``` + +## Argument Reference + +The following arguments are available: + +* `statement` - (Required) + * `effect` - (Required, string) Effect of policy [`Allow`, `Deny`] + * `action` - (Required, list(string)) Allowed methods: [`GET`, `PUT`, `DELETE`] + * `principal` - (Required, list(string)) The principals the policy applies to + * `resource` - (Required, list(string)) The resources the policy applies to + +## Attributes reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID reference of the service action (format: `BlobStorePolicy/${GUID}`) +* `guid` - The GUID of the bucket diff --git a/docs/resources/blr_bucket.md b/docs/resources/blr_bucket.md new file mode 100644 index 00000000..ee390281 --- /dev/null +++ b/docs/resources/blr_bucket.md @@ -0,0 +1,52 @@ +--- +subcategory: "Blob Repository (BLR)" +page_title: "HSDP: hsdp_blr_bucket" +description: |- + Manages HSDP Connect Blob Repository Buckets +--- + +# hsdp_blr_bucket + +Create and manage Blob Repository Buckets + +## Example Usage + +```hcl +resource "hsdp_blr_bucket" "store" { + name = "bucket-store-1" + + proposition_id = data.hsdp_connect_mdm_propososition.prop.id + + enable_cdn = false + + cors_configuration { + allowed_origins = ["https://foo.hsdp.io"] + allowed_methods = ["GET"] + expose_headers = ["X-Hsdp-Signature"] + } +} +``` + +## Argument Reference + +The following arguments are available: + +* `name` - (Required) The name of the device group +* `proposition_id` - (Required) The proposition ID where this bucket falls under +* `versioning_enabled` - (Required) Set versioning +* `enable_cdn` - (Optional) Enable CDN or not +* `enable_create_or_delete_blob_meta` - (Optional) Enables creation or deletion of Blob meta data +* `enable_hsdp_domain` - (Optional) Enable HSDP domain mapping +* `cache_control_age` - (Optional) Cache control age settings (Max: `1800`, Min: `300`, Default: `1`) +* `cors_configuration` - (Optional) + * `allowed_origins` - (Required, list(string)) List of allowed origins + * `allowed_methods` - (Required, list(string)) Allowed methods: [`GET`, `PUT`, `POST`, `DELETE`, `HEAD`] + * `max_age_seconds` - (Optional) Max age in seconds + * `expose_headers` - (Optional, list(string)) List of headers to expose + +## Attributes reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The ID reference of the service action (format: `Bucket/${GUID}`) +* `guid` - The GUID of the bucket diff --git a/docs/resources/connect_mdm_bucket.md b/docs/resources/connect_mdm_bucket.md index b73cbbd6..a6e1523f 100644 --- a/docs/resources/connect_mdm_bucket.md +++ b/docs/resources/connect_mdm_bucket.md @@ -9,6 +9,8 @@ description: |- Create and manage MDM Bucket resources +~> This resource is deprecated. Please switch to using `hsdp_blr_bucket`. + ## Example Usage ```hcl diff --git a/go.mod b/go.mod index 054c55b9..caa37b99 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/philips-software/terraform-provider-hsdp -go 1.19 +go 1.21 require ( github.com/cenkalti/backoff/v4 v4.2.1 @@ -18,7 +18,7 @@ require ( github.com/loafoe/easyssh-proxy/v2 v2.0.4 github.com/loafoe/ferrite v0.2.0 github.com/philips-labs/siderite v0.16.6 - github.com/philips-software/go-hsdp-api v0.82.3 + github.com/philips-software/go-hsdp-api v0.82.4 github.com/pkg/errors v0.9.1 github.com/robfig/cron/v3 v3.0.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 3172bd14..7817792b 100644 --- a/go.sum +++ b/go.sum @@ -34,6 +34,7 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/Azure/azure-pipeline-go v0.2.1/go.mod h1:UGSo8XybXnIGZ3epmeBw7Jdz+HiUVpqIlpz/HKHylF4= github.com/Azure/azure-storage-blob-go v0.8.0/go.mod h1:lPI3aLPpuLTeUwh1sViKXFxwl2B6teiRqI0deQUvsw0= @@ -64,6 +65,7 @@ github.com/Masterminds/vcs v1.13.0/go.mod h1:N09YCmOQr6RLxC6UNHzuVwAdodYbbnycGHS github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= @@ -77,6 +79,7 @@ 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/TylerBrock/colorjson v0.0.0-20180527164720-95ec53f28296/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= +github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= @@ -123,6 +126,7 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA= +github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/buger/jsonparser v0.0.0-20200322175846-f7e751efca13/go.mod h1:tgcrVJ81GPSF0mz+0nu1Xaz0fazGPrmmJfJtxjbHhUQ= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/bytedance/sonic v1.5.0 h1:XWdTi8bwPgxIML+eNV1IwNuTROK6EUrQ65ey8yd6fRQ= @@ -185,6 +189,7 @@ github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= +github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -193,6 +198,7 @@ github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M= github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= +github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= @@ -208,17 +214,21 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= +github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= +github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.0.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= github.com/go-git/go-billy/v5 v5.1.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= +github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= github.com/go-git/go-git-fixtures/v4 v4.0.2-0.20200613231340-f56387b50c12/go.mod h1:m+ICp2rF3jDhFgEZ/8yziagdT1C+ZpZcrJjappBCDSw= github.com/go-git/go-git/v5 v5.3.0/go.mod h1:xdX4bWJ48aOrdhnl2XqHYstHbbp6+LFS4r4X+lNVprw= github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= +github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -272,6 +282,7 @@ github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2K github.com/go-openapi/validate v0.19.5/go.mod h1:8DJv2CVJQ6kGNpFW6eV9N3JviE1C85nY1c2z52x1Gk4= github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= @@ -305,6 +316,7 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/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/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -379,8 +391,11 @@ github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= +github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/graph-gophers/graphql-go v1.5.0 h1:fDqblo50TEpD0LY7RXk/LFVYEVqo3+tXMNMPSVXA1yc= +github.com/graph-gophers/graphql-go v1.5.0/go.mod h1:YtmJZDLbF1YYNrlNAuiO5zAStUWc3XZT07iGsVqe1Os= github.com/graph-gophers/graphql-transport-ws v0.0.2 h1:DbmSkbIGzj8SvHei6n8Mh9eLQin8PtA8xY9eCzjRpvo= +github.com/graph-gophers/graphql-transport-ws v0.0.2/go.mod h1:5BVKvFzOd2BalVIBFfnfmHjpJi/MZ5rOj8G55mXvZ8g= github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA= github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/grpc-ecosystem/go-grpc-middleware v1.1.0/go.mod h1:f5nM7jw/oeRSadq3xCzHAvxcr8HZnzsqU6ILg/0NiiE= @@ -499,6 +514,7 @@ github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJS github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74= github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= +github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= @@ -520,6 +536,7 @@ github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= +github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= @@ -533,6 +550,7 @@ github.com/klauspost/cpuid v1.2.0 h1:NMpwD2G9JSFOE1/TJjGSo5zG7Yb2bTe7eq1jH+irmeE github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.1.0 h1:eyi1Ad2aNJMW95zcSbmGg7Cg6cq3ADwLpMAP96d8rF0= +github.com/klauspost/cpuid/v2 v2.1.0/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/pgzip v1.2.4/go.mod h1:Ch1tH69qFZu15pkjo5kYi6mth2Zzwzt50oCQKQE9RUs= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -667,17 +685,19 @@ github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtP github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.9.4 h1:tjENF6MfZAg8e4ZmZTeWaWiT2vXtsoO6+iuOjFhECwM= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= +github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/philips-labs/siderite v0.16.6 h1:lG+Ze7K5WOcNB3KOcUzXDxGwHZg13mKKMa+yd8wHphw= github.com/philips-labs/siderite v0.16.6/go.mod h1:0mVh0VJ5109l9QCJDCizGTdtEbClbeQ/lcCrsEZiu60= -github.com/philips-software/go-hsdp-api v0.82.3 h1:wXhFNRuwE6u1M0pkSdRpqsPdAUb6JLGHBlVeF/+ATzw= -github.com/philips-software/go-hsdp-api v0.82.3/go.mod h1:JbSWbEfQVB7Ei8wov4C2zPO5N1+Wr9bha4urcfxddw4= +github.com/philips-software/go-hsdp-api v0.82.4 h1:lYIc9OT8Ua9g7vubamClh7WEsMU57ohcAm6nzkAeOp0= +github.com/philips-software/go-hsdp-api v0.82.4/go.mod h1:JbSWbEfQVB7Ei8wov4C2zPO5N1+Wr9bha4urcfxddw4= github.com/philips-software/go-hsdp-signer v1.4.0 h1:yg7UILhmI4xJhr/tQiAiQwJL0EZFvLuMqpH2GZ9ygY4= github.com/philips-software/go-hsdp-signer v1.4.0/go.mod h1:/QehZ/+Aks2t1TFpjhF/7ZSB8PJIIJHzLc03rOqwLw0= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pires/go-proxyproto v0.0.0-20191211124218-517ecdf5bb2b/go.mod h1:Odh9VFOZJCf9G8cLW5o435Xf1J95Jw9Gw5rnCjcwzAY= github.com/pjbgf/sha1cd v0.3.0 h1:4D5XXmUUBUl/xQ6IjCkEAbqXskkq/4O7LmGn0AqMDs4= +github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= @@ -727,6 +747,7 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM= +github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo= github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= @@ -799,6 +820,7 @@ github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAh github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= +github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -1047,6 +1069,7 @@ golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= 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= @@ -1254,6 +1277,7 @@ gopkg.in/yaml.v2 v2.2.5/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/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/config/config.go b/internal/config/config.go index 0dc7af99..e40205d2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -5,6 +5,8 @@ import ( "io" "net/http" + "github.com/philips-software/go-hsdp-api/blr" + "github.com/google/fhir/go/jsonformat" "github.com/hashicorp/go-retryablehttp" "github.com/philips-software/go-hsdp-api/ai" @@ -65,6 +67,7 @@ type Config struct { consoleClient *console.Client pkiClient *pki.Client stlClient *stl.Client + blrClient *blr.Client notificationClient *notification.Client mdmClient *mdm.Client discoveryClient *discovery.Client @@ -78,6 +81,7 @@ type Config struct { notificationClientErr error mdmClientErr error discoveryClientErr error + blrClientErr error TimeZone string `json:"time_zone"` STU3MA *jsonformat.Marshaller `json:"-"` @@ -158,6 +162,23 @@ func (c *Config) DiscoveryClient(principal ...*Principal) (*discovery.Client, er return c.discoveryClient, c.discoveryClientErr } +func (c *Config) BLRClient(principal ...*Principal) (*blr.Client, error) { + if len(principal) > 0 && principal[0] != nil && principal[0].HasAuth() { + region := principal[0].Region + environment := principal[0].Environment + iamClient, err := c.IAMClient(principal...) + if err != nil { + return nil, err + } + return blr.NewClient(iamClient, &blr.Config{ + Region: region, + Environment: environment, + DebugLog: c.DebugWriter, + }) + } + return c.blrClient, c.blrClientErr +} + func (c *Config) CartelClient() (*cartel.Client, error) { return c.cartelClient, c.cartelClientErr } @@ -782,3 +803,22 @@ func (c *Config) SetupDiscoveryClient() { c.discoveryClient = client c.discoveryClientErr = nil } + +func (c *Config) SetupBLRClient() { + if c.iamClientErr != nil { + c.blrClientErr = fmt.Errorf("IAM client error in SetupBLRClient: %w", c.iamClientErr) + return + } + client, err := blr.NewClient(c.iamClient, &blr.Config{ + Region: c.Region, + Environment: c.Environment, + DebugLog: c.DebugWriter, + }) + if err != nil { + c.blrClient = nil + c.blrClientErr = err + return + } + c.blrClient = client + c.blrClientErr = nil +} diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 63647066..41969c13 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -5,6 +5,8 @@ import ( "encoding/json" "os" + "github.com/philips-software/terraform-provider-hsdp/internal/services/blr" + "github.com/philips-software/terraform-provider-hsdp/internal/services/iam/group_membership" "github.com/google/fhir/go/fhirversion" @@ -324,6 +326,8 @@ func Provider(build string) *schema.Provider { "hsdp_cdr_practitioner": practitioner.ResourceCDRPractitioner(), "hsdp_iam_role_sharing_policy": role_sharing_policy.ResourceRoleSharingPolicy(), "hsdp_iam_device": device.ResourceIAMDevice(), + "hsdp_blr_bucket": blr.ResourceBLRBucket(), + "hsdp_blr_blob_store_policy": blr.ResourceBLRBlobStorePolicy(), }, DataSourcesMap: map[string]*schema.Resource{ "hsdp_iam_introspect": iam.DataSourceIAMIntrospect(), @@ -399,6 +403,7 @@ func Provider(build string) *schema.Provider { "hsdp_discovery_service": discovery.DataSourceDiscoveryService(), "hsdp_connect_mdm_service_action": mdm.DataSourceConnectMDMServiceAction(), "hsdp_connect_mdm_service_actions": mdm.DataSourceConnectMDMServiceActions(), + "hsdp_blr_store_policy": blr.DataSourceBLRBlobStorePolicyDefinition(), }, ConfigureContextFunc: providerConfigure(build), } @@ -496,6 +501,7 @@ func providerConfigure(build string) schema.ConfigureContextFunc { c.SetupNotificationClient() c.SetupMDMClient() c.SetupDiscoveryClient() + c.SetupBLRClient() ma, err := jsonformat.NewMarshaller(false, "", "", fhirversion.STU3) if err != nil { diff --git a/internal/services/blr/data_source_blr_blob_store_policy.go b/internal/services/blr/data_source_blr_blob_store_policy.go new file mode 100644 index 00000000..65808e03 --- /dev/null +++ b/internal/services/blr/data_source_blr_blob_store_policy.go @@ -0,0 +1,59 @@ +package blr + +import ( + "context" + "encoding/json" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/philips-software/terraform-provider-hsdp/internal/config" +) + +func DataSourceBLRBlobStorePolicyDefinition() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceBLRStorePolicyRead, + Schema: map[string]*schema.Schema{ + "policy_id": { + Type: schema.TypeString, + Required: true, + }, + "policy": { + Type: schema.TypeString, + Computed: true, + }, + "principal": config.PrincipalSchema(), + }, + } + +} + +func dataSourceBLRStorePolicyRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + policyID := d.Get("policy_id").(string) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + defer client.Close() + + resource, _, err := client.Configurations.GetBlobStorePolicyByID(policyID) + if err != nil { + return diag.FromErr(err) + } + + b, err := json.Marshal(resource.Statement) + if err != nil { + return diag.FromErr(err) + } + + d.SetId(policyID) + _ = d.Set("policy", string(b)) + + return diags +} diff --git a/internal/services/blr/resource_blr_blob_store_policy.go b/internal/services/blr/resource_blr_blob_store_policy.go new file mode 100644 index 00000000..2ee24884 --- /dev/null +++ b/internal/services/blr/resource_blr_blob_store_policy.go @@ -0,0 +1,224 @@ +package blr + +import ( + "context" + "fmt" + "net/http" + + "github.com/philips-software/go-hsdp-api/blr" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/philips-software/terraform-provider-hsdp/internal/config" + "github.com/philips-software/terraform-provider-hsdp/internal/tools" +) + +func importStatePassthroughSetGuidContext(_ context.Context, d *schema.ResourceData, _ interface{}) ([]*schema.ResourceData, error) { + var id string + count, _ := fmt.Sscanf(d.Id(), "BlobStorePolicy/%s", &id) + if count == 0 { + return []*schema.ResourceData{d}, fmt.Errorf("invalid ID: %s", d.Id()) + } + _ = d.Set("guid", id) + return []*schema.ResourceData{d}, nil +} + +func ResourceBLRBlobStorePolicy() *schema.Resource { + return &schema.Resource{ + Importer: &schema.ResourceImporter{ + StateContext: importStatePassthroughSetGuidContext, + }, + CreateContext: resourceBLRBlobStorePolicyCreate, + ReadContext: resourceBLRBlobStorePolicyRead, + DeleteContext: resourceBLRBlobStorePolicyDelete, + + Schema: map[string]*schema.Schema{ + "statement": blobStorePolicyStatementSchema(), + "principal": config.PrincipalSchema(), + "guid": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func policyStatementResource() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "effect": { + Type: schema.TypeString, + Required: true, + }, + "action": { + Type: schema.TypeSet, + MaxItems: 4, + MinItems: 1, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "principal": { + Type: schema.TypeSet, + MinItems: 1, + MaxItems: 10, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "resource": { + Type: schema.TypeSet, + MinItems: 1, + MaxItems: 10, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func blobStorePolicyStatementSchema() *schema.Schema { + return &schema.Schema{ + Type: schema.TypeSet, + Required: true, + ForceNew: true, + MaxItems: 1, + Elem: policyStatementResource(), + } +} + +func schemaToBlobStorePolicy(d *schema.ResourceData) blr.BlobStorePolicy { + + resource := blr.BlobStorePolicy{ + ResourceType: "Bucket", + Statement: []blr.BlobStorePolicyStatement{}, + } + if v, ok := d.GetOk("statement"); ok { + vL := v.(*schema.Set).List() + for _, entry := range vL { + var statement blr.BlobStorePolicyStatement + mV := entry.(map[string]interface{}) + statement.Effect = mV["effect"].(string) + statement.Action = tools.ExpandStringList(mV["action"].(*schema.Set).List()) + statement.Principal = tools.ExpandStringList(mV["principal"].(*schema.Set).List()) + statement.Resource = tools.ExpandStringList(mV["resource"].(*schema.Set).List()) + resource.Statement = append(resource.Statement, statement) + } + } + return resource +} + +func blobStorePolicyToSchema(resource blr.BlobStorePolicy, d *schema.ResourceData) { + a := &schema.Set{F: schema.HashResource(policyStatementResource())} + entry := make(map[string]interface{}) + entry["effect"] = resource.Statement[0].Effect + entry["action"] = tools.SchemaSetStrings(resource.Statement[0].Action) + entry["principal"] = tools.SchemaSetStrings(resource.Statement[0].Principal) + entry["resource"] = tools.SchemaSetStrings(resource.Statement[0].Resource) + a.Add(entry) + + _ = d.Set("statement", a) +} + +func resourceBLRBlobStorePolicyCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + resource := schemaToBlobStorePolicy(d) + + var created *blr.BlobStorePolicy + var resp *blr.Response + err = tools.TryHTTPCall(ctx, 5, func() (*http.Response, error) { + var err error + created, resp, err = client.Configurations.CreateBlobStorePolicy(resource) + if err != nil { + _ = client.TokenRefresh() + } + if resp == nil { + return nil, err + } + return resp.Response, err + }) + if err != nil { + return diag.FromErr(err) + } + if created == nil { + return diag.FromErr(fmt.Errorf("failed to create resource: %d", resp.StatusCode())) + } + _ = d.Set("guid", created.ID) + d.SetId(fmt.Sprintf("BlobStorePolicy/%s", created.ID)) + + return resourceBLRBucketRead(ctx, d, m) +} + +func resourceBLRBlobStorePolicyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + var id string + _, _ = fmt.Sscanf(d.Id(), "BlobStorePolicy/%s", &id) + var resource *blr.BlobStorePolicy + var resp *blr.Response + err = tools.TryHTTPCall(ctx, 10, func() (*http.Response, error) { + var err error + resource, resp, err = client.Configurations.GetBlobStorePolicyByID(id) + if err != nil { + _ = client.TokenRefresh() + } + if resp == nil { + return nil, err + } + return resp.Response, err + }) + if err != nil { + if resp != nil && (resp.StatusCode() == http.StatusNotFound || resp.StatusCode() == http.StatusGone) { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + blobStorePolicyToSchema(*resource, d) + return diags +} + +func resourceBLRBlobStorePolicyDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + var id string + _, _ = fmt.Sscanf(d.Id(), "BlobStorePolicy/%s", &id) + resource, _, err := client.Configurations.GetBlobStorePolicyByID(id) + if err != nil { + return diag.FromErr(err) + } + + ok, _, err := client.Configurations.DeleteBlobStorePolicy(*resource) + if err != nil { + return diag.FromErr(err) + } + if !ok { + return diag.FromErr(config.ErrInvalidResponse) + } + d.SetId("") + return diags +} diff --git a/internal/services/blr/resource_blr_bucket.go b/internal/services/blr/resource_blr_bucket.go new file mode 100644 index 00000000..68a8c3e0 --- /dev/null +++ b/internal/services/blr/resource_blr_bucket.go @@ -0,0 +1,299 @@ +package blr + +import ( + "context" + "fmt" + "net/http" + + "github.com/philips-software/go-hsdp-api/blr" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/philips-software/terraform-provider-hsdp/internal/config" + "github.com/philips-software/terraform-provider-hsdp/internal/tools" +) + +func ResourceBLRBucket() *schema.Resource { + return &schema.Resource{ + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + CreateContext: resourceBLRBucketCreate, + ReadContext: resourceBLRBucketRead, + UpdateContext: resourceBLRBucketUpdate, + DeleteContext: resourceBLRBucketDelete, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + "proposition_id": { + Type: schema.TypeString, + ForceNew: true, + Required: true, + }, + "principal": config.PrincipalSchema(), + "price_class": { + Type: schema.TypeString, + Optional: true, + }, + "cors_configuration": { + Type: schema.TypeSet, + Optional: true, + MaxItems: 1, + Elem: corsConfigurationsSchema(), + }, + "enable_create_or_delete_blob_meta": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "enable_hsdp_domain": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "enable_cdn": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "cache_control_age": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + }, + "guid": { + Type: schema.TypeString, + Computed: true, + }, + }, + } +} + +func corsConfigurationsSchema() *schema.Resource { + return &schema.Resource{ + Schema: map[string]*schema.Schema{ + "allowed_origins": { + Type: schema.TypeSet, + MaxItems: 100, + MinItems: 1, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "allowed_methods": { + Type: schema.TypeSet, + MaxItems: 5, + MinItems: 1, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "allowed_headers": { + Type: schema.TypeSet, + MinItems: 1, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "max_age_seconds": { + Type: schema.TypeInt, + Optional: true, + Default: 1, + }, + "expose_headers": { + Type: schema.TypeSet, + MinItems: 1, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, + }, + } +} + +func schemaToBucket(d *schema.ResourceData) blr.Bucket { + name := d.Get("name").(string) + propositionId := d.Get("proposition_id").(string) + priceClass := d.Get("price_class").(string) + enableHSDPDomain := d.Get("enable_hsdp_domain").(bool) + enableCreateOrDeleteBlobMeta := d.Get("enable_create_or_delete_blob_meta").(bool) + enableCDN := d.Get("enable_cdn").(bool) + cacheControlAge := d.Get("cache_control_age").(int) + + resource := blr.Bucket{ + ResourceType: "Bucket", + Name: name, + PropositionID: blr.Reference{Reference: propositionId, Display: "Terraform managed"}, + PriceClass: priceClass, + EnableHSDPDomain: enableHSDPDomain, + EnableCreateOrDeleteBlobMeta: enableCreateOrDeleteBlobMeta, + EnableCDN: enableCDN, + CacheControlAge: cacheControlAge, + } + if v, ok := d.GetOk("cors_configuration"); ok { + vL := v.(*schema.Set).List() + for _, entry := range vL { + mV := entry.(map[string]interface{}) + resource.CorsConfiguration.MaxAgeSeconds = mV["max_age_seconds"].(int) + resource.CorsConfiguration.AllowedOrigins = tools.ExpandStringList(mV["allowed_origins"].(*schema.Set).List()) + resource.CorsConfiguration.AllowedHeaders = tools.ExpandStringList(mV["allowed_headers"].(*schema.Set).List()) + resource.CorsConfiguration.AllowedMethods = tools.ExpandStringList(mV["allowed_methods"].(*schema.Set).List()) + resource.CorsConfiguration.ExposeHeaders = tools.ExpandStringList(mV["expose_headers"].(*schema.Set).List()) + } + } + return resource +} + +func bucketToSchema(resource blr.Bucket, d *schema.ResourceData) { + _ = d.Set("name", resource.Name) + _ = d.Set("proposition_id", resource.PropositionID) + _ = d.Set("enable_cdn", resource.EnableCDN) + _ = d.Set("price_class", resource.PriceClass) + _ = d.Set("enable_hsdp_domain", resource.EnableHSDPDomain) + _ = d.Set("enable_create_or_delete_blob_meta", resource.EnableCreateOrDeleteBlobMeta) + _ = d.Set("cache_control_age", resource.CacheControlAge) + + // Add CORSConfiguration + a := &schema.Set{F: schema.HashResource(corsConfigurationsSchema())} + entry := make(map[string]interface{}) + entry["allowed_origins"] = tools.SchemaSetStrings(resource.CorsConfiguration.AllowedOrigins) + entry["allowed_headers"] = tools.SchemaSetStrings(resource.CorsConfiguration.AllowedHeaders) + entry["expose_headers"] = tools.SchemaSetStrings(resource.CorsConfiguration.ExposeHeaders) + entry["allowed_methods"] = tools.SchemaSetStrings(resource.CorsConfiguration.AllowedMethods) + entry["max_age_seconds"] = resource.CorsConfiguration.MaxAgeSeconds + a.Add(entry) + + _ = d.Set("cors_configuration", a) +} + +func resourceBLRBucketCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + resource := schemaToBucket(d) + + var created *blr.Bucket + var resp *blr.Response + err = tools.TryHTTPCall(ctx, 5, func() (*http.Response, error) { + var err error + created, resp, err = client.Configurations.CreateBucket(resource) + if err != nil { + _ = client.TokenRefresh() + } + if resp == nil { + return nil, err + } + return resp.Response, err + }) + if err != nil { + return diag.FromErr(err) + } + if created == nil { + return diag.FromErr(fmt.Errorf("failed to create resource: %d", resp.StatusCode())) + } + _ = d.Set("guid", created.ID) + d.SetId(fmt.Sprintf("Bucket/%s", created.ID)) + + return resourceBLRBucketRead(ctx, d, m) +} + +func resourceBLRBucketRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + var id string + _, _ = fmt.Sscanf(d.Id(), "Bucket/%s", &id) + var resource *blr.Bucket + var resp *blr.Response + err = tools.TryHTTPCall(ctx, 10, func() (*http.Response, error) { + var err error + resource, resp, err = client.Configurations.GetBucketByID(id) + if err != nil { + _ = client.TokenRefresh() + } + if resp == nil { + return nil, err + } + return resp.Response, err + }) + if err != nil { + if resp != nil && (resp.StatusCode() == http.StatusNotFound || resp.StatusCode() == http.StatusGone) { + d.SetId("") + return nil + } + return diag.FromErr(err) + } + bucketToSchema(*resource, d) + return diags +} + +func resourceBLRBucketUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + id := d.Get("guid").(string) + + resource := schemaToBucket(d) + resource.ID = id + + _, _, err = client.Configurations.UpdateBucket(resource) + + if err != nil { + diags = append(diags, diag.FromErr(err)...) + } + if len(diags) > 0 { + return diags + } + return resourceBLRBucketRead(ctx, d, m) +} + +func resourceBLRBucketDelete(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { + c := m.(*config.Config) + + var diags diag.Diagnostics + + principal := config.SchemaToPrincipal(d, m) + + client, err := c.BLRClient(principal) + if err != nil { + return diag.FromErr(err) + } + + id := d.Get("guid").(string) + resource, _, err := client.Configurations.GetBucketByID(id) + if err != nil { + return diag.FromErr(err) + } + + ok, _, err := client.Configurations.DeleteBucket(*resource) + if err != nil { + return diag.FromErr(err) + } + if !ok { + return diag.FromErr(config.ErrInvalidResponse) + } + d.SetId("") + return diags +} diff --git a/internal/services/connect/mdm/resource_connect_mdm_bucket.go b/internal/services/connect/mdm/resource_connect_mdm_bucket.go index e4b28f2b..cae10b56 100644 --- a/internal/services/connect/mdm/resource_connect_mdm_bucket.go +++ b/internal/services/connect/mdm/resource_connect_mdm_bucket.go @@ -17,10 +17,11 @@ func ResourceConnectMDMBucket() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: schema.ImportStatePassthroughContext, }, - CreateContext: resourceConnectMDMBucketCreate, - ReadContext: resourceConnectMDMBucketRead, - UpdateContext: resourceConnectMDMBucketUpdate, - DeleteContext: resourceConnectMDMBucketDelete, + CreateContext: resourceConnectMDMBucketCreate, + ReadContext: resourceConnectMDMBucketRead, + UpdateContext: resourceConnectMDMBucketUpdate, + DeleteContext: resourceConnectMDMBucketDelete, + DeprecationMessage: "Use the hsdp_blr_bucket resource to manage buckets.", Schema: map[string]*schema.Schema{ "name": {