---
title: Get functions
url: /docs/iac/concepts/functions/get-functions/
---
<!-- chooser: language -->

<!-- option: typescript -->
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.

<!-- /option -->

<!-- option: go -->
You can use the `Get` function (e.g., `ec2.GetSecurityGroup`), which is available as a package-level function for all resource types, to look up an existing resource that is not managed by Pulumi.

<!-- /option -->

<!-- option: yaml -->
You can use the `get` stanza, which is available on all resource types, to look up an existing resource that is not managed by Pulumi.

<!-- /option -->

<!-- /chooser -->

The `get` function is different from the [`import` CLI command](/docs/iac/cli/commands/pulumi_import): `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.
1. 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:

<!-- chooser: language -->

<!-- option: typescript -->
```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
});

```

<!-- /option -->

<!-- option: python -->
```python
import pulumi_aws as aws

group = aws.ec2.SecurityGroup.get('group', 'sg-0dfd33cdac25b1ec9')

server = aws.ec2.Instance('web-server',
    ami='ami-6869aa05',
    instance_type='t2.micro',
    security_groups=[group.name]) # reference the security group resource above

```

<!-- /option -->

<!-- option: go -->
```go
import (
    "github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
    "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
        group, err := ec2.GetSecurityGroup(ctx, "group", pulumi.ID("sg-0dfd33cdac25b1ec9"), nil)
        if err != nil {
            return err
        }
        server, err := ec2.NewInstance(ctx, "web-server", &ec2.InstanceArgs{
            Ami:            pulumi.String("ami-6869aa05"),
            InstanceType:   pulumi.String("t2.micro"),
            SecurityGroups: pulumi.StringArray{group.Name},
        })
        if err != nil {
            return err
        }
        return nil
    })
}

```

<!-- /option -->

<!-- option: csharp -->
```csharp
using Pulumi;
using Pulumi.Aws.Ec2;
using Pulumi.Aws.Ec2.Inputs;

class MyStack : Stack
{
    public MyStack()
    {
        var group = SecurityGroup.Get("group", "sg-0dfd33cdac25b1ec9");

        var server = new Instance("web-server", new InstanceArgs {
            Ami = "ami-6869aa05",
            InstanceType = "t2.micro",
            SecurityGroups = { group.Name }
        });
    }
}

```

<!-- /option -->

<!-- option: java -->
```java
public static void stack(Context ctx) {
    var group = SecurityGroup.get("group", Output.of("sg-0dfd33cdac25b1ec9"), null, null);

    var server = new Instance("web-server", InstanceArgs.builder()
        .ami("ami-6869aa05")
        .instanceType("t2.micro")
        .securityGroups(
            group.name().applyValue(v -> List.of(v)))
        .build());
}

```

<!-- /option -->

<!-- option: yaml -->
```yaml
resources:
  group:
    type: aws:ec2:SecurityGroup
    get:
      id: sg-0dfd33cdac25b1ec9
  web-server:
    type: aws:ec2:Instance
    properties:
      ami: ami-6869aa05
      instanceType: t2.micro
      securityGroups:
        - ${group.name}

```

<!-- /option -->

<!-- /chooser -->

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.


