1. Packages
  2. Coder Provider
  3. API Docs
  4. Env
coder 2.4.0-pre1 published on Tuesday, Apr 15, 2025 by coder

coder.Env

Explore with Pulumi AI

Use this resource to set an environment variable in a workspace. Note that this resource cannot be used to overwrite existing environment variables set on the coder.Agent resource.

Example Usage

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

const me = coder.getWorkspace({});
const dev = new coder.Agent("dev", {
    os: "linux",
    arch: "amd64",
    dir: "/workspace",
});
const welcomeMessage = new coder.Env("welcomeMessage", {
    agentId: dev.agentId,
    value: "Welcome to your Coder workspace!",
});
const internalApiUrl = new coder.Env("internalApiUrl", {
    agentId: dev.agentId,
    value: "https://api.internal.company.com/v1",
});
Copy
import pulumi
import pulumi_coder as coder

me = coder.get_workspace()
dev = coder.Agent("dev",
    os="linux",
    arch="amd64",
    dir="/workspace")
welcome_message = coder.Env("welcomeMessage",
    agent_id=dev.agent_id,
    value="Welcome to your Coder workspace!")
internal_api_url = coder.Env("internalApiUrl",
    agent_id=dev.agent_id,
    value="https://api.internal.company.com/v1")
Copy
package main

