1. Answers
  2. How to select resources for updating in Pulumi?

How do I selectively update resources in Pulumi?

To update specific resources in Pulumi, you can use the --target flag when running the pulumi up command. This flag allows you to specify which resources to update during an operation, effectively allowing you to narrow down your focus.

Here’s an example scenario where we have a basic AWS setup with an S3 bucket and an EC2 instance. We will include both resources in the definition, but we will focus on how to selectively update the EC2 instance without affecting the S3 bucket.

This example program:

  1. Creates an AWS S3 bucket.
  2. Creates an AWS EC2 instance.

Here is the Pulumi program in Terraform syntax:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

// Create an S3 bucket
const myBucket = new aws.s3.BucketV2("my_bucket", {bucket: "my-pulumi-bucket-12345"});
// Create an EC2 instance
const myInstance = new aws.ec2.Instance("my_instance", {
    ami: "ami-0c55b159cbfafe1f0",
    instanceType: aws.ec2.InstanceType.T2_Micro,
    tags: {
        Name: "MyPulumiInstance",
    },
});
export const bucketId = myBucket.id;
export const instanceId = myInstance.id;

In this example:

  • We define an AWS provider specifying the us-west-2 region.
  • We create an S3 bucket named my-pulumi-bucket-12345.
  • We create an EC2 instance using a specific AMI and instance type t2.micro.
  • Outputs are defined at the end to expose the IDs of the bucket and instance created.

After deploying the program, you can specifically target updates to the EC2 instance by using the appropriate command like pulumi up --target urn:pulumi:stack::project::aws:ec2/instance:my_instance.

In summary, this program sets up both an S3 bucket and an EC2 instance and shows how you can define resources. When updating resources selectively, you would utilize the targeting features available during deployment.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up