1. Packages
  2. Oracle Cloud Infrastructure
  3. API Docs
  4. Identity
  5. getCompartments
Oracle Cloud Infrastructure v0.20.1 published on Tuesday, Jun 6, 2023 by Pulumi

oci.Identity.getCompartments

Explore with Pulumi AI

oci logo
Oracle Cloud Infrastructure v0.20.1 published on Tuesday, Jun 6, 2023 by Pulumi

    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

    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 = @var.Compartment_id,
            AccessLevel = @var.Compartment_access_level,
            CompartmentIdInSubtree = @var.Compartment_compartment_id_in_subtree,
            Name = @var.Compartment_name,
            State = @var.Compartment_state,
        });
    
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-oci/sdk/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:          _var.Compartment_id,
    			AccessLevel:            pulumi.StringRef(_var.Compartment_access_level),
    			CompartmentIdInSubtree: pulumi.BoolRef(_var.Compartment_compartment_id_in_subtree),
    			Name:                   pulumi.StringRef(_var.Compartment_name),
    			State:                  pulumi.StringRef(_var.Compartment_state),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    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(var_.compartment_id())
                .accessLevel(var_.compartment_access_level())
                .compartmentIdInSubtree(var_.compartment_compartment_id_in_subtree())
                .name(var_.compartment_name())
                .state(var_.compartment_state())
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_oci as oci
    
    test_compartments = oci.Identity.get_compartments(compartment_id=%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference),
        access_level=%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference),
        compartment_id_in_subtree=%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference),
        name=%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference),
        state=%!v(PANIC=Format method: runtime error: invalid memory address or nil pointer dereference))
    
    import * as pulumi from "@pulumi/pulumi";
    import * as oci from "@pulumi/oci";
    
    const testCompartments = oci.Identity.getCompartments({
        compartmentId: _var.compartment_id,
        accessLevel: _var.compartment_access_level,
        compartmentIdInSubtree: _var.compartment_compartment_id_in_subtree,
        name: _var.compartment_name,
        state: _var.compartment_state,
    });
    
    variables:
      testCompartments:
        fn::invoke:
          Function: oci:Identity:getCompartments
          Arguments:
            compartmentId: ${var.compartment_id}
            accessLevel: ${var.compartment_access_level}
            compartmentIdInSubtree: ${var.compartment_compartment_id_in_subtree}
            name: ${var.compartment_name}
            state: ${var.compartment_state}
    

    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[_identity.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[_identity.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)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: oci:Identity/getCompartments:getCompartments
      arguments:
        # arguments dictionary

    The 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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    CompartmentIdInSubtree bool

    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<GetCompartmentsFilter>
    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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    CompartmentIdInSubtree bool

    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 []GetCompartmentsFilter
    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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    compartmentIdInSubtree Boolean

    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<GetCompartmentsFilter>
    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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    compartmentIdInSubtree boolean

    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 GetCompartmentsFilter[]
    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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    compartment_id_in_subtree bool

    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 GetCompartmentsFilter]
    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 ANY and ACCESSIBLE. Default is ANY. Setting this to ACCESSIBLE returns 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 ANY permissions are not checked.

    compartmentIdInSubtree Boolean

    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<GetCompartmentsCompartment>

    The list of compartments.

    Id string

    The provider-assigned unique ID for this managed resource.

    AccessLevel string
    CompartmentIdInSubtree bool
    Filters List<GetCompartmentsFilter>
    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 []GetCompartmentsCompartment

    The list of compartments.

    Id string

    The provider-assigned unique ID for this managed resource.

    AccessLevel string
    CompartmentIdInSubtree bool
    Filters []GetCompartmentsFilter
    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<GetCompartmentsCompartment>

    The list of compartments.

    id String

    The provider-assigned unique ID for this managed resource.

    accessLevel String
    compartmentIdInSubtree Boolean
    filters List<GetCompartmentsFilter>
    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 GetCompartmentsCompartment[]

    The list of compartments.

    id string

    The provider-assigned unique ID for this managed resource.

    accessLevel string
    compartmentIdInSubtree boolean
    filters GetCompartmentsFilter[]
    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 GetCompartmentsCompartment]

    The list of compartments.

    id str

    The provider-assigned unique ID for this managed resource.

    access_level str
    compartment_id_in_subtree bool
    filters GetCompartmentsFilter]
    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
    compartmentIdInSubtree Boolean
    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).

    DefinedTags Dictionary<string, object>

    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
    FreeformTags Dictionary<string, object>

    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).

    DefinedTags map[string]interface{}

    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
    FreeformTags map[string]interface{}

    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).

    definedTags Map<String,Object>

    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
    freeformTags Map<String,Object>

    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).

    definedTags {[key: string]: any}

    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
    freeformTags {[key: string]: any}

    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).

    defined_tags Mapping[str, Any]

    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
    freeform_tags Mapping[str, Any]

    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).

    definedTags Map<Any>

    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
    freeformTags Map<Any>

    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

    Name string

    A filter to only return resources that match the given name exactly.

    Values List<string>
    Regex bool
    Name string

    A filter to only return resources that match the given name exactly.

    Values []string
    Regex bool
    name String

    A filter to only return resources that match the given name exactly.

    values List<String>
    regex Boolean
    name string

    A filter to only return resources that match the given name exactly.

    values string[]
    regex boolean
    name str

    A filter to only return resources that match the given name exactly.

    values Sequence[str]
    regex bool
    name String

    A filter to only return resources that match the given name exactly.

    values List<String>
    regex Boolean

    Package Details

    Repository
    oci pulumi/pulumi-oci
    License
    Apache-2.0
    Notes

    This Pulumi package is based on the oci Terraform Provider.

    oci logo
    Oracle Cloud Infrastructure v0.20.1 published on Tuesday, Jun 6, 2023 by Pulumi