import (
	"github.com/pulumi/pulumi-terraform-provider/sdks/go/coder/v2/coder"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := coder.GetWorkspace(ctx, map[string]interface{}{}, nil)
		if err != nil {
			return err
		}
		dev, err := coder.NewAgent(ctx, "dev", &coder.AgentArgs{
			Os:   pulumi.String("linux"),
			Arch: pulumi.String("amd64"),
			Dir:  pulumi.String("/workspace"),
		})
		if err != nil {
			return err
		}
		_, err = coder.NewEnv(ctx, "welcomeMessage", &coder.EnvArgs{
			AgentId: dev.AgentId,
			Value:   pulumi.String("Welcome to your Coder workspace!"),
		})
		if err != nil {
			return err
		}
		_, err = coder.NewEnv(ctx, "internalApiUrl", &coder.EnvArgs{
			AgentId: dev.AgentId,
			Value:   pulumi.String("https://api.internal.company.com/v1"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Coder = Pulumi.Coder;

return await Deployment.RunAsync(() => 
{
    var me = Coder.GetWorkspace.Invoke();

    var dev = new Coder.Agent("dev", new()
    {
        Os = "linux",
        Arch = "amd64",
        Dir = "/workspace",
    });

    var welcomeMessage = new Coder.Env("welcomeMessage", new()
    {
        AgentId = dev.AgentId,
        Value = "Welcome to your Coder workspace!",
    });

    var internalApiUrl = new Coder.Env("internalApiUrl", new()
    {
        AgentId = dev.AgentId,
        Value = "https://api.internal.company.com/v1",
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.coder.CoderFunctions;
import com.pulumi.coder.Agent;
import com.pulumi.coder.AgentArgs;
import com.pulumi.coder.Env;
import com.pulumi.coder.EnvArgs;
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 me = CoderFunctions.getWorkspace();

        var dev = new Agent("dev", AgentArgs.builder()
            .os("linux")
            .arch("amd64")
            .dir("/workspace")
            .build());

        var welcomeMessage = new Env("welcomeMessage", EnvArgs.builder()
            .agentId(dev.agentId())
            .value("Welcome to your Coder workspace!")
            .build());

        var internalApiUrl = new Env("internalApiUrl", EnvArgs.builder()
            .agentId(dev.agentId())
            .value("https://api.internal.company.com/v1")
            .build());

    }
}
Copy
resources:
  dev:
    type: coder:Agent
    properties:
      os: linux
      arch: amd64
      dir: /workspace
  welcomeMessage:
    type: coder:Env
    properties:
      agentId: ${dev.agentId}
      value: Welcome to your Coder workspace!
  internalApiUrl:
    type: coder:Env
    properties:
      agentId: ${dev.agentId}
      value: https://api.internal.company.com/v1
variables:
  me:
    fn::invoke:
      function: coder:getWorkspace
      arguments: {}
Copy

Create Env Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new Env(name: string, args: EnvArgs, opts?: CustomResourceOptions);
@overload
def Env(resource_name: str,
        args: EnvArgs,
        opts: Optional[ResourceOptions] = None)

@overload
def Env(resource_name: str,
        opts: Optional[ResourceOptions] = None,
        agent_id: Optional[str] = None,
        env_id: Optional[str] = None,
        name: Optional[str] = None,
        value: Optional[str] = None)
func NewEnv(ctx *Context, name string, args EnvArgs, opts ...ResourceOption) (*Env, error)
public Env(string name, EnvArgs args, CustomResourceOptions? opts = null)
public Env(String name, EnvArgs args)
public Env(String name, EnvArgs args, CustomResourceOptions options)
type: coder:Env
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. EnvArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. EnvArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. EnvArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. EnvArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. EnvArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var envResource = new Coder.Env("envResource", new()
{
    AgentId = "string",
    EnvId = "string",
    Name = "string",
    Value = "string",
});
Copy
example, err := coder.NewEnv(ctx, "envResource", &coder.EnvArgs{
AgentId: pulumi.String("string"),
EnvId: pulumi.String("string"),
Name: pulumi.String("string"),
Value: pulumi.String("string"),
})
Copy
var envResource = new Env("envResource", EnvArgs.builder()
    .agentId("string")
    .envId("string")
    .name("string")
    .value("string")
    .build());
Copy
env_resource = coder.Env("envResource",
    agent_id="string",
    env_id="string",
    name="string",
    value="string")
Copy
const envResource = new coder.Env("envResource", {
    agentId: "string",
    envId: "string",
    name: "string",
    value: "string",
});
Copy
type: coder:Env
properties:
    agentId: string
    envId: string
    name: string
    value: string
Copy

Env Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The Env resource accepts the following input properties:

AgentId This property is required. string
The id property of a coder.Agent resource to associate with.
EnvId string
The ID of this resource.
Name string
The name of the environment variable.
Value string
The value of the environment variable.
AgentId This property is required. string
The id property of a coder.Agent resource to associate with.
EnvId string
The ID of this resource.
Name string
The name of the environment variable.
Value string
The value of the environment variable.
agentId This property is required. String
The id property of a coder.Agent resource to associate with.
envId String
The ID of this resource.
name String
The name of the environment variable.
value String
The value of the environment variable.
agentId This property is required. string
The id property of a coder.Agent resource to associate with.
envId string
The ID of this resource.
name string
The name of the environment variable.
value string
The value of the environment variable.
agent_id This property is required. str
The id property of a coder.Agent resource to associate with.
env_id str
The ID of this resource.
name str
The name of the environment variable.
value str
The value of the environment variable.
agentId This property is required. String
The id property of a coder.Agent resource to associate with.
envId String
The ID of this resource.
name String
The name of the environment variable.
value String
The value of the environment variable.

Outputs

All input properties are implicitly available as output properties. Additionally, the Env resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing Env Resource

Get an existing Env resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: EnvState, opts?: CustomResourceOptions): Env
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        agent_id: Optional[str] = None,
        env_id: Optional[str] = None,
        name: Optional[str] = None,
        value: Optional[str] = None) -> Env
func GetEnv(ctx *Context, name string, id IDInput, state *EnvState, opts ...ResourceOption) (*Env, error)
public static Env Get(string name, Input<string> id, EnvState? state, CustomResourceOptions? opts = null)
public static Env get(String name, Output<String> id, EnvState state, CustomResourceOptions options)
resources:  _:    type: coder:Env    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
AgentId string
The id property of a coder.Agent resource to associate with.
EnvId string
The ID of this resource.
Name string
The name of the environment variable.
Value string
The value of the environment variable.
AgentId string
The id property of a coder.Agent resource to associate with.
EnvId string
The ID of this resource.
Name string
The name of the environment variable.
Value string
The value of the environment variable.
agentId String
The id property of a coder.Agent resource to associate with.
envId String
The ID of this resource.
name String
The name of the environment variable.
value String
The value of the environment variable.
agentId string
The id property of a coder.Agent resource to associate with.
envId string
The ID of this resource.
name string
The name of the environment variable.
value string
The value of the environment variable.
agent_id str
The id property of a coder.Agent resource to associate with.
env_id str
The ID of this resource.
name str
The name of the environment variable.
value str
The value of the environment variable.
agentId String
The id property of a coder.Agent resource to associate with.
envId String
The ID of this resource.
name String
The name of the environment variable.
value String
The value of the environment variable.

Package Details

Repository
coder coder/terraform-provider-coder
License
Notes
This Pulumi package is based on the coder Terraform Provider.