Search code examples
terraformoracle-cloud-infrastructure

Terraform. Create a user in a secondary instance of Oracle Identity Cloud Service (IDCS)


I am using Terraform to create several technical users for my applicationl, like this one:

resource "oci_identity_user" "scheduler_user" {
    compartment_id = var.tenancy_ocid
    name = "scheduler"
    description = "This user is used by the cron process."
}

It creates a user inside the primary user database of my OCI tenancy.

Oracle Cloud supports multiple user databases using one or more secondary instances of Identity Cloud Service. It is useful, if you want to separate users of a custom application.

https://docs.oracle.com/en/cloud/paas/identity-cloud/uaids/multiple-instances.html

The problem is that I have no idea, how to address this secondary IDCS instance from my Terraform script.


Solution

  • Identity Cloud Service doesn't support Terraform, but has a fully-features REST API (or SDKs) that you can use:

    https://docs.oracle.com/en/cloud/paas/identity-cloud/rest-api/index.html

    You can either create users individual (https://docs.oracle.com/en/cloud/paas/identity-cloud/rest-api/op-admin-v1-users-post.html) or through the bulk API if you want to do several at once (https://docs.oracle.com/en/cloud/paas/identity-cloud/rest-api/op-admin-v1-bulk-post.html).

    For example, to create users individually, make the following REST call:

    curl
    -X POST
    -H "Content-Type:application/scim+json"
    -H "Authorization: Bearer <Access Token Value>"
    https://tenant-base-url/admin/v1/Users
    

    Passing in the following body:

    {
      "schemas": [
        "urn:ietf:params:scim:schemas:core:2.0:User"
      ],
      "userName": "[email protected]",
      "name": {
        "familyName": "Jensen",
        "givenName": "Barbara",
        "middleName": "Jane"
      },
      "emails": [
        {
          "value": "[email protected]",
          "type": "work",
          "primary": true
        }
      ]
    }
    

    You will need to obtain an access token from IDCS first so you can include that token in your authorization header. Refer to the Quick Start: https://docs.oracle.com/en/cloud/paas/identity-cloud/rest-api/QuickStart.html