Skip to content

Get functions ​

You can use the static get method, which is available on all resource classes, to look up an existing resource that is not managed by Pulumi.

The get function is different from the import CLI command: pulumi import is used to bring an existing resource under management by Pulumi. get is used to allow the attributes of an existing resource to be used within a Pulumi program. A resource read with the get function will never be updated or deleted by Pulumi during an update.

Two values are passed to the get function:

  1. The logical name Pulumi will use to refer to the resource.
  2. The physical ID that the resource has in the target cloud.

You can use the get function to consume properties from a resource that was provisioned elsewhere. For example, this program reads an existing EC2 Security Group whose ID is sg-0dfd33cdac25b1ec9 and uses the result as input to create an EC2 Instance that Pulumi will manage:

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

let group = aws.ec2.SecurityGroup.get("group", "sg-0dfd33cdac25b1ec9");

let server = new aws.ec2.Instance("web-server", {
    ami: "ami-6869aa05",
    instanceType: "t2.micro",
    securityGroups: [ group.name ], // reference the security group resource above
});

In the example above, Pulumi will never attempt to modify the security group. It queries the attributes of the security group from your cloud account and then uses its name as an input for the new EC2 Instance.

WARNING

If the resource that you are trying to look up does not exist, Pulumi will throw an exception or error (depending on the language being used) and the program will terminate.

Content from the official Pulumi documentation (github.com/pulumi/docs).