oci.Identity.getCompartments
Explore with Pulumi AI
This data source provides the list of Compartments in Oracle Cloud Infrastructure Identity service.
Lists the compartments in a specified compartment. The members of the list returned depends on the values set for several parameters.
With the exception of the tenancy (root compartment), the ListCompartments operation
returns only the first-level child compartments in the parent compartment specified in
compartmentId. The list does not include any subcompartments of the child
compartments (grandchildren).
The parameter accessLevel specifies whether to return only those compartments for which the
requestor has INSPECT permissions on at least one resource directly
or indirectly (the resource can be in a subcompartment).
The parameter compartmentIdInSubtree applies only when you perform ListCompartments on the
tenancy (root compartment). When set to true, the entire hierarchy of compartments can be returned.
To get a full list of all compartments and subcompartments in the tenancy (root compartment),
set the parameter compartmentIdInSubtree to true and accessLevel to ANY.
See Where to Get the Tenancy’s OCID and User’s OCID.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as oci from "@pulumi/oci";
const testCompartments = oci.Identity.getCompartments({
    compartmentId: compartmentId,
    accessLevel: compartmentAccessLevel,
    compartmentIdInSubtree: compartmentCompartmentIdInSubtree,
    name: compartmentName,
    state: compartmentState,
});
import pulumi
import pulumi_oci as oci
test_compartments = oci.Identity.get_compartments(compartment_id=compartment_id,
    access_level=compartment_access_level,
    compartment_id_in_subtree=compartment_compartment_id_in_subtree,
    name=compartment_name,
    state=compartment_state)
