Adding container environment variables
When you add environment variables, a new container revision is created. You cannot add environment variables to an existing revision.
- In the management console
, select the folder with your container. - Select Serverless Containers.
- Select the container whose version you want to add an environment variable for.
- Go to the Editor tab.
- In the window that opens, under Image settings, specify the environment variable and click Add. You can add multiple environment variables.
- Click Create revision. A new container revision with the specified environment variables will be created.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. 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 inkey=value
format. You can specify multiple pairs separated by commas.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
To add environment variables:
-
Open the Terraform configuration file and add a list with environment variables named
environment
to theimage
section for theyandex_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 inkey="value"
format. You can specify more than one pair.For more information about the
yandex_serverless_container
resource parameters in Terraform, see the relevant provider documentation . -
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.
You can check the new environment variables using the management console
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.