From c590a992d9af3a454cea236fa858481c4d07f752 Mon Sep 17 00:00:00 2001 From: poorani Date: Mon, 21 Jul 2025 14:28:44 +0100 Subject: [PATCH] feat(IAM Identity): Identity Preferences --- .../ibm-iam-identity-preferences/README.md | 105 +++++++++ examples/ibm-iam-identity-preferences/main.tf | 35 +++ .../ibm-iam-identity-preferences/outputs.tf | 6 + .../ibm-iam-identity-preferences/variables.tf | 70 ++++++ .../ibm-iam-identity-preferences/versions.tf | 9 + go.mod | 7 + go.sum | 26 +++ ibm/provider/provider.go | 3 + ...data_source_ibm_iam_identity_preference.go | 117 ++++++++++ ...source_ibm_iam_identity_preference_test.go | 62 +++++ ...ata_source_ibm_iam_identity_preferences.go | 148 ++++++++++++ ...ource_ibm_iam_identity_preferences_test.go | 74 ++++++ .../resource_ibm_iam_identity_preference.go | 217 ++++++++++++++++++ ...source_ibm_iam_identity_preference_test.go | 147 ++++++++++++ instructions.md | 98 ++++++++ .../d/iam_identity_preference.html.markdown | 41 ++++ .../d/iam_identity_preferences.html.markdown | 42 ++++ .../r/iam_identity_preference.html.markdown | 62 +++++ 18 files changed, 1269 insertions(+) create mode 100644 examples/ibm-iam-identity-preferences/README.md create mode 100644 examples/ibm-iam-identity-preferences/main.tf create mode 100644 examples/ibm-iam-identity-preferences/outputs.tf create mode 100644 examples/ibm-iam-identity-preferences/variables.tf create mode 100644 examples/ibm-iam-identity-preferences/versions.tf create mode 100644 ibm/service/iamidentity/data_source_ibm_iam_identity_preference.go create mode 100644 ibm/service/iamidentity/data_source_ibm_iam_identity_preference_test.go create mode 100644 ibm/service/iamidentity/data_source_ibm_iam_identity_preferences.go create mode 100644 ibm/service/iamidentity/data_source_ibm_iam_identity_preferences_test.go create mode 100644 ibm/service/iamidentity/resource_ibm_iam_identity_preference.go create mode 100644 ibm/service/iamidentity/resource_ibm_iam_identity_preference_test.go create mode 100644 instructions.md create mode 100644 website/docs/d/iam_identity_preference.html.markdown create mode 100644 website/docs/d/iam_identity_preferences.html.markdown create mode 100644 website/docs/r/iam_identity_preference.html.markdown diff --git a/examples/ibm-iam-identity-preferences/README.md b/examples/ibm-iam-identity-preferences/README.md new file mode 100644 index 0000000000..7c055da62e --- /dev/null +++ b/examples/ibm-iam-identity-preferences/README.md @@ -0,0 +1,105 @@ +# Examples for IAM Identity Services + +These examples illustrate how to use the resources and data sources associated with IAM Identity Services. + +The following resources are supported: +* ibm_iam_identity_preference + +The following data sources are supported: +* ibm_iam_identity_preference + +## Usage + +To run this example, execute the following commands: + +```bash +$ terraform init +$ terraform plan +$ terraform apply +``` + +Run `terraform destroy` when you don't need these resources. + +## IAM Identity Services resources + +### Resource: ibm_iam_identity_preference + +```hcl +resource "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = var.iam_identity_preference_account_id + iam_id = var.iam_identity_preference_iam_id + service = var.iam_identity_preference_service + preference_id = var.iam_identity_preference_preference_id + value_string = var.iam_identity_preference_value_string + value_list_of_strings = var.iam_identity_preference_value_list_of_strings +} +``` + +#### Inputs + +| Name | Description | Type | Required | +|------|-------------|------|---------| +| ibmcloud\_api\_key | IBM Cloud API key | `string` | true | +| account_id | Account id to update preference for. | `string` | true | +| iam_id | IAM id to update the preference for. | `string` | true | +| service | Service of the preference to be updated. | `string` | true | +| preference_id | Identifier of preference to be updated. | `string` | true | +| value_string | String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. | `string` | true | +| value_list_of_strings | List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. | `list(string)` | false | + +#### Outputs + +| Name | Description | +|------|-------------| +| scope | Scope of the preference, 'global' or 'account'. | +| preference_id | Unique ID of the preference. | + +## IAM Identity Services data sources + +### Data source: ibm_iam_identity_preference + +```hcl +data "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = var.data_iam_identity_preference_account_id + iam_id = var.data_iam_identity_preference_iam_id + service = var.data_iam_identity_preference_service + preference_id = var.data_iam_identity_preference_preference_id +} +``` + +#### Inputs + +| Name | Description | Type | Required | +|------|-------------|------|---------| +| account_id | Account id to get preference for. | `string` | true | +| iam_id | IAM id to get the preference for. | `string` | true | +| service | Service of the preference to be fetched. | `string` | true | +| preference_id | Identifier of preference to be fetched. | `string` | true | + +#### Outputs + +| Name | Description | +|------|-------------| +| scope | Scope of the preference, 'global' or 'account'. | +| value_string | String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. | +| value_list_of_strings | List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. | + +## Assumptions + +1. TODO + +## Notes + +1. TODO + +## Requirements + +| Name | Version | +|------|---------| +| terraform | ~> 0.12 | + +## Providers + +| Name | Version | +|------|---------| +| ibm | 1.13.1 | diff --git a/examples/ibm-iam-identity-preferences/main.tf b/examples/ibm-iam-identity-preferences/main.tf new file mode 100644 index 0000000000..28680afb73 --- /dev/null +++ b/examples/ibm-iam-identity-preferences/main.tf @@ -0,0 +1,35 @@ +provider "ibm" { + ibmcloud_api_key = var.ibmcloud_api_key +} + +// Provision iam_identity_preference resource instance +resource "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = var.iam_identity_preference_account_id + iam_id = var.iam_identity_preference_iam_id + service = var.iam_identity_preference_service + preference_id = var.iam_identity_preference_preference_id + value_string = var.iam_identity_preference_value_string + value_list_of_strings = var.iam_identity_preference_value_list_of_strings +} + +// Data source is not linked to a resource instance +// Uncomment if an existing data source instance exists +/* +// Create iam_identity_preference data source +data "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = var.data_iam_identity_preference_account_id + iam_id = var.data_iam_identity_preference_iam_id + service = var.data_iam_identity_preference_service + preference_id = var.data_iam_identity_preference_preference_id +} +*/ + +// Data source is not linked to a resource instance +// Uncomment if an existing data source instance exists +/* +// Create iam_identity_preferences data source +data "ibm_iam_identity_preferences" "iam_identity_preferences_instance" { + account_id = var.iam_identity_preferences_account_id + iam_id = var.iam_identity_preferences_iam_id +} +*/ \ No newline at end of file diff --git a/examples/ibm-iam-identity-preferences/outputs.tf b/examples/ibm-iam-identity-preferences/outputs.tf new file mode 100644 index 0000000000..7474a23407 --- /dev/null +++ b/examples/ibm-iam-identity-preferences/outputs.tf @@ -0,0 +1,6 @@ +// This output allows iam_identity_preference data to be referenced by other resources and the terraform CLI +// Modify this output if only certain data should be exposed +output "ibm_iam_identity_preference" { + value = ibm_iam_identity_preference.iam_identity_preference_instance + description = "iam_identity_preference resource instance" +} diff --git a/examples/ibm-iam-identity-preferences/variables.tf b/examples/ibm-iam-identity-preferences/variables.tf new file mode 100644 index 0000000000..70a667475e --- /dev/null +++ b/examples/ibm-iam-identity-preferences/variables.tf @@ -0,0 +1,70 @@ +variable "ibmcloud_api_key" { + description = "IBM Cloud API key" + type = string +} + +// Resource arguments for iam_identity_preference +variable "iam_identity_preference_account_id" { + description = "Account id to update preference for." + type = string + default = "account_id" +} +variable "iam_identity_preference_iam_id" { + description = "IAM id to update the preference for." + type = string + default = "iam_id" +} +variable "iam_identity_preference_service" { + description = "Service of the preference to be updated." + type = string + default = "service" +} +variable "iam_identity_preference_preference_id" { + description = "Identifier of preference to be updated." + type = string + default = "preference_id" +} +variable "iam_identity_preference_value_string" { + description = "String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present." + type = string + default = "value_string" +} +variable "iam_identity_preference_value_list_of_strings" { + description = "List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present." + type = list(string) + default = [ "value_list_of_strings" ] +} + +// Data source arguments for iam_identity_preference +variable "data_iam_identity_preference_account_id" { + description = "Account id to get preference for." + type = string + default = "account_id" +} +variable "data_iam_identity_preference_iam_id" { + description = "IAM id to get the preference for." + type = string + default = "iam_id" +} +variable "data_iam_identity_preference_service" { + description = "Service of the preference to be fetched." + type = string + default = "service" +} +variable "data_iam_identity_preference_preference_id" { + description = "Identifier of preference to be fetched." + type = string + default = "preference_id" +} + +// Data source arguments for iam_identity_preferences +variable "iam_identity_preferences_account_id" { + description = "Account id to get preferences for." + type = string + default = "account_id" +} +variable "iam_identity_preferences_iam_id" { + description = "IAM id to get the preferences for." + type = string + default = "iam_id" +} diff --git a/examples/ibm-iam-identity-preferences/versions.tf b/examples/ibm-iam-identity-preferences/versions.tf new file mode 100644 index 0000000000..54c9d03e8d --- /dev/null +++ b/examples/ibm-iam-identity-preferences/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_version = ">= 1.0" + required_providers { + ibm = { + source = "IBM-Cloud/ibm" + version = "1.52.0-beta0" + } + } +} diff --git a/go.mod b/go.mod index 6fdf5c2806..d7aa3f45a3 100644 --- a/go.mod +++ b/go.mod @@ -129,13 +129,18 @@ require ( github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.7 // indirect github.com/hashicorp/hc-install v0.9.2 // indirect + github.com/hashicorp/hc-install v0.9.2 // indirect github.com/hashicorp/hcl v1.0.1-vault-7 // indirect github.com/hashicorp/hcl/v2 v2.23.0 // indirect github.com/hashicorp/logutils v1.0.0 // indirect github.com/hashicorp/terraform-exec v0.23.0 // indirect github.com/hashicorp/terraform-json v0.25.0 // indirect github.com/hashicorp/terraform-plugin-go v0.28.0 // indirect + github.com/hashicorp/terraform-exec v0.23.0 // indirect + github.com/hashicorp/terraform-json v0.25.0 // indirect + github.com/hashicorp/terraform-plugin-go v0.28.0 // indirect github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect + github.com/hashicorp/terraform-plugin-testing v1.13.3 github.com/hashicorp/terraform-registry-address v0.2.5 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/vault/api v1.16.0 // indirect @@ -208,6 +213,8 @@ require ( google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect google.golang.org/grpc v1.72.1 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect + google.golang.org/grpc v1.72.1 // indirect google.golang.org/protobuf v1.36.7 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect diff --git a/go.sum b/go.sum index 23b8f1e3cb..59d62106fc 100644 --- a/go.sum +++ b/go.sum @@ -180,6 +180,8 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0 github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:zL3Ph7RCZadAPb7QV0gMIDmjuZHFawNhoPZ5erh6TRw= github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56/go.mod h1:nE9BGpMlMfM9Z3U+P+mWtcHNDwHcGctalMx1VTkODAY= +github.com/ProtonMail/go-crypto v1.1.0-alpha.2 h1:bkyFVUP+ROOARdgCiJzNQo2V2kiB97LyUpzH9P6Hrlg= +github.com/ProtonMail/go-crypto v1.1.0-alpha.2/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= @@ -677,6 +679,8 @@ github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtng github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI= +github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs= github.com/hashicorp/go-cty v1.5.0 h1:EkQ/v+dDNUqnuVpmS5fPqyY71NXVgT5gf32+57xY8g0= github.com/hashicorp/go-cty v1.5.0/go.mod h1:lFUCG5kd8exDobgSfyj4ONE/dc822kiYMguVKdHGMLM= github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ= @@ -692,6 +696,8 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= +github.com/hashicorp/go-plugin v1.6.2 h1:zdGAEd0V1lCaU0u+MxWQhtSDQmahpkwOun8U8EiRVog= +github.com/hashicorp/go-plugin v1.6.2/go.mod h1:CkgLQ5CZqNmdL9U9JzM532t8ZiYQ35+pj3b1FD37R0Q= github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg= github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= @@ -727,6 +733,8 @@ github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hc-install v0.9.0 h1:2dIk8LcvANwtv3QZLckxcjyF5w8KVtiMxu6G6eLhghE= +github.com/hashicorp/hc-install v0.9.0/go.mod h1:+6vOP+mf3tuGgMApVYtmsnDoKWMDcFXeTxCACYZ8SFg= github.com/hashicorp/hc-install v0.9.2 h1:v80EtNX4fCVHqzL9Lg/2xkp62bbvQMnvPQ0G+OmtO24= github.com/hashicorp/hc-install v0.9.2/go.mod h1:XUqBQNnuT4RsxoxiM9ZaUk0NX8hi2h+Lb6/c0OZnC/I= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= @@ -740,16 +748,28 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.4/go.mod h1:mtBihi+LeNXGtG8L9dX59gAEa12BDtBQSp4v/YAJqrc= github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= +github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVWkd/RG0D2XQ= +github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg= github.com/hashicorp/terraform-exec v0.23.0 h1:MUiBM1s0CNlRFsCLJuM5wXZrzA3MnPYEsiXmzATMW/I= github.com/hashicorp/terraform-exec v0.23.0/go.mod h1:mA+qnx1R8eePycfwKkCRk3Wy65mwInvlpAeOwmA7vlY= +github.com/hashicorp/terraform-json v0.23.0 h1:sniCkExU4iKtTADReHzACkk8fnpQXrdD2xoR+lppBkI= +github.com/hashicorp/terraform-json v0.23.0/go.mod h1:MHdXbBAbSg0GvzuWazEGKAn/cyNfIB7mN6y7KJN6y2c= github.com/hashicorp/terraform-json v0.25.0 h1:rmNqc/CIfcWawGiwXmRuiXJKEiJu1ntGoxseG1hLhoQ= github.com/hashicorp/terraform-json v0.25.0/go.mod h1:sMKS8fiRDX4rVlR6EJUMudg1WcanxCMoWwTLkgZP/vc= +github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks= +github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw= github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA= github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0 h1:wyKCCtn6pBBL46c1uIIBNUOWlNfYXfXpVo16iDyLp8Y= +github.com/hashicorp/terraform-plugin-sdk/v2 v2.35.0/go.mod h1:B0Al8NyYVr8Mp/KLwssKXG1RqnTk7FySqSn4fRuLNgw= github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0 h1:NFPMacTrY/IdcIcnUB+7hsore1ZaRWU9cnB6jFoBnIM= github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0/go.mod h1:QYmYnLfsosrxjCnGY1p9c7Zj6n9thnEE+7RObeYs3fA= +github.com/hashicorp/terraform-plugin-testing v1.13.3 h1:QLi/khB8Z0a5L54AfPrHukFpnwsGL8cwwswj4RZduCo= +github.com/hashicorp/terraform-plugin-testing v1.13.3/go.mod h1:WHQ9FDdiLoneey2/QHpGM/6SAYf4A7AZazVg7230pLE= +github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI= +github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM= github.com/hashicorp/terraform-registry-address v0.2.5 h1:2GTftHqmUhVOeuu9CW3kwDkRe4pcBDq0uuK5VJngU1M= github.com/hashicorp/terraform-registry-address v0.2.5/go.mod h1:PpzXWINwB5kuVS5CA7m1+eO2f1jKb5ZDIxrOPfpnGkg= github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ= @@ -1216,6 +1236,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zclconf/go-cty v1.15.0 h1:tTCRWxsexYUmtt/wVxgDClUe+uQusuI443uL6e+5sXQ= +github.com/zclconf/go-cty v1.15.0/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty v1.16.3 h1:osr++gw2T61A8KVYHoQiFbFd1Lh3JOCXc/jFLJXKTxk= github.com/zclconf/go-cty v1.16.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo= @@ -1864,6 +1886,8 @@ google.golang.org/genproto v0.0.0-20220421151946-72621c1f0bd3/go.mod h1:8w6bsBMX google.golang.org/genproto v0.0.0-20220429170224-98d788798c3e/go.mod h1:8w6bsBMX6yCPbAVTeqQHvzxW0EIFigd5lZyahWgyfDo= google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3/go.mod h1:RAyBrSAP7Fh3Nc84ghnVLDPuV51xc9agzmm4Ph6i0Q4= google.golang.org/genproto v0.0.0-20220602131408-e326c6e8e9c8/go.mod h1:yKyY4AMRwFiC8yMMNaMi+RkCnjZJt9LoWuvhXjMs+To= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= @@ -1898,6 +1922,8 @@ google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11 google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.46.2/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= +google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= +google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/grpc v1.72.1 h1:HR03wO6eyZ7lknl75XlxABNVLLFc2PAb6mHlYh756mA= google.golang.org/grpc v1.72.1/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= diff --git a/ibm/provider/provider.go b/ibm/provider/provider.go index 401a374957..0aad63d524 100644 --- a/ibm/provider/provider.go +++ b/ibm/provider/provider.go @@ -459,6 +459,8 @@ func Provider() *schema.Provider { "ibm_iam_trusted_profile_template": iamidentity.DataSourceIBMTrustedProfileTemplate(), "ibm_iam_account_settings_template_assignment": iamidentity.DataSourceIBMAccountSettingsTemplateAssignment(), "ibm_iam_trusted_profile_template_assignment": iamidentity.DataSourceIBMTrustedProfileTemplateAssignment(), + "ibm_iam_identity_preference": iamidentity.DataSourceIBMIamIdentityPreference(), + "ibm_iam_identity_preferences": iamidentity.DataSourceIBMIamIdentityPreferences(), "ibm_iam_policy_template": iampolicy.DataSourceIBMIAMPolicyTemplate(), "ibm_iam_policy_template_version": iampolicy.DataSourceIBMIAMPolicyTemplateVersion(), "ibm_iam_policy_assignments": iampolicy.DataSourceIBMIAMPolicyAssignments(), @@ -1310,6 +1312,7 @@ func Provider() *schema.Provider { "ibm_iam_trusted_profile_template": iamidentity.ResourceIBMTrustedProfileTemplate(), "ibm_iam_account_settings_template_assignment": iamidentity.ResourceIBMAccountSettingsTemplateAssignment(), "ibm_iam_trusted_profile_template_assignment": iamidentity.ResourceIBMTrustedProfileTemplateAssignment(), + "ibm_iam_identity_preference": iamidentity.ResourceIBMIamIdentityPreference(), "ibm_ipsec_vpn": classicinfrastructure.ResourceIBMIPSecVPN(), "ibm_iam_policy_template": iampolicy.ResourceIBMIAMPolicyTemplate(), "ibm_iam_policy_template_version": iampolicy.ResourceIBMIAMPolicyTemplateVersion(), diff --git a/ibm/service/iamidentity/data_source_ibm_iam_identity_preference.go b/ibm/service/iamidentity/data_source_ibm_iam_identity_preference.go new file mode 100644 index 0000000000..30de99fbd6 --- /dev/null +++ b/ibm/service/iamidentity/data_source_ibm_iam_identity_preference.go @@ -0,0 +1,117 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.106.0-09823488-20250707-071701 + */ + +package iamidentity + +import ( + "context" + "fmt" + "log" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/platform-services-go-sdk/iamidentityv1" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func DataSourceIBMIamIdentityPreference() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMIamIdentityPreferenceRead, + + Schema: map[string]*schema.Schema{ + "account_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Account id to get preference for.", + }, + "iam_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "IAM id to get the preference for.", + }, + "service": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Service of the preference to be fetched.", + }, + "preference_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Identifier of preference to be fetched.", + }, + "scope": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Scope of the preference, 'global' or 'account'.", + }, + "value_string": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + }, + "value_list_of_strings": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func dataSourceIBMIamIdentityPreferenceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_iam_identity_preference", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getPreferenceOnScopeAccountOptions := &iamidentityv1.GetPreferencesOnScopeAccountOptions{} + + getPreferenceOnScopeAccountOptions.SetAccountID(d.Get("account_id").(string)) + getPreferenceOnScopeAccountOptions.SetIamID(d.Get("iam_id").(string)) + getPreferenceOnScopeAccountOptions.SetService(d.Get("service").(string)) + getPreferenceOnScopeAccountOptions.SetPreferenceID(d.Get("preference_id").(string)) + + identityPreferenceResponse, _, err := iamIdentityClient.GetPreferencesOnScopeAccountWithContext(context, getPreferenceOnScopeAccountOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetPreferenceOnScopeAccountWithContext failed: %s", err.Error()), "(Data) ibm_iam_identity_preference", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(fmt.Sprintf("%s/%s/%s/%s", *getPreferenceOnScopeAccountOptions.AccountID, *getPreferenceOnScopeAccountOptions.IamID, *getPreferenceOnScopeAccountOptions.Service, *getPreferenceOnScopeAccountOptions.PreferenceID)) + + if !core.IsNil(identityPreferenceResponse.Scope) { + if err = d.Set("scope", identityPreferenceResponse.Scope); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting scope: %s", err), "(Data) ibm_iam_identity_preference", "read", "set-scope").GetDiag() + } + } + + if !core.IsNil(identityPreferenceResponse.ValueString) { + if err = d.Set("value_string", identityPreferenceResponse.ValueString); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting value_string: %s", err), "(Data) ibm_iam_identity_preference", "read", "set-value_string").GetDiag() + } + } + + if !core.IsNil(identityPreferenceResponse.ValueListOfStrings) { + valueListOfStrings := []interface{}{} + for _, valueListOfStringsItem := range identityPreferenceResponse.ValueListOfStrings { + valueListOfStrings = append(valueListOfStrings, valueListOfStringsItem) + } + if err = d.Set("value_list_of_strings", valueListOfStrings); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting value_list_of_strings: %s", err), "(Data) ibm_iam_identity_preference", "read", "set-value_list_of_strings").GetDiag() + } + } + + return nil +} diff --git a/ibm/service/iamidentity/data_source_ibm_iam_identity_preference_test.go b/ibm/service/iamidentity/data_source_ibm_iam_identity_preference_test.go new file mode 100644 index 0000000000..0498195685 --- /dev/null +++ b/ibm/service/iamidentity/data_source_ibm_iam_identity_preference_test.go @@ -0,0 +1,62 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.106.0-09823488-20250707-071701 + */ + +package iamidentity_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccIBMIamIdentityPreferenceDataSourceBasic(t *testing.T) { + identityPreferenceResponseAccountID := fmt.Sprintf("tf_account_id_%d", acctest.RandIntRange(10, 100)) + identityPreferenceResponseIamID := fmt.Sprintf("tf_iam_id_%d", acctest.RandIntRange(10, 100)) + identityPreferenceResponseService := fmt.Sprintf("tf_service_%d", acctest.RandIntRange(10, 100)) + identityPreferenceResponsePreferenceID := fmt.Sprintf("tf_preference_id_%d", acctest.RandIntRange(10, 100)) + identityPreferenceResponseValueString := fmt.Sprintf("tf_value_string_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIamIdentityPreferenceDataSourceConfigBasic(identityPreferenceResponseAccountID, identityPreferenceResponseIamID, identityPreferenceResponseService, identityPreferenceResponsePreferenceID, identityPreferenceResponseValueString), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preference.iam_identity_preference_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preference.iam_identity_preference_instance", "account_id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preference.iam_identity_preference_instance", "iam_id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preference.iam_identity_preference_instance", "service"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preference.iam_identity_preference_instance", "preference_id"), + ), + }, + }, + }) +} + +func testAccCheckIBMIamIdentityPreferenceDataSourceConfigBasic(identityPreferenceResponseAccountID string, identityPreferenceResponseIamID string, identityPreferenceResponseService string, identityPreferenceResponsePreferenceID string, identityPreferenceResponseValueString string) string { + return fmt.Sprintf(` + resource "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = "%s" + iam_id = "%s" + service = "%s" + preference_id = "%s" + value_string = "%s" + } + + data "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = ibm_iam_identity_preference.iam_identity_preference_instance.account_id + iam_id = ibm_iam_identity_preference.iam_identity_preference_instance.iam_id + service = ibm_iam_identity_preference.iam_identity_preference_instance.service + preference_id = ibm_iam_identity_preference.iam_identity_preference_instance.preference_id + } + `, identityPreferenceResponseAccountID, identityPreferenceResponseIamID, identityPreferenceResponseService, identityPreferenceResponsePreferenceID, identityPreferenceResponseValueString) +} diff --git a/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences.go b/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences.go new file mode 100644 index 0000000000..32edc5ca6e --- /dev/null +++ b/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences.go @@ -0,0 +1,148 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.107.1-41b0fbd0-20250825-080732 + */ + +package iamidentity + +import ( + "context" + "fmt" + "log" + "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/platform-services-go-sdk/iamidentityv1" +) + +func DataSourceIBMIamIdentityPreferences() *schema.Resource { + return &schema.Resource{ + ReadContext: dataSourceIBMIamIdentityPreferencesRead, + + Schema: map[string]*schema.Schema{ + "account_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "Account id to get preferences for.", + }, + "iam_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "IAM id to get the preferences for.", + }, + "preferences": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of Identity Preferences.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "service": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Service of the preference.", + }, + "id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Unique ID of the preference.", + }, + "account_id": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Account ID of the preference, only present for scope 'account'.", + }, + "scope": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Scope of the preference, 'global' or 'account'.", + }, + "value_string": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + }, + "value_list_of_strings": &schema.Schema{ + Type: schema.TypeList, + Computed: true, + Description: "List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + }, + }, + }, + } +} + +func dataSourceIBMIamIdentityPreferencesRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_iam_identity_preferences", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getAllPreferencesOnScopeAccountOptions := &iamidentityv1.GetAllPreferencesOnScopeAccountOptions{} + + getAllPreferencesOnScopeAccountOptions.SetAccountID(d.Get("account_id").(string)) + getAllPreferencesOnScopeAccountOptions.SetIamID(d.Get("iam_id").(string)) + + identityPreferencesResponse, _, err := iamIdentityClient.GetAllPreferencesOnScopeAccountWithContext(context, getAllPreferencesOnScopeAccountOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetAllPreferencesOnScopeAccountWithContext failed: %s", err.Error()), "(Data) ibm_iam_identity_preferences", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId(dataSourceIBMIamIdentityPreferencesID(d)) + + preferences := []map[string]interface{}{} + for _, preferencesItem := range identityPreferencesResponse.Preferences { + preferencesItemMap, err := DataSourceIBMIamIdentityPreferencesIdentityPreferenceResponseToMap(&preferencesItem) // #nosec G601 + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "(Data) ibm_iam_identity_preferences", "read", "preferences-to-map").GetDiag() + } + preferences = append(preferences, preferencesItemMap) + } + if err = d.Set("preferences", preferences); err != nil { + return flex.DiscriminatedTerraformErrorf(err, fmt.Sprintf("Error setting preferences: %s", err), "(Data) ibm_iam_identity_preferences", "read", "set-preferences").GetDiag() + } + + return nil +} + +// dataSourceIBMIamIdentityPreferencesID returns a reasonable ID for the list. +func dataSourceIBMIamIdentityPreferencesID(d *schema.ResourceData) string { + return time.Now().UTC().String() +} + +func DataSourceIBMIamIdentityPreferencesIdentityPreferenceResponseToMap(model *iamidentityv1.IdentityPreferenceResponse) (map[string]interface{}, error) { + modelMap := make(map[string]interface{}) + if model.Service != nil { + modelMap["service"] = *model.Service + } + if model.ID != nil { + modelMap["id"] = *model.ID + } + if model.AccountID != nil { + modelMap["account_id"] = *model.AccountID + } + if model.Scope != nil { + modelMap["scope"] = *model.Scope + } + if model.ValueString != nil { + modelMap["value_string"] = *model.ValueString + } + if model.ValueListOfStrings != nil { + modelMap["value_list_of_strings"] = model.ValueListOfStrings + } + return modelMap, nil +} diff --git a/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences_test.go b/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences_test.go new file mode 100644 index 0000000000..eba7e870f9 --- /dev/null +++ b/ibm/service/iamidentity/data_source_ibm_iam_identity_preferences_test.go @@ -0,0 +1,74 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.107.1-41b0fbd0-20250825-080732 + */ + +package iamidentity_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/iamidentity" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/platform-services-go-sdk/iamidentityv1" + "github.com/stretchr/testify/assert" +) + +func TestAccIBMIamIdentityPreferencesDataSourceBasic(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIamIdentityPreferencesDataSourceConfigBasic(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preferences.iam_identity_preferences_instance", "id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preferences.iam_identity_preferences_instance", "account_id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preferences.iam_identity_preferences_instance", "iam_id"), + resource.TestCheckResourceAttrSet("data.ibm_iam_identity_preferences.iam_identity_preferences_instance", "preferences.#"), + ), + }, + }, + }) +} + +func testAccCheckIBMIamIdentityPreferencesDataSourceConfigBasic() string { + return fmt.Sprintf(` + data "ibm_iam_identity_preferences" "iam_identity_preferences_instance" { + account_id = "account_id" + iam_id = "iam_id" + } + `) +} + +func TestDataSourceIBMIamIdentityPreferencesIdentityPreferenceResponseToMap(t *testing.T) { + checkResult := func(result map[string]interface{}) { + model := make(map[string]interface{}) + model["service"] = "testString" + model["id"] = "testString" + model["account_id"] = "testString" + model["scope"] = "testString" + model["value_string"] = "testString" + model["value_list_of_strings"] = []string{"testString"} + + assert.Equal(t, result, model) + } + + model := new(iamidentityv1.IdentityPreferenceResponse) + model.Service = core.StringPtr("testString") + model.ID = core.StringPtr("testString") + model.AccountID = core.StringPtr("testString") + model.Scope = core.StringPtr("testString") + model.ValueString = core.StringPtr("testString") + model.ValueListOfStrings = []string{"testString"} + + result, err := iamidentity.DataSourceIBMIamIdentityPreferencesIdentityPreferenceResponseToMap(model) + assert.Nil(t, err) + checkResult(result) +} diff --git a/ibm/service/iamidentity/resource_ibm_iam_identity_preference.go b/ibm/service/iamidentity/resource_ibm_iam_identity_preference.go new file mode 100644 index 0000000000..64cccf6339 --- /dev/null +++ b/ibm/service/iamidentity/resource_ibm_iam_identity_preference.go @@ -0,0 +1,217 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +/* + * IBM OpenAPI Terraform Generator Version: 3.106.0-09823488-20250707-071701 + */ + +package iamidentity + +import ( + "context" + "fmt" + "log" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + "github.com/IBM/go-sdk-core/v5/core" + "github.com/IBM/platform-services-go-sdk/iamidentityv1" +) + +func ResourceIBMIamIdentityPreference() *schema.Resource { + return &schema.Resource{ + ReadContext: resourceIBMIamIdentityPreferenceRead, + UpdateContext: resourceIBMIamIdentityPreferenceUpdate, + DeleteContext: resourceIBMIamIdentityPreferenceDelete, + Importer: &schema.ResourceImporter{}, + + Schema: map[string]*schema.Schema{ + "account_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Account id to update preference for.", + }, + "iam_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "IAM id to update the preference for.", + }, + "service": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Service of the preference to be updated.", + }, + "preference_id": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "Identifier of preference to be updated.", + }, + "value_string": &schema.Schema{ + Type: schema.TypeString, + Required: true, + Description: "String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + }, + "value_list_of_strings": &schema.Schema{ + Type: schema.TypeList, + Optional: true, + Description: "List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present.", + Elem: &schema.Schema{Type: schema.TypeString}, + }, + "scope": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + Description: "Scope of the preference, 'global' or 'account'.", + }, + }, + } +} + +func resourceIBMIamIdentityPreferenceRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + getPreferenceOnScopeAccountOptions := &iamidentityv1.GetPreferencesOnScopeAccountOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "sep-id-parts").GetDiag() + } + + getPreferenceOnScopeAccountOptions.SetAccountID(parts[0]) + getPreferenceOnScopeAccountOptions.SetIamID(parts[1]) + getPreferenceOnScopeAccountOptions.SetService(parts[2]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[3]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[4]) + + identityPreferenceResponse, response, err := iamIdentityClient.GetPreferencesOnScopeAccountWithContext(context, getPreferenceOnScopeAccountOptions) + if err != nil { + if response != nil && response.StatusCode == 404 { + d.SetId("") + return nil + } + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("GetPreferenceOnScopeAccountWithContext failed: %s", err.Error()), "ibm_iam_identity_preference", "read") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + if err = d.Set("account_id", identityPreferenceResponse.AccountID); err != nil { + err = fmt.Errorf("Error setting account_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-account_id").GetDiag() + } + if err = d.Set("service", identityPreferenceResponse.Service); err != nil { + err = fmt.Errorf("Error setting service: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-service").GetDiag() + } + if err = d.Set("value_string", identityPreferenceResponse.ValueString); err != nil { + err = fmt.Errorf("Error setting value_string: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-value_string").GetDiag() + } + if !core.IsNil(identityPreferenceResponse.ValueListOfStrings) { + if err = d.Set("value_list_of_strings", identityPreferenceResponse.ValueListOfStrings); err != nil { + err = fmt.Errorf("Error setting value_list_of_strings: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-value_list_of_strings").GetDiag() + } + } + if !core.IsNil(identityPreferenceResponse.Scope) { + if err = d.Set("scope", identityPreferenceResponse.Scope); err != nil { + err = fmt.Errorf("Error setting scope: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-scope").GetDiag() + } + } + if !core.IsNil(identityPreferenceResponse.ID) { + if err = d.Set("preference_id", identityPreferenceResponse.ID); err != nil { + err = fmt.Errorf("Error setting preference_id: %s", err) + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "read", "set-preference_id").GetDiag() + } + } + + return nil +} + +func resourceIBMIamIdentityPreferenceUpdate(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "update", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + updatePreferenceOnScopeAccountOptions := &iamidentityv1.UpdatePreferenceOnScopeAccountOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "update", "sep-id-parts").GetDiag() + } + + updatePreferenceOnScopeAccountOptions.SetAccountID(parts[0]) + updatePreferenceOnScopeAccountOptions.SetIamID(parts[1]) + updatePreferenceOnScopeAccountOptions.SetService(parts[2]) + updatePreferenceOnScopeAccountOptions.SetPreferenceID(parts[3]) + updatePreferenceOnScopeAccountOptions.SetPreferenceID(parts[4]) + updatePreferenceOnScopeAccountOptions.SetAccountID(d.Get("account_id").(string)) + updatePreferenceOnScopeAccountOptions.SetIamID(d.Get("iam_id").(string)) + updatePreferenceOnScopeAccountOptions.SetService(d.Get("service").(string)) + updatePreferenceOnScopeAccountOptions.SetPreferenceID(d.Get("preference_id").(string)) + updatePreferenceOnScopeAccountOptions.SetValueString(d.Get("value_string").(string)) + if _, ok := d.GetOk("value_list_of_strings"); ok { + var valueListOfStrings []string + for _, v := range d.Get("value_list_of_strings").([]interface{}) { + valueListOfStringsItem := v.(string) + valueListOfStrings = append(valueListOfStrings, valueListOfStringsItem) + } + updatePreferenceOnScopeAccountOptions.SetValueListOfStrings(valueListOfStrings) + } + + _, _, err = iamIdentityClient.UpdatePreferenceOnScopeAccountWithContext(context, updatePreferenceOnScopeAccountOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("UpdatePreferenceOnScopeAccountWithContext failed: %s", err.Error()), "ibm_iam_identity_preference", "update") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + return resourceIBMIamIdentityPreferenceRead(context, d, meta) +} + +func resourceIBMIamIdentityPreferenceDelete(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + iamIdentityClient, err := meta.(conns.ClientSession).IAMIdentityV1API() + if err != nil { + tfErr := flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "delete", "initialize-client") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + deletePreferenceOnScopeAccountOptions := &iamidentityv1.DeletePreferencesOnScopeAccountOptions{} + + parts, err := flex.SepIdParts(d.Id(), "/") + if err != nil { + return flex.DiscriminatedTerraformErrorf(err, err.Error(), "ibm_iam_identity_preference", "delete", "sep-id-parts").GetDiag() + } + + deletePreferenceOnScopeAccountOptions.SetAccountID(parts[0]) + deletePreferenceOnScopeAccountOptions.SetIamID(parts[1]) + deletePreferenceOnScopeAccountOptions.SetService(parts[2]) + deletePreferenceOnScopeAccountOptions.SetPreferenceID(parts[3]) + deletePreferenceOnScopeAccountOptions.SetPreferenceID(parts[4]) + + _, err = iamIdentityClient.DeletePreferencesOnScopeAccount(deletePreferenceOnScopeAccountOptions) + if err != nil { + tfErr := flex.TerraformErrorf(err, fmt.Sprintf("DeletePreferenceOnScopeAccountWithContext failed: %s", err.Error()), "ibm_iam_identity_preference", "delete") + log.Printf("[DEBUG]\n%s", tfErr.GetDebugMessage()) + return tfErr.GetDiag() + } + + d.SetId("") + + return nil +} diff --git a/ibm/service/iamidentity/resource_ibm_iam_identity_preference_test.go b/ibm/service/iamidentity/resource_ibm_iam_identity_preference_test.go new file mode 100644 index 0000000000..8c99cd156d --- /dev/null +++ b/ibm/service/iamidentity/resource_ibm_iam_identity_preference_test.go @@ -0,0 +1,147 @@ +// Copyright IBM Corp. 2025 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package iamidentity_test + +import ( + "fmt" + "testing" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns" + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/IBM/platform-services-go-sdk/iamidentityv1" +) + +func TestAccIBMIamIdentityPreferenceBasic(t *testing.T) { + var conf iamidentityv1.IdentityPreferenceResponse + accountID := fmt.Sprintf("tf_account_id_%d", acctest.RandIntRange(10, 100)) + iamID := fmt.Sprintf("tf_iam_id_%d", acctest.RandIntRange(10, 100)) + service := fmt.Sprintf("tf_service_%d", acctest.RandIntRange(10, 100)) + preferenceID := fmt.Sprintf("tf_preference_id_%d", acctest.RandIntRange(10, 100)) + valueString := fmt.Sprintf("tf_value_string_%d", acctest.RandIntRange(10, 100)) + valueStringUpdate := fmt.Sprintf("tf_value_string_%d", acctest.RandIntRange(10, 100)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMIamIdentityPreferenceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMIamIdentityPreferenceConfigBasic(accountID, iamID, service, preferenceID, valueString), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMIamIdentityPreferenceExists("ibm_iam_identity_preference.iam_identity_preference_instance", conf), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "account_id", accountID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "iam_id", iamID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "service", service), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "preference_id", preferenceID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "value_string", valueString), + ), + }, + resource.TestStep{ + Config: testAccCheckIBMIamIdentityPreferenceConfigBasic(accountID, iamID, service, preferenceID, valueStringUpdate), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "account_id", accountID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "iam_id", iamID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "service", service), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "preference_id", preferenceID), + resource.TestCheckResourceAttr("ibm_iam_identity_preference.iam_identity_preference_instance", "value_string", valueStringUpdate), + ), + }, + resource.TestStep{ + ResourceName: "ibm_iam_identity_preference.iam_identity_preference", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testAccCheckIBMIamIdentityPreferenceConfigBasic(accountID string, iamID string, service string, preferenceID string, valueString string) string { + return fmt.Sprintf(` + resource "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = "%s" + iam_id = "%s" + service = "%s" + preference_id = "%s" + value_string = "%s" + } + `, accountID, iamID, service, preferenceID, valueString) +} + +func testAccCheckIBMIamIdentityPreferenceExists(n string, obj iamidentityv1.IdentityPreferenceResponse) resource.TestCheckFunc { + + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + iamIdentityClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).IAMIdentityV1API() + if err != nil { + return err + } + + getPreferenceOnScopeAccountOptions := &iamidentityv1.GetPreferencesOnScopeAccountOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getPreferenceOnScopeAccountOptions.SetAccountID(parts[0]) + getPreferenceOnScopeAccountOptions.SetIamID(parts[1]) + getPreferenceOnScopeAccountOptions.SetService(parts[2]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[3]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[4]) + + identityPreferenceResponse, _, err := iamIdentityClient.GetPreferencesOnScopeAccount(getPreferenceOnScopeAccountOptions) + if err != nil { + return err + } + + obj = *identityPreferenceResponse + return nil + } +} + +func testAccCheckIBMIamIdentityPreferenceDestroy(s *terraform.State) error { + iamIdentityClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).IAMIdentityV1API() + if err != nil { + return err + } + for _, rs := range s.RootModule().Resources { + if rs.Type != "ibm_iam_identity_preference" { + continue + } + + getPreferenceOnScopeAccountOptions := &iamidentityv1.GetPreferencesOnScopeAccountOptions{} + + parts, err := flex.SepIdParts(rs.Primary.ID, "/") + if err != nil { + return err + } + + getPreferenceOnScopeAccountOptions.SetAccountID(parts[0]) + getPreferenceOnScopeAccountOptions.SetIamID(parts[1]) + getPreferenceOnScopeAccountOptions.SetService(parts[2]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[3]) + getPreferenceOnScopeAccountOptions.SetPreferenceID(parts[4]) + + // Try to find the key + _, response, err := iamIdentityClient.GetPreferencesOnScopeAccount(getPreferenceOnScopeAccountOptions) + + if err == nil { + return fmt.Errorf("iam_identity_preference still exists: %s", rs.Primary.ID) + } else if response.StatusCode != 404 { + return fmt.Errorf("Error checking for iam_identity_preference (%s) has been destroyed: %s", rs.Primary.ID, err) + } + } + + return nil +} diff --git a/instructions.md b/instructions.md new file mode 100644 index 0000000000..68d6643e96 --- /dev/null +++ b/instructions.md @@ -0,0 +1,98 @@ +# Instructions + +To add the generated code into the IBM Terraform Provider, you will need to make the following changes to the project. Note that these changes have already been generated into this local development environment, with the exception of the change to `website/allowed-subcategories.txt` which is unnecessary for local development. + +### Changes to `provider.go` + +- Add the following entry to `import`: +``` + "github.com/IBM-Cloud/terraform-provider-ibm/ibm/service/iamidentity" +``` + +- Add the following entries to `DataSourcesMap`: +``` + "ibm_iam_identity_preference": iamidentity.DataSourceIBMIamIdentityPreference(), +``` + +- Add the following entries to `ResourcesMap`: +``` + "ibm_iam_identity_preference": iamidentity.ResourceIBMIamIdentityPreference(), +``` + +### Changes to `config.go` + +- Add an import for the generated Go SDK: +``` + "github.com/IBM/platform-services-go-sdk/iamidentityv1" +``` + +- Add a method to the `ClientSession interface`: +``` + IamIdentityV1() (*iamidentityv1.IamIdentityV1, error) +``` + +- Add two fields to the `clientSession struct`: +``` + iamIdentityClient *iamidentityv1.IamIdentityV1 + iamIdentityClientErr error +``` + +- Implement a new method on the `clientSession struct`: +``` + // IAM Identity Services + func (session clientSession) IamIdentityV1() (*iamidentityv1.IamIdentityV1, error) { + return session.iamIdentityClient, session.iamIdentityClientErr + } +``` + +- In the `ClientSession()` method of `Config`, below the existing block of code that creates an authenticator: +``` + var authenticator core.Authenticator + if c.BluemixAPIKey != "" { + authenticator = &core.IamAuthenticator{ + ApiKey: c.BluemixAPIKey, + URL: EnvFallBack([]string{"IBMCLOUD_IAM_API_ENDPOINT"}, "https://iam.cloud.ibm.com") + "/identity/token", + } + } else if strings.HasPrefix(sess.BluemixSession.Config.IAMAccessToken, "Bearer") { + authenticator = &core.BearerTokenAuthenticator{ + BearerToken: sess.BluemixSession.Config.IAMAccessToken[7:], + } + } else { + authenticator = &core.BearerTokenAuthenticator{ + BearerToken: sess.BluemixSession.Config.IAMAccessToken, + } + } +``` + +- In the `ClientSession()` method of `Config`, add the code to initialize the service client: +``` + + // Construct an instance of the 'IAM Identity Services' service. + if session.iamIdentityClientErr == nil { + // Construct the service options. + iamIdentityClientOptions := &iamidentityv1.IamIdentityV1Options{ + Authenticator: authenticator, + } + + // Construct the service client. + session.iamIdentityClient, err = iamidentityv1.NewIamIdentityV1(iamIdentityClientOptions) + if err == nil { + // Enable retries for API calls + session.iamIdentityClient.Service.EnableRetries(c.RetryCount, c.RetryDelay) + // Add custom header for analytics + session.iamIdentityClient.SetDefaultHeaders(gohttp.Header{ + "X-Original-User-Agent": { fmt.Sprintf("terraform-provider-ibm/%s", version.Version) }, + }) + } else { + session.iamIdentityClientErr = fmt.Errorf("Error occurred while constructing 'IAM Identity Services' service client: %q", err) + } + } +``` + +### Changes to website/allowed-subcategories.txt + +Insert the following line into the website/allowed-subcategories.txt file (in alphabetic order): + +``` +IAM Identity Services +``` diff --git a/website/docs/d/iam_identity_preference.html.markdown b/website/docs/d/iam_identity_preference.html.markdown new file mode 100644 index 0000000000..36fea4532f --- /dev/null +++ b/website/docs/d/iam_identity_preference.html.markdown @@ -0,0 +1,41 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_iam_identity_preference" +description: |- + Get information about iam_identity_preference +subcategory: "IAM Identity Services" +--- + +# ibm_iam_identity_preference + +Provides a read-only data source to retrieve information about an iam_identity_preference. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_iam_identity_preference" "iam_identity_preference" { + account_id = ibm_iam_identity_preference.iam_identity_preference_instance.account_id + iam_id = ibm_iam_identity_preference.iam_identity_preference_instance.iam_id + preference_id = ibm_iam_identity_preference.iam_identity_preference_instance.preference_id + service = ibm_iam_identity_preference.iam_identity_preference_instance.service +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `account_id` - (Required, Forces new resource, String) Account id to get preference for. +* `iam_id` - (Required, Forces new resource, String) IAM id to get the preference for. +* `preference_id` - (Required, Forces new resource, String) Identifier of preference to be fetched. +* `service` - (Required, Forces new resource, String) Service of the preference to be fetched. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the iam_identity_preference. +* `scope` - (String) Scope of the preference, 'global' or 'account'. +* `value_list_of_strings` - (List) List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. +* `value_string` - (String) String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. + diff --git a/website/docs/d/iam_identity_preferences.html.markdown b/website/docs/d/iam_identity_preferences.html.markdown new file mode 100644 index 0000000000..a14ac35f2c --- /dev/null +++ b/website/docs/d/iam_identity_preferences.html.markdown @@ -0,0 +1,42 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_iam_identity_preferences" +description: |- + Get information about iam_identity_preferences +subcategory: "IAM Identity Services" +--- + +# ibm_iam_identity_preferences + +Provides a read-only data source to retrieve information about iam_identity_preferences. You can then reference the fields of the data source in other resources within the same configuration by using interpolation syntax. + +## Example Usage + +```hcl +data "ibm_iam_identity_preferences" "iam_identity_preferences" { + account_id = "account_id" + iam_id = "iam_id" +} +``` + +## Argument Reference + +You can specify the following arguments for this data source. + +* `account_id` - (Required, Forces new resource, String) Account id to get preferences for. +* `iam_id` - (Required, Forces new resource, String) IAM id to get the preferences for. + +## Attribute Reference + +After your data source is created, you can read values from the following attributes. + +* `id` - The unique identifier of the iam_identity_preferences. +* `preferences` - (List) List of Identity Preferences. +Nested schema for **preferences**: + * `account_id` - (String) Account ID of the preference, only present for scope 'account'. + * `id` - (String) Unique ID of the preference. + * `scope` - (String) Scope of the preference, 'global' or 'account'. + * `service` - (String) Service of the preference. + * `value_list_of_strings` - (List) List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. + * `value_string` - (String) String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. + diff --git a/website/docs/r/iam_identity_preference.html.markdown b/website/docs/r/iam_identity_preference.html.markdown new file mode 100644 index 0000000000..cadf48cb40 --- /dev/null +++ b/website/docs/r/iam_identity_preference.html.markdown @@ -0,0 +1,62 @@ +--- +layout: "ibm" +page_title: "IBM : ibm_iam_identity_preference" +description: |- + Manages iam_identity_preference. +subcategory: "IAM Identity Services" +--- + +# ibm_iam_identity_preference + +Create, update, and delete iam_identity_preferences with this resource. + +## Example Usage + +```hcl +resource "ibm_iam_identity_preference" "iam_identity_preference_instance" { + account_id = "account_id" + iam_id = "iam_id" + preference_id = "preference_id" + service = "service" + value_string = "value_string" +} +``` + +## Argument Reference + +You can specify the following arguments for this resource. + +* `account_id` - (Required, Forces new resource, String) Account id to update preference for. +* `iam_id` - (Required, Forces new resource, String) IAM id to update the preference for. +* `preference_id` - (Required, Forces new resource, String) Identifier of preference to be updated. +* `service` - (Required, Forces new resource, String) Service of the preference to be updated. +* `value_list_of_strings` - (Optional, List) List of value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. +* `value_string` - (Required, String) String value of the preference, only one value property is set, either 'value_string' or 'value_list_of_strings' is present. + +## Attribute Reference + +After your resource is created, you can read values from the listed arguments and the following attributes. + +* `id` - The unique identifier of the iam_identity_preference. +* `preference_id` - (String) Unique ID of the preference. +* `scope` - (String) Scope of the preference, 'global' or 'account'. + + +## Import + +You can import the `ibm_iam_identity_preference` resource by using `id`. +The `id` property can be formed from `account_id`, `iam_id`, `service`, `preference_id`, and `preference_id` in the following format: + +
+<account_id>/<iam_id>/<service>/<preference_id>/<preference_id>
+
+* `account_id`: A string. Account id to update preference for. +* `iam_id`: A string. IAM id to update the preference for. +* `service`: A string. Service of the preference to be updated. +* `preference_id`: A string. Identifier of preference to be updated. +* `preference_id`: A string. Unique ID of the preference. + +# Syntax +
+$ terraform import ibm_iam_identity_preference.iam_identity_preference <account_id>/<iam_id>/<service>/<preference_id>/<preference_id>
+