1. Packages
  2. Juju Provider
  3. API Docs
  4. getSecret
juju 0.19.0 published on Wednesday, Apr 30, 2025 by juju

juju.getSecret

Explore with Pulumi AI

juju logo
juju 0.19.0 published on Wednesday, Apr 30, 2025 by juju

    A data source representing a Juju Secret.

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as juju from "@pulumi/juju";
    
    const myModel = juju.getModel({
        name: "default",
    });
    const mySecretDataSource = myModel.then(myModel => juju.getSecret({
        name: "my_secret",
        model: myModel.name,
    }));
    const ubuntu = new juju.Application("ubuntu", {
        model: myModel.then(myModel => myModel.name),
        charms: [{
            name: "ubuntu",
        }],
        config: {
            secret: mySecretDataSource.then(mySecretDataSource => mySecretDataSource.secretId),
        },
    });
    const mySecretAccess = new juju.AccessSecret("mySecretAccess", {
        model: myModel.then(myModel => myModel.name),
        applications: [ubuntu.name],
        secretId: mySecretDataSource.then(mySecretDataSource => mySecretDataSource.secretId),
    });
    
    import pulumi
    import pulumi_juju as juju
    
    my_model = juju.get_model(name="default")
    my_secret_data_source = juju.get_secret(name="my_secret",
        model=my_model.name)
    ubuntu = juju.Application("ubuntu",
        model=my_model.name,
        charms=[{
            "name": "ubuntu",
        }],
        config={
            "secret": my_secret_data_source.secret_id,
        })
    my_secret_access = juju.AccessSecret("mySecretAccess",
        model=my_model.name,
        applications=[ubuntu.name],
        secret_id=my_secret_data_source.secret_id)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-terraform-provider/sdks/go/juju/juju"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		myModel, err := juju.LookupModel(ctx, &juju.LookupModelArgs{
    			Name: "default",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		mySecretDataSource, err := juju.LookupSecret(ctx, &juju.LookupSecretArgs{
    			Name:  "my_secret",
    			Model: myModel.Name,
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ubuntu, err := juju.NewApplication(ctx, "ubuntu", &juju.ApplicationArgs{
    			Model: pulumi.String(myModel.Name),
    			Charms: juju.ApplicationCharmArray{
    				&juju.ApplicationCharmArgs{
    					Name: pulumi.String("ubuntu"),
    				},
    			},
    			Config: pulumi.StringMap{
    				"secret": pulumi.String(mySecretDataSource.SecretId),
    			},
    		})
    		if err != nil {
    			return err
    		}
    		_, err = juju.NewAccessSecret(ctx, "mySecretAccess", &juju.AccessSecretArgs{
    			Model: pulumi.String(myModel.Name),
    			Applications: pulumi.StringArray{
    				ubuntu.Name,
    			},
    			SecretId: pulumi.String(mySecretDataSource.SecretId),
    		})
    		if err != nil {
    			return err
    		}
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Juju = Pulumi.Juju;
    
    return await Deployment.RunAsync(() => 
    {
        var myModel = Juju.GetModel.Invoke(new()
        {
            Name = "default",
        });
    
        var mySecretDataSource = Juju.GetSecret.Invoke(new()
        {
            Name = "my_secret",
            Model = myModel.Apply(getModelResult => getModelResult.Name),
        });
    
        var ubuntu = new Juju.Application("ubuntu", new()
        {
            Model = myModel.Apply(getModelResult => getModelResult.Name),
            Charms = new[]
            {
                new Juju.Inputs.ApplicationCharmArgs
                {
                    Name = "ubuntu",
                },
            },
            Config = 
            {
                { "secret", mySecretDataSource.Apply(getSecretResult => getSecretResult.SecretId) },
            },
        });
    
        var mySecretAccess = new Juju.AccessSecret("mySecretAccess", new()
        {
            Model = myModel.Apply(getModelResult => getModelResult.Name),
            Applications = new[]
            {
                ubuntu.Name,
            },
            SecretId = mySecretDataSource.Apply(getSecretResult => getSecretResult.SecretId),
        });
    
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.juju.JujuFunctions;
    import com.pulumi.juju.inputs.GetModelArgs;
    import com.pulumi.juju.inputs.GetSecretArgs;
    import com.pulumi.juju.Application;
    import com.pulumi.juju.ApplicationArgs;
    import com.pulumi.juju.inputs.ApplicationCharmArgs;
    import com.pulumi.juju.AccessSecret;
    import com.pulumi.juju.AccessSecretArgs;
    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 myModel = JujuFunctions.getModel(GetModelArgs.builder()
                .name("default")
                .build());
    
            final var mySecretDataSource = JujuFunctions.getSecret(GetSecretArgs.builder()
                .name("my_secret")
                .model(myModel.applyValue(getModelResult -> getModelResult.name()))
                .build());
    
            var ubuntu = new Application("ubuntu", ApplicationArgs.builder()
                .model(myModel.applyValue(getModelResult -> getModelResult.name()))
                .charms(ApplicationCharmArgs.builder()
                    .name("ubuntu")
                    .build())
                .config(Map.of("secret", mySecretDataSource.applyValue(getSecretResult -> getSecretResult.secretId())))
                .build());
    
            var mySecretAccess = new AccessSecret("mySecretAccess", AccessSecretArgs.builder()
                .model(myModel.applyValue(getModelResult -> getModelResult.name()))
                .applications(ubuntu.name())
                .secretId(mySecretDataSource.applyValue(getSecretResult -> getSecretResult.secretId()))
                .build());
    
        }
    }
    
    resources:
      ubuntu:
        type: juju:Application
        properties:
          model: ${myModel.name}
          charms:
            - name: ubuntu
          config:
            secret: ${mySecretDataSource.secretId}
      mySecretAccess:
        type: juju:AccessSecret
        properties:
          model: ${myModel.name}
          applications:
            - ${ubuntu.name}
          secretId: ${mySecretDataSource.secretId}
    variables:
      myModel:
        fn::invoke:
          function: juju:getModel
          arguments:
            name: default
      mySecretDataSource:
        fn::invoke:
          function: juju:getSecret
          arguments:
            name: my_secret
            model: ${myModel.name}
    

    Using getSecret

    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 getSecret(args: GetSecretArgs, opts?: InvokeOptions): Promise<GetSecretResult>
    function getSecretOutput(args: GetSecretOutputArgs, opts?: InvokeOptions): Output<GetSecretResult>
    def get_secret(model: Optional[str] = None,
                   name: Optional[str] = None,
                   opts: Optional[InvokeOptions] = None) -> GetSecretResult
    def get_secret_output(model: Optional[pulumi.Input[str]] = None,
                   name: Optional[pulumi.Input[str]] = None,
                   opts: Optional[InvokeOptions] = None) -> Output[GetSecretResult]
    func LookupSecret(ctx *Context, args *LookupSecretArgs, opts ...InvokeOption) (*LookupSecretResult, error)
    func LookupSecretOutput(ctx *Context, args *LookupSecretOutputArgs, opts ...InvokeOption) LookupSecretResultOutput

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

    public static class GetSecret 
    {
        public static Task<GetSecretResult> InvokeAsync(GetSecretArgs args, InvokeOptions? opts = null)
        public static Output<GetSecretResult> Invoke(GetSecretInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetSecretResult> getSecret(GetSecretArgs args, InvokeOptions options)
    public static Output<GetSecretResult> getSecret(GetSecretArgs args, InvokeOptions options)
    
    fn::invoke:
      function: juju:index/getSecret:getSecret
      arguments:
        # arguments dictionary

    The following arguments are supported:

    Model string
    The name of the model containing the secret.
    Name string
    The name of the secret.
    Model string
    The name of the model containing the secret.
    Name string
    The name of the secret.
    model String
    The name of the model containing the secret.
    name String
    The name of the secret.
    model string
    The name of the model containing the secret.
    name string
    The name of the secret.
    model str
    The name of the model containing the secret.
    name str
    The name of the secret.
    model String
    The name of the model containing the secret.
    name String
    The name of the secret.

    getSecret Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    Model string
    The name of the model containing the secret.
    Name string
    The name of the secret.
    SecretId string
    The ID of the secret.
    Id string
    The provider-assigned unique ID for this managed resource.
    Model string
    The name of the model containing the secret.
    Name string
    The name of the secret.
    SecretId string
    The ID of the secret.
    id String
    The provider-assigned unique ID for this managed resource.
    model String
    The name of the model containing the secret.
    name String
    The name of the secret.
    secretId String
    The ID of the secret.
    id string
    The provider-assigned unique ID for this managed resource.
    model string
    The name of the model containing the secret.
    name string
    The name of the secret.
    secretId string
    The ID of the secret.
    id str
    The provider-assigned unique ID for this managed resource.
    model str
    The name of the model containing the secret.
    name str
    The name of the secret.
    secret_id str
    The ID of the secret.
    id String
    The provider-assigned unique ID for this managed resource.
    model String
    The name of the model containing the secret.
    name String
    The name of the secret.
    secretId String
    The ID of the secret.

    Package Details

    Repository
    juju juju/terraform-provider-juju
    License
    Notes
    This Pulumi package is based on the juju Terraform Provider.
    juju logo
    juju 0.19.0 published on Wednesday, Apr 30, 2025 by juju