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/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[_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:
- Compartment
Id string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Access
Level string Valid values are
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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 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<Get
Compartments 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 string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- Access
Level string Valid values are
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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 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
[]Get
Compartments 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 String - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- access
Level String Valid values are
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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 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<Get
Compartments 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 string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- access
Level string Valid values are
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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 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
Get
Compartments 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
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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_ 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[identity.
Get Compartments 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.
- compartment
Id String - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- access
Level String Valid values are
ANY
andACCESSIBLE
. Default isANY
. Setting this toACCESSIBLE
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 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:
- Compartment
Id string - The OCID of the parent compartment containing the compartment.
- Compartments
List<Get
Compartments Compartment> - The list of compartments.
- Id string
- The provider-assigned unique ID for this managed resource.
- Access
Level string - Compartment
Id boolIn Subtree - Filters
List<Get
Compartments 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 string - The OCID of the parent compartment containing the compartment.
- Compartments
[]Get
Compartments Compartment - The list of compartments.
- Id string
- The provider-assigned unique ID for this managed resource.
- Access
Level string - Compartment
Id boolIn Subtree - Filters
[]Get
Compartments 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 String - The OCID of the parent compartment containing the compartment.
- compartments
List<Get
Compartments Compartment> - The list of compartments.
- id String
- The provider-assigned unique ID for this managed resource.
- access
Level String - compartment
Id BooleanIn Subtree - filters
List<Get
Compartments 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 string - The OCID of the parent compartment containing the compartment.
- compartments
Get
Compartments Compartment[] - The list of compartments.
- id string
- The provider-assigned unique ID for this managed resource.
- access
Level string - compartment
Id booleanIn Subtree - filters
Get
Compartments 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[identity.
Get Compartments 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[identity.
Get Compartments 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.
- compartment
Id 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.
- access
Level String - compartment
Id 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
- Compartment
Id string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- 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.
- Enable
Delete bool - 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.
- Inactive
State string - 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 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.
- Time
Created string - Date and time the compartment was created, in the format defined by RFC3339. Example:
2016-08-25T21:10:29.600Z
- Compartment
Id string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- 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.
- Enable
Delete bool - 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.
- Inactive
State string - 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 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.
- Time
Created string - Date and time the compartment was created, in the format defined by RFC3339. Example:
2016-08-25T21:10:29.600Z
- compartment
Id String - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- 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.
- enable
Delete Boolean - 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.
- inactive
State String - The detailed status of INACTIVE lifecycleState.
- is
Accessible 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.
- time
Created String - Date and time the compartment was created, in the format defined by RFC3339. Example:
2016-08-25T21:10:29.600Z
- compartment
Id string - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- {[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.
- enable
Delete boolean - {[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.
- inactive
State string - The detailed status of INACTIVE lifecycleState.
- is
Accessible 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.
- time
Created 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, 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 - 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
- compartment
Id String - The OCID of the compartment (remember that the tenancy is simply the root compartment).
- 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.
- enable
Delete Boolean - 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.
- inactive
State String - The detailed status of INACTIVE lifecycleState.
- is
Accessible 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.
- time
Created 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
oci
Terraform Provider.