1. Docs
  2. Pulumi IaC
  3. Concepts
  4. Inputs & outputs

Inputs & outputs

    Inputs

    All resources in Pulumi accept values that describe the way the resource behaves. We call these values inputs.

    const myId = new random.RandomId("mine", {
        byteLength: 8, // byteLength is an input
    });
    
    const myId = new random.RandomId("mine", {
        byteLength: 8, // byteLength is an input
    });
    
    my_id = random.RandomId("mine",
        byte_length=8 # byte_length is an input
    )
    
    
    myId, err := random.NewRandomId(ctx, "mine", &random.RandomIdArgs{
    	ByteLength: pulumi.Int(8), // ByteLength is an input
    })
    if err != nil {
    	return err
    }
    
    var myId = new Random.RandomId("mine", new()
    {
        ByteLength = 8, // ByteLength is an input
    });
    
    var myId = new RandomId("mine", RandomIdArgs.builder()
        .byteLength(8) // byteLength is an input
        .build());
    
    resources:
      myId:
        type: random:randomId
        properties:
          byteLength: 8 # byteLength is an input
    

    Inputs are generally representations of the parameters to the underlying API call of any resource that Pulumi is managing. The simplest way to create a resource with its required inputs is to use a plain value.

    const key = new tls.PrivateKey("my-private-key", {
        algorithm: "ECDSA", // ECDSA is a plain value
    });
    
    const key = new tls.PrivateKey("my-private-key", {
        algorithm: "ECDSA", // ECDSA is a plain value
    });
    
    key = tls.PrivateKey("my-private-key",
      algorithm="ECDSA", # ECDSA is a plain value
    )
    
    
    key, err := tls.NewPrivateKey(ctx, "my-private-key", &tls.PrivateKeyArgs{
    	Algorithm:  pulumi.String("ECDSA"), // ECDSA is a plain value
    })
    if err != nil {
    	return err
    }
    
    var key = new PrivateKey("my-private-key", new PrivateKeyArgs{
        Algorithm = "ECDSA", // ECDSA is a plain value
    });
    
    var key = new PrivateKey("my-private-key", PrivateKeyArgs.builder()
        .algorithm("ECDSA") // ECDSA is a plain value
        .build()
    )
    
    resources:
      key:
        type: tls:PrivateKey
        properties:
          algorithm: "ECDSA" # ECDSA is a plain value
    
    Plain value in this document is used to describe a standard string, boolean, integer or other typed value or data structure in your language of choice. Plain value is a way of differentiating these language specific values from Pulumi’s asynchronous values.

    However, in most Pulumi programs, the inputs to a resource will reference values from another resource:

    let password = new random.RandomPassword("password", {
        length: 16,
        special: true,
        overrideSpecial: "!#$%&*()-_=+[]{}<>:?",
    });
    let example = new aws.rds.Instance("example", {
        instanceClass: "db.t3.micro",
        allocatedStorage: 64,
        engine: "mysql",
        username: "someone",
        password: password.result, // We pass the output from password as an input
    });
    
    const password = new random.RandomPassword("password", {
        length: 16,
        special: true,
        overrideSpecial: "!#$%&*()-_=+[]{}<>:?",
    });
    const example = new aws.rds.Instance("example", {
        instanceClass: "db.t3.micro",
        allocatedStorage: 64,
        engine: "mysql",
        username: "someone",
        password: password.result, // We pass the output from password as an input
    });
    
    password = random.RandomPassword(
        "password",
        length=16,
        special=True,
        override_special="!#$%&*()-_=+[]{}<>:?"
    )
    example = aws.rds.Instance(
        "example",
        instance_class="db.t3.micro",
        allocated_storage=64,
        engine="mysql",
        username="someone",
        password=password.result, # We pass the output from password as an input
    )
    
    password, err := random.NewRandomPassword(ctx, "password", &random.RandomPasswordArgs{
    	Length:          pulumi.Int(16),
    	Special:         pulumi.Bool(true),
    	OverrideSpecial: pulumi.String("!#$%&*()-_=+[]{}<>:?"),
    })
    if err != nil {
    	return err
    }
    _, err = rds.NewInstance(ctx, "example", &rds.InstanceArgs{
    	InstanceClass:    pulumi.String("db.t3.micro"),
    	AllocatedStorage: pulumi.Int(64),
    	Engine:           pulumi.String("mysql"),
    	Username:         pulumi.String("someone"),
    	Password:         password.Result, // We pass the output from password as an input
    })
    if err != nil {
    	return err
    }
    
    var password = new Random.RandomPassword("password", new()
    {
        Length = 16,
        Special = true,
        OverrideSpecial = "!#$%&*()-_=+[]{}<>:?",
    });
    
    var example = new Aws.Rds.Instance("example", new()
    {
        InstanceClass = "db.t3.micro",
        AllocatedStorage = 64,
        Engine = "mysql",
        Username = "someone",
        Password = password.Result, // We pass the output from password as an input
    });
    
    var password = new RandomPassword("password", RandomPasswordArgs.builder()
        .length(16)
        .special(true)
        .overrideSpecial("!#$%&*()-_=+[]{}<>:?")
        .build());
    
    var example = new Instance("example", InstanceArgs.builder()
        .instanceClass("db.t3.micro")
        .allocatedStorage(64)
        .engine("mysql")
        .username("someone")
        .password(password.result()) // We pass the output from password as an input
        .build());
    

    In this case, Pulumi is taking the output from one resource and using it as the input to another resource.

    Outputs

    All resources created by Pulumi will have properties which are returned from the cloud provider API. These values are called outputs.

    Outputs are a unique and complex type in Pulumi which behave very much like promises. Simply put, outputs are a way of representing values that are not initially known but will become available once the infrastructure resource has completed provisioning, and this happens asynchronously. This is because the provisioning of resources is an asynchronous operation. It takes time for a cloud provider to complete the provisioning process, and Pulumi optimizes the process by executing operations in parallel rather than sequentially.

    Because outputs are asynchronous, their actual plain values are not immediately available. Note that outputs themselves are not plain/primitive types, and they cannot be converted into plain types. For example, you cannot turn an a variable of type Output into a regular String or an Integer. An output can only be transformed into another output.

    If you need to access and interact with an output’s plain value, you can do so using one of the following options:

    • Apply: used for accessing single output values
    • All: used for accessing multiple output values

    Tracking dependencies

    Outputs are also how Pulumi tracks dependencies between resources. When an output from one resource has been returned from the cloud provider API, Pulumi can link the two resources together and pass it as the input to another resource.

    Pulumi automatically captures dependencies when you pass an output from one resource as an input to another resource. Capturing these dependencies ensures that the physical infrastructure resources are not created or updated until all their dependencies are available and up-to-date.

      PulumiUP 2024. Watch On Demand.