Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Serverless Containers
  • Comparison with other Yandex Cloud services
    • All guides
    • Getting an IAM token for a service account using a container
      • Making a revision active
      • Changing the container operation mode
      • Adding environment variables
      • Specifying a cloud network
      • Transferring Yandex Lockbox secrets
      • Viewing monitoring charts
      • Migration to the ru-central1-d availability zone
      • Deleting a container
    • Viewing operations with service resources
  • Access management
  • Pricing policy
  • Terraform reference
  • Audit Trails events
  • Release notes
  • FAQ
  1. Step-by-step guides
  2. Managing a container
  3. Adding environment variables

Adding container environment variables

Written by
Yandex Cloud
Updated at May 5, 2025

When you add environment variables, a new container revision is created. You cannot add environment variables to an existing revision.

Management console
CLI
Terraform
API
  1. In the management console, select the folder with your container.
  2. Select Serverless Containers.
  3. Select the container whose version you want to add an environment variable for.
  4. Go to the Editor tab.
  5. In the window that opens, under Image settings, specify the environment variable and click Add. You can add multiple environment variables.
  6. Click Create revision. A new container revision with the specified environment variables will be created.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

To add environment variables, run the command:

Warning

If the previous revision contained environment variables, this command overwrites them.

yc serverless container revision deploy \
  --container-name <container_name> \
  --image <Docker_image_URL> \
  --cores 1 \
  --memory 1GB \
  --service-account-id <service_account_ID> \
  --environment <environment_variables>

Where:

  • --cores: Number of cores available to the container.
  • --memory: Required memory. The default value is 128 MB.
  • --environment: Environment variables in key=value format. You can specify multiple pairs separated by commas.

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

To add environment variables:

  1. Open the Terraform configuration file and add a list with environment variables named environment to the image section for the yandex_serverless_container resource:

    ...
    resource "yandex_serverless_container" "test-container" {
      name               = "my-container"
      memory             = 256
      service_account_id = "ajecvjv1lv01********"
      image {
          url = "cr.yandex/yc/test-image:v1"
          environment = {
              <key> = "<value>"
          }
      }
    }
    ...
    

    Where environment represents environment variables in key="value" format. You can specify more than one pair.

    For more information about the yandex_serverless_container parameters in Terraform, see the relevant Terraform article.

  2. Check the configuration using this command:

    terraform validate
    

    If the configuration is correct, you will get this message:

    Success! The configuration is valid.
    
  3. Run this command:

    terraform plan
    

    The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  4. Apply the configuration changes:

    terraform apply
    
  5. Confirm the changes: type yes into the terminal and press Enter.

You can check the new environment variables using the management console or this CLI command:

yc serverless container revision get <revision_ID>

To add an environment variable, use the deployRevision REST API method for the Container resource or the ContainerService/DeployRevision gRPC API call.

See alsoSee also

  • Environment variables

Was the article helpful?

Previous
Deleting scaling settings
Next
Specifying a cloud network
Yandex project
© 2025 Yandex.Cloud LLC