1. Packages
  2. Cloudflare Provider
  3. API Docs
  4. getUser
Cloudflare v5.39.1 published on Tuesday, Sep 24, 2024 by Pulumi

cloudflare.getUser

Explore with Pulumi AI

cloudflare logo
Cloudflare v5.39.1 published on Tuesday, Sep 24, 2024 by Pulumi

    Use this data source to retrieve information about the currently authenticated user.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as cloudflare from "@pulumi/cloudflare";
    
    const me = cloudflare.getUser({});
    const all = cloudflare.getApiTokenPermissionGroups({});
    const example = new cloudflare.ApiToken("example", {
        name: "Terraform Cloud (Terraform)",
        policies: [{
            permissionGroups: [all.then(all => all.user?.["User Details Read"])],
            resources: me.then(me => {
                [`com.cloudflare.api.user.${me.id}`]: "*",
            }),
        }],
    });
    
    import pulumi
    import pulumi_cloudflare as cloudflare
    
    me = cloudflare.get_user()
    all = cloudflare.get_api_token_permission_groups()
    example = cloudflare.ApiToken("example",
        name="Terraform Cloud (Terraform)",
        policies=[{
            "permission_groups": [all.user["User Details Read"]],
            "resources": {
                "": "*",
            },
        }])
    
    package main
    
    import (
    	"fmt"
    
    	"github.com/pulumi/pulumi-cloudflare/sdk/v5/go/cloudflare"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
    me, err := cloudflare.GetUser(ctx, nil, nil);
    if err != nil {
    return err
    }
    all, err := cloudflare.GetApiTokenPermissionGroups(ctx, nil, nil);
    if err != nil {
    return err
    }
    _, err = cloudflare.NewApiToken(ctx, "example", &cloudflare.ApiTokenArgs{
    Name: pulumi.String("Terraform Cloud (Terraform)"),
    Policies: cloudflare.ApiTokenPolicyArray{
    &cloudflare.ApiTokenPolicyArgs{
    PermissionGroups: pulumi.StringArray{
    pulumi.String(all.User.User Details Read),
    },
    Resources: pulumi.StringMap{
    fmt.Sprintf("com.cloudflare.api.user.%v", me.Id): pulumi.String("*"),
    },
    },
    },
    })
    if err != nil {
    return err
    }
    return nil
    })
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Cloudflare = Pulumi.Cloudflare;
    
    return await Deployment.RunAsync(() => 
    {
        var me = Cloudflare.GetUser.Invoke();
    
        var all = Cloudflare.GetApiTokenPermissionGroups.Invoke();
    
        var example = new Cloudflare.ApiToken("example", new()
        {
            Name = "Terraform Cloud (Terraform)",
            Policies = new[]
            {
                new Cloudflare.Inputs.ApiTokenPolicyArgs
                {
                    PermissionGroups = new[]
                    {
                        all.Apply(getApiTokenPermissionGroupsResult => getApiTokenPermissionGroupsResult.User?.User_Details_Read),
                    },
                    Resources = 
                    {
                        { $"com.cloudflare.api.user.{me.Apply(getUserResult => getUserResult.Id)}", "*" },
                    },
                },
            },
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.cloudflare.CloudflareFunctions;
    import com.pulumi.cloudflare.ApiToken;
    import com.pulumi.cloudflare.ApiTokenArgs;
    import com.pulumi.cloudflare.inputs.ApiTokenPolicyArgs;
    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 me = CloudflareFunctions.getUser();
    
            final var all = CloudflareFunctions.getApiTokenPermissionGroups();
    
            var example = new ApiToken("example", ApiTokenArgs.builder()
                .name("Terraform Cloud (Terraform)")
                .policies(ApiTokenPolicyArgs.builder()
                    .permissionGroups(all.applyValue(getApiTokenPermissionGroupsResult -> getApiTokenPermissionGroupsResult.user().User Details Read()))
                    .resources(Map.of(String.format("com.cloudflare.api.user.%s", me.applyValue(getUserResult -> getUserResult.id())), "*"))
                    .build())
                .build());
    
        }
    }
    
    resources:
      example:
        type: cloudflare:ApiToken
        properties:
          name: Terraform Cloud (Terraform)
          policies:
            - permissionGroups:
                - ${all.user"User Details Read"[%!s(MISSING)]}
              resources:
                com.cloudflare.api.user.${me.id}: '*'
    variables:
      me:
        fn::invoke:
          Function: cloudflare:getUser
          Arguments: {}
      all:
        fn::invoke:
          Function: cloudflare:getApiTokenPermissionGroups
          Arguments: {}
    

    Using getUser

    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 getUser(opts?: InvokeOptions): Promise<GetUserResult>
    function getUserOutput(opts?: InvokeOptions): Output<GetUserResult>
    def get_user(opts: Optional[InvokeOptions] = None) -> GetUserResult
    def get_user_output(opts: Optional[InvokeOptions] = None) -> Output[GetUserResult]
    func GetUser(ctx *Context, opts ...InvokeOption) (*GetUserResult, error)
    func GetUserOutput(ctx *Context, opts ...InvokeOption) GetUserResultOutput

    > Note: This function is named GetUser in the Go SDK.

    public static class GetUser 
    {
        public static Task<GetUserResult> InvokeAsync(InvokeOptions? opts = null)
        public static Output<GetUserResult> Invoke(InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetUserResult> getUser(InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: cloudflare:index/getUser:getUser
      arguments:
        # arguments dictionary

    getUser Result

    The following output properties are available:

    Email string
    The user's email address.
    Id string
    The user's unique identifier.
    Username string
    The user's username.
    Email string
    The user's email address.
    Id string
    The user's unique identifier.
    Username string
    The user's username.
    email String
    The user's email address.
    id String
    The user's unique identifier.
    username String
    The user's username.
    email string
    The user's email address.
    id string
    The user's unique identifier.
    username string
    The user's username.
    email str
    The user's email address.
    id str
    The user's unique identifier.
    username str
    The user's username.
    email String
    The user's email address.
    id String
    The user's unique identifier.
    username String
    The user's username.

    Package Details

    Repository
    Cloudflare pulumi/pulumi-cloudflare
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the cloudflare Terraform Provider.
    cloudflare logo
    Cloudflare v5.39.1 published on Tuesday, Sep 24, 2024 by Pulumi