Skip to content

azurermCosmosdbSqlRoleAssignment

Manages a Cosmos DB SQL Role Assignment.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const dataAzurermClientConfigCurrent =
  new azurerm.dataAzurermClientConfig.DataAzurermClientConfig(
    this,
    "current",
    {}
  );
const azurermCosmosdbAccountExample =
  new azurerm.cosmosdbAccount.CosmosdbAccount(this, "example_2", {
    consistency_policy: [
      {
        consistency_level: "Strong",
      },
    ],
    geo_location: [
      {
        failover_priority: 0,
        location: azurermResourceGroupExample.location,
      },
    ],
    kind: "GlobalDocumentDB",
    location: azurermResourceGroupExample.location,
    name: "example-cosmosdb",
    offer_type: "Standard",
    resource_group_name: azurermResourceGroupExample.name,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermCosmosdbAccountExample.overrideLogicalId("example");
const azurermCosmosdbSqlRoleDefinitionExample =
  new azurerm.cosmosdbSqlRoleDefinition.CosmosdbSqlRoleDefinition(
    this,
    "example_3",
    {
      account_name: azurermCosmosdbAccountExample.name,
      assignable_scopes: [azurermCosmosdbAccountExample.id],
      name: "examplesqlroledef",
      permissions: [
        {
          data_actions: [
            "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/items/read",
          ],
        },
      ],
      resource_group_name: azurermResourceGroupExample.name,
      type: "CustomRole",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermCosmosdbSqlRoleDefinitionExample.overrideLogicalId("example");
const azurermCosmosdbSqlRoleAssignmentExample =
  new azurerm.cosmosdbSqlRoleAssignment.CosmosdbSqlRoleAssignment(
    this,
    "example_4",
    {
      account_name: azurermCosmosdbAccountExample.name,
      name: "736180af-7fbc-4c7f-9004-22735173c1c3",
      principal_id: dataAzurermClientConfigCurrent.objectId,
      resource_group_name: azurermResourceGroupExample.name,
      role_definition_id: azurermCosmosdbSqlRoleDefinitionExample.id,
      scope: azurermCosmosdbAccountExample.id,
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermCosmosdbSqlRoleAssignmentExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

  • resourceGroupName - (Required) The name of the Resource Group in which the Cosmos DB SQL Role Assignment is created. Changing this forces a new resource to be created.

  • accountName - (Required) The name of the Cosmos DB Account. Changing this forces a new resource to be created.

  • principalId - (Required) The ID of the Principal (Client) in Azure Active Directory. Changing this forces a new resource to be created.

  • roleDefinitionId - (Required) The resource ID of the Cosmos DB SQL Role Definition.

  • scope - (Required) The data plane resource path for which access is being granted through this Cosmos DB SQL Role Assignment. Changing this forces a new resource to be created.

  • name - (Optional) The GUID as the name of the Cosmos DB SQL Role Assignment - one will be generated if not specified. Changing this forces a new resource to be created.

Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

  • id - The ID of the Cosmos DB SQL Role Assignment.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 30 minutes) Used when creating the Cosmos DB SQL Role Assignment.
  • read - (Defaults to 5 minutes) Used when retrieving the Cosmos DB SQL Role Assignment.
  • update - (Defaults to 30 minutes) Used when updating the Cosmos DB SQL Role Assignment.
  • delete - (Defaults to 30 minutes) Used when deleting the Cosmos DB SQL Role Assignment.

Import

Cosmos DB SQL Role Assignments can be imported using the resourceId, e.g.

terraform import azurerm_cosmosdb_sql_role_assignment.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.DocumentDB/databaseAccounts/account1/sqlRoleAssignments/9e007587-dbcd-4190-84cb-fcab5a09ca39