package main
import (
	"github.com/pulumi/pulumi-oci/sdk/v2/go/oci/identity"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := identity.GetCompartments(ctx, &identity.GetCompartmentsArgs{
			CompartmentId:          compartmentId,
			AccessLevel:            pulumi.StringRef(compartmentAccessLevel),
			CompartmentIdInSubtree: pulumi.BoolRef(compartmentCompartmentIdInSubtree),
			Name:                   pulumi.StringRef(compartmentName),
			State:                  pulumi.StringRef(compartmentState),
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Oci = Pulumi.Oci;
return await Deployment.RunAsync(() => 
{
    var testCompartments = Oci.Identity.GetCompartments.Invoke(new()
    {
        CompartmentId = compartmentId,
        AccessLevel = compartmentAccessLevel,
        CompartmentIdInSubtree = compartmentCompartmentIdInSubtree,
        Name = compartmentName,
        State = compartmentState,
    });
});
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.oci.Identity.IdentityFunctions;
import com.pulumi.oci.Identity.inputs.GetCompartmentsArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }
    public static void stack(Context ctx) {
        final var testCompartments = IdentityFunctions.getCompartments(GetCompartmentsArgs.builder()
            .compartmentId(compartmentId)
            .accessLevel(compartmentAccessLevel)
            .compartmentIdInSubtree(compartmentCompartmentIdInSubtree)
            .name(compartmentName)
            .state(compartmentState)
            .build());
    }
}
variables:
  testCompartments:
    fn::invoke:
      function: oci:Identity:getCompartments
      arguments:
        compartmentId: ${compartmentId}
        accessLevel: ${compartmentAccessLevel}
        compartmentIdInSubtree: ${compartmentCompartmentIdInSubtree}
        name: ${compartmentName}
        state: ${compartmentState}
Using getCompartments
Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.
function getCompartments(args: GetCompartmentsArgs, opts?: InvokeOptions): Promise<GetCompartmentsResult>
function getCompartmentsOutput(args: GetCompartmentsOutputArgs, opts?: InvokeOptions): Output<GetCompartmentsResult>def get_compartments(access_level: Optional[str] = None,
                     compartment_id: Optional[str] = None,
                     compartment_id_in_subtree: Optional[bool] = None,
                     filters: Optional[Sequence[GetCompartmentsFilter]] = None,
                     name: Optional[str] = None,
                     state: Optional[str] = None,
                     opts: Optional[InvokeOptions] = None) -> GetCompartmentsResult
def get_compartments_output(access_level: Optional[pulumi.Input[str]] = None,
                     compartment_id: Optional[pulumi.Input[str]] = None,
                     compartment_id_in_subtree: Optional[pulumi.Input[bool]] = None,
                     filters: Optional[pulumi.Input[Sequence[pulumi.Input[GetCompartmentsFilterArgs]]]] = None,
                     name: Optional[pulumi.Input[str]] = None,
                     state: Optional[pulumi.Input[str]] = None,
                     opts: Optional[InvokeOptions] = None) -> Output[GetCompartmentsResult]func GetCompartments(ctx *Context, args *GetCompartmentsArgs, opts ...InvokeOption) (*GetCompartmentsResult, error)
func GetCompartmentsOutput(ctx *Context, args *GetCompartmentsOutputArgs, opts ...InvokeOption) GetCompartmentsResultOutput> Note: This function is named GetCompartments in the Go SDK.
public static class GetCompartments 
{
    public static Task<GetCompartmentsResult> InvokeAsync(GetCompartmentsArgs args, InvokeOptions? opts = null)
    public static Output<GetCompartmentsResult> Invoke(GetCompartmentsInvokeArgs args, InvokeOptions? opts = null)
}public static CompletableFuture<GetCompartmentsResult> getCompartments(GetCompartmentsArgs args, InvokeOptions options)
public static Output<GetCompartmentsResult> getCompartments(GetCompartmentsArgs args, InvokeOptions options)
fn::invoke:
  function: oci:Identity/getCompartments:getCompartments
  arguments:
    # arguments dictionaryThe following arguments are supported:
- CompartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- AccessLevel string
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- CompartmentId boolIn Subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- Filters
List<GetCompartments Filter> 
- Name string
- A filter to only return resources that match the given name exactly.
- State string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- CompartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- AccessLevel string
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- CompartmentId boolIn Subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- Filters
[]GetCompartments Filter 
- Name string
- A filter to only return resources that match the given name exactly.
- State string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- compartmentId String
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- accessLevel String
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- compartmentId BooleanIn Subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- filters
List<GetCompartments Filter> 
- name String
- A filter to only return resources that match the given name exactly.
- state String
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- compartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- accessLevel string
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- compartmentId booleanIn Subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- filters
GetCompartments Filter[] 
- name string
- A filter to only return resources that match the given name exactly.
- state string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- compartment_id str
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- access_level str
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- compartment_id_ boolin_ subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- filters
Sequence[GetCompartments Filter] 
- name str
- A filter to only return resources that match the given name exactly.
- state str
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- compartmentId String
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- accessLevel String
- Valid values are - ANYand- ACCESSIBLE. Default is- ANY. Setting this to- ACCESSIBLEreturns only those compartments for which the user has INSPECT permissions directly or indirectly (permissions can be on a resource in a subcompartment). For the compartments on which the user indirectly has INSPECT permissions, a restricted set of fields is returned.- When set to - ANYpermissions are not checked.
- compartmentId BooleanIn Subtree 
- Default is false. Can only be set to true when performing ListCompartments on the tenancy (root compartment). When set to true, the hierarchy of compartments is traversed and all compartments and subcompartments in the tenancy are returned depending on the the setting of accessLevel.
- filters List<Property Map>
- name String
- A filter to only return resources that match the given name exactly.
- state String
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
getCompartments Result
The following output properties are available:
- CompartmentId string
- The OCID of the parent compartment containing the compartment.
- Compartments
List<GetCompartments Compartment> 
- The list of compartments.
- Id string
- The provider-assigned unique ID for this managed resource.
- AccessLevel string
- CompartmentId boolIn Subtree 
- Filters
List<GetCompartments Filter> 
- Name string
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- State string
- The compartment's current state.
- CompartmentId string
- The OCID of the parent compartment containing the compartment.
- Compartments
[]GetCompartments Compartment 
- The list of compartments.
- Id string
- The provider-assigned unique ID for this managed resource.
- AccessLevel string
- CompartmentId boolIn Subtree 
- Filters
[]GetCompartments Filter 
- Name string
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- State string
- The compartment's current state.
- compartmentId String
- The OCID of the parent compartment containing the compartment.
- compartments
List<GetCompartments Compartment> 
- The list of compartments.
- id String
- The provider-assigned unique ID for this managed resource.
- accessLevel String
- compartmentId BooleanIn Subtree 
- filters
List<GetCompartments Filter> 
- name String
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- state String
- The compartment's current state.
- compartmentId string
- The OCID of the parent compartment containing the compartment.
- compartments
GetCompartments Compartment[] 
- The list of compartments.
- id string
- The provider-assigned unique ID for this managed resource.
- accessLevel string
- compartmentId booleanIn Subtree 
- filters
GetCompartments Filter[] 
- name string
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- state string
- The compartment's current state.
- compartment_id str
- The OCID of the parent compartment containing the compartment.
- compartments
Sequence[GetCompartments Compartment] 
- The list of compartments.
- id str
- The provider-assigned unique ID for this managed resource.
- access_level str
- compartment_id_ boolin_ subtree 
- filters
Sequence[GetCompartments Filter] 
- name str
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- state str
- The compartment's current state.
- compartmentId String
- The OCID of the parent compartment containing the compartment.
- compartments List<Property Map>
- The list of compartments.
- id String
- The provider-assigned unique ID for this managed resource.
- accessLevel String
- compartmentId BooleanIn Subtree 
- filters List<Property Map>
- name String
- The name you assign to the compartment during creation. The name must be unique across all compartments in the parent. Avoid entering confidential information.
- state String
- The compartment's current state.
Supporting Types
GetCompartmentsCompartment  
- CompartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Dictionary<string, string>
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- Description string
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- EnableDelete bool
- Dictionary<string, string>
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- Id string
- The OCID of the compartment.
- InactiveState string
- The detailed status of INACTIVE lifecycleState.
- IsAccessible bool
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- Name string
- A filter to only return resources that match the given name exactly.
- State string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- TimeCreated string
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
- CompartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- map[string]string
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- Description string
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- EnableDelete bool
- map[string]string
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- Id string
- The OCID of the compartment.
- InactiveState string
- The detailed status of INACTIVE lifecycleState.
- IsAccessible bool
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- Name string
- A filter to only return resources that match the given name exactly.
- State string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- TimeCreated string
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
- compartmentId String
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Map<String,String>
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- description String
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- enableDelete Boolean
- Map<String,String>
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- id String
- The OCID of the compartment.
- inactiveState String
- The detailed status of INACTIVE lifecycleState.
- isAccessible Boolean
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- name String
- A filter to only return resources that match the given name exactly.
- state String
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- timeCreated String
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
- compartmentId string
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- {[key: string]: string}
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- description string
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- enableDelete boolean
- {[key: string]: string}
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- id string
- The OCID of the compartment.
- inactiveState string
- The detailed status of INACTIVE lifecycleState.
- isAccessible boolean
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- name string
- A filter to only return resources that match the given name exactly.
- state string
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- timeCreated string
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
- compartment_id str
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Mapping[str, str]
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- description str
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- enable_delete bool
- Mapping[str, str]
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- id str
- The OCID of the compartment.
- inactive_state str
- The detailed status of INACTIVE lifecycleState.
- is_accessible bool
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- name str
- A filter to only return resources that match the given name exactly.
- state str
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- time_created str
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
- compartmentId String
- The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Map<String>
- Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see Resource Tags. Example: {"Operations.CostCenter": "42"}
- description String
- The description you assign to the compartment. Does not have to be unique, and it's changeable.
- enableDelete Boolean
- Map<String>
- Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see Resource Tags. Example: {"Department": "Finance"}
- id String
- The OCID of the compartment.
- inactiveState String
- The detailed status of INACTIVE lifecycleState.
- isAccessible Boolean
- Indicates whether or not the compartment is accessible for the user making the request. Returns true when the user has INSPECT permissions directly on a resource in the compartment or indirectly (permissions can be on a resource in a subcompartment).
- name String
- A filter to only return resources that match the given name exactly.
- state String
- A filter to only return resources that match the given lifecycle state. The state value is case-insensitive.
- timeCreated String
- Date and time the compartment was created, in the format defined by RFC3339. Example: 2016-08-25T21:10:29.600Z
GetCompartmentsFilter  
Package Details
- Repository
- oci pulumi/pulumi-oci
- License
- Apache-2.0
- Notes
- This Pulumi package is based on the ociTerraform Provider.