How to use environment variables in Compute Engine on Google Cloud Platform? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Setting environment variable for a Compute Engine VMWhat is the difference between Google App Engine and Google Compute Engine?Google cloud compute not recognizing any resourcesGoogle Compute Engine : Export and Import Compute-Engine(VM) infoStartup Scripts on Google Compute EngineHow to have a google cloud function communicate with google compute engine instance?Google cloud compute startup script ignored with no loggingRunning a single docker container on Google Cloud PlatformGoogle Cloud KMS server installGoogle Compute Engine: Required 'compute.zones.get' permission errorHow to link Google Cloud App Engine Web app to Google Compute engine VM instance?

Table formatting with tabularx?

Vertical ranges of Column Plots in 12

One-one communication

Why are two-digit numbers in Jonathan Swift's "Gulliver's Travels" (1726) written in "German style"?

Marquee sign letters

Short story about astronauts fertilizing soil with their own bodies

What is a more techy Technical Writer job title that isn't cutesy or confusing?

3D Masyu - A Die

Is the Mordenkainen's Sword spell underpowered?

How to infer difference of population proportion between two groups when proportion is small?

Why do C and C++ allow the expression (int) + 4*5;

Meaning of 境 in その日を境に

Any stored/leased 737s that could substitute for grounded MAXs?

Is there a verb for listening stealthily?

Understanding piped commands in GNU/Linux

Does a random sequence of vectors span a Hilbert space?

Pointing to problems without suggesting solutions

Why not use the yoke to control yaw, as well as pitch and roll?

How to make an animal which can only breed for a certain number of generations?

Keep at all times, the minus sign above aligned with minus sign below

What is "Lambda" in Heston's original paper on stochastic volatility models?

Does the main washing effect of soap come from foam?

Is the time—manner—place ordering of adverbials an oversimplification?

By what mechanism was the 2017 UK General Election called?



How to use environment variables in Compute Engine on Google Cloud Platform?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Setting environment variable for a Compute Engine VMWhat is the difference between Google App Engine and Google Compute Engine?Google cloud compute not recognizing any resourcesGoogle Compute Engine : Export and Import Compute-Engine(VM) infoStartup Scripts on Google Compute EngineHow to have a google cloud function communicate with google compute engine instance?Google cloud compute startup script ignored with no loggingRunning a single docker container on Google Cloud PlatformGoogle Cloud KMS server installGoogle Compute Engine: Required 'compute.zones.get' permission errorHow to link Google Cloud App Engine Web app to Google Compute engine VM instance?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have an application running in Compute Engine on Google Cloud Platform which reads system environmental variables.



I wonder what is the way to put them in my instance so that the application will be able to read them in runtime.



Here is how I create an instance:



gcloud compute instances create $PROJECT_ID 
--image-family debian-9
--image-project debian-cloud
--machine-type g1-small
--scopes "userinfo-email,cloud-platform"
--metadata-from-file startup-script=$SCRIPT
--metadata release-url=$BUCKET_URL
--zone $ZONE
--tags http-server


I have some security credentials, e.g. API keys, passwords, etc. which I want to upload to my instance and expose them as env vars to be read by my application.



Is there any console available for that, flag or command to automate this?










share|improve this question
























  • The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

    – night-gold
    Oct 13 '18 at 11:37






  • 1





    @night-gold on other computer I do heroku config:set API_KEY=xxx.

    – Kamil Lelonek
    Oct 13 '18 at 15:07











  • Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

    – Kolban
    Oct 13 '18 at 15:09

















1















I have an application running in Compute Engine on Google Cloud Platform which reads system environmental variables.



I wonder what is the way to put them in my instance so that the application will be able to read them in runtime.



Here is how I create an instance:



gcloud compute instances create $PROJECT_ID 
--image-family debian-9
--image-project debian-cloud
--machine-type g1-small
--scopes "userinfo-email,cloud-platform"
--metadata-from-file startup-script=$SCRIPT
--metadata release-url=$BUCKET_URL
--zone $ZONE
--tags http-server


I have some security credentials, e.g. API keys, passwords, etc. which I want to upload to my instance and expose them as env vars to be read by my application.



Is there any console available for that, flag or command to automate this?










share|improve this question
























  • The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

    – night-gold
    Oct 13 '18 at 11:37






  • 1





    @night-gold on other computer I do heroku config:set API_KEY=xxx.

    – Kamil Lelonek
    Oct 13 '18 at 15:07











  • Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

    – Kolban
    Oct 13 '18 at 15:09













1












1








1








I have an application running in Compute Engine on Google Cloud Platform which reads system environmental variables.



I wonder what is the way to put them in my instance so that the application will be able to read them in runtime.



Here is how I create an instance:



gcloud compute instances create $PROJECT_ID 
--image-family debian-9
--image-project debian-cloud
--machine-type g1-small
--scopes "userinfo-email,cloud-platform"
--metadata-from-file startup-script=$SCRIPT
--metadata release-url=$BUCKET_URL
--zone $ZONE
--tags http-server


I have some security credentials, e.g. API keys, passwords, etc. which I want to upload to my instance and expose them as env vars to be read by my application.



Is there any console available for that, flag or command to automate this?










share|improve this question
















I have an application running in Compute Engine on Google Cloud Platform which reads system environmental variables.



I wonder what is the way to put them in my instance so that the application will be able to read them in runtime.



Here is how I create an instance:



gcloud compute instances create $PROJECT_ID 
--image-family debian-9
--image-project debian-cloud
--machine-type g1-small
--scopes "userinfo-email,cloud-platform"
--metadata-from-file startup-script=$SCRIPT
--metadata release-url=$BUCKET_URL
--zone $ZONE
--tags http-server


I have some security credentials, e.g. API keys, passwords, etc. which I want to upload to my instance and expose them as env vars to be read by my application.



Is there any console available for that, flag or command to automate this?







google-cloud-platform google-compute-engine






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 13 '18 at 15:06







Kamil Lelonek

















asked Oct 13 '18 at 10:40









Kamil LelonekKamil Lelonek

9,62695277




9,62695277












  • The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

    – night-gold
    Oct 13 '18 at 11:37






  • 1





    @night-gold on other computer I do heroku config:set API_KEY=xxx.

    – Kamil Lelonek
    Oct 13 '18 at 15:07











  • Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

    – Kolban
    Oct 13 '18 at 15:09

















  • The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

    – night-gold
    Oct 13 '18 at 11:37






  • 1





    @night-gold on other computer I do heroku config:set API_KEY=xxx.

    – Kamil Lelonek
    Oct 13 '18 at 15:07











  • Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

    – Kolban
    Oct 13 '18 at 15:09
















The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

– night-gold
Oct 13 '18 at 11:37





The same way you would do it on any other computer? More seriously, could you be more precise? What OS are you using? How do you create your compute engine? ....

– night-gold
Oct 13 '18 at 11:37




1




1





@night-gold on other computer I do heroku config:set API_KEY=xxx.

– Kamil Lelonek
Oct 13 '18 at 15:07





@night-gold on other computer I do heroku config:set API_KEY=xxx.

– Kamil Lelonek
Oct 13 '18 at 15:07













Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

– Kolban
Oct 13 '18 at 15:09





Might this be part of the answer to the question: stackoverflow.com/questions/52041092/…

– Kolban
Oct 13 '18 at 15:09












1 Answer
1






active

oldest

votes


















0














You can do it by connecting over SSH once you have created the instance.



It is explained in set default values in environment variables.

For example, use the export command to set the zone and region variables like:



$ export CLOUDSDK_COMPUTE_ZONE="us-central1-a"
$ export CLOUDSDK_COMPUTE_REGION="us-central1"


To make these environment variables permanent:



Alternatif-1: Using bashrc file




include these export commands in your ~/.bashrc file




you can use nano or vim to put the variables



sudo nano ~/.bashrc


then restart your terminal and cek



$ env


Alternatif-2: Using start up script



You can also use the export command within a start up script to let your metadata to become the environment variables.



Upon creating your instance you may put it directly or via a file like this:



gcloud compute instances create vm-1 
--metadata-from-file startup-script=$HOME/startup.sh
--zone=us-west1-a


If the instance is already running, follow the instructions to set a startup script on a running instance .



Please remember that if you use the method of this start up script then you will need to run the script manually each time you set new variables.



Whatever method you choose, make sure your $ env setting is working correctly.
Better cek it again by restarting your instance within the shell or using the stop and start button in your console.






share|improve this answer

























  • What if a machine is recreated after deployment?

    – Kamil Lelonek
    Mar 9 at 8:54











  • You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

    – Chetabahana
    Mar 9 at 23:04












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52792051%2fhow-to-use-environment-variables-in-compute-engine-on-google-cloud-platform%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














You can do it by connecting over SSH once you have created the instance.



It is explained in set default values in environment variables.

For example, use the export command to set the zone and region variables like:



$ export CLOUDSDK_COMPUTE_ZONE="us-central1-a"
$ export CLOUDSDK_COMPUTE_REGION="us-central1"


To make these environment variables permanent:



Alternatif-1: Using bashrc file




include these export commands in your ~/.bashrc file




you can use nano or vim to put the variables



sudo nano ~/.bashrc


then restart your terminal and cek



$ env


Alternatif-2: Using start up script



You can also use the export command within a start up script to let your metadata to become the environment variables.



Upon creating your instance you may put it directly or via a file like this:



gcloud compute instances create vm-1 
--metadata-from-file startup-script=$HOME/startup.sh
--zone=us-west1-a


If the instance is already running, follow the instructions to set a startup script on a running instance .



Please remember that if you use the method of this start up script then you will need to run the script manually each time you set new variables.



Whatever method you choose, make sure your $ env setting is working correctly.
Better cek it again by restarting your instance within the shell or using the stop and start button in your console.






share|improve this answer

























  • What if a machine is recreated after deployment?

    – Kamil Lelonek
    Mar 9 at 8:54











  • You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

    – Chetabahana
    Mar 9 at 23:04
















0














You can do it by connecting over SSH once you have created the instance.



It is explained in set default values in environment variables.

For example, use the export command to set the zone and region variables like:



$ export CLOUDSDK_COMPUTE_ZONE="us-central1-a"
$ export CLOUDSDK_COMPUTE_REGION="us-central1"


To make these environment variables permanent:



Alternatif-1: Using bashrc file




include these export commands in your ~/.bashrc file




you can use nano or vim to put the variables



sudo nano ~/.bashrc


then restart your terminal and cek



$ env


Alternatif-2: Using start up script



You can also use the export command within a start up script to let your metadata to become the environment variables.



Upon creating your instance you may put it directly or via a file like this:



gcloud compute instances create vm-1 
--metadata-from-file startup-script=$HOME/startup.sh
--zone=us-west1-a


If the instance is already running, follow the instructions to set a startup script on a running instance .



Please remember that if you use the method of this start up script then you will need to run the script manually each time you set new variables.



Whatever method you choose, make sure your $ env setting is working correctly.
Better cek it again by restarting your instance within the shell or using the stop and start button in your console.






share|improve this answer

























  • What if a machine is recreated after deployment?

    – Kamil Lelonek
    Mar 9 at 8:54











  • You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

    – Chetabahana
    Mar 9 at 23:04














0












0








0







You can do it by connecting over SSH once you have created the instance.



It is explained in set default values in environment variables.

For example, use the export command to set the zone and region variables like:



$ export CLOUDSDK_COMPUTE_ZONE="us-central1-a"
$ export CLOUDSDK_COMPUTE_REGION="us-central1"


To make these environment variables permanent:



Alternatif-1: Using bashrc file




include these export commands in your ~/.bashrc file




you can use nano or vim to put the variables



sudo nano ~/.bashrc


then restart your terminal and cek



$ env


Alternatif-2: Using start up script



You can also use the export command within a start up script to let your metadata to become the environment variables.



Upon creating your instance you may put it directly or via a file like this:



gcloud compute instances create vm-1 
--metadata-from-file startup-script=$HOME/startup.sh
--zone=us-west1-a


If the instance is already running, follow the instructions to set a startup script on a running instance .



Please remember that if you use the method of this start up script then you will need to run the script manually each time you set new variables.



Whatever method you choose, make sure your $ env setting is working correctly.
Better cek it again by restarting your instance within the shell or using the stop and start button in your console.






share|improve this answer















You can do it by connecting over SSH once you have created the instance.



It is explained in set default values in environment variables.

For example, use the export command to set the zone and region variables like:



$ export CLOUDSDK_COMPUTE_ZONE="us-central1-a"
$ export CLOUDSDK_COMPUTE_REGION="us-central1"


To make these environment variables permanent:



Alternatif-1: Using bashrc file




include these export commands in your ~/.bashrc file




you can use nano or vim to put the variables



sudo nano ~/.bashrc


then restart your terminal and cek



$ env


Alternatif-2: Using start up script



You can also use the export command within a start up script to let your metadata to become the environment variables.



Upon creating your instance you may put it directly or via a file like this:



gcloud compute instances create vm-1 
--metadata-from-file startup-script=$HOME/startup.sh
--zone=us-west1-a


If the instance is already running, follow the instructions to set a startup script on a running instance .



Please remember that if you use the method of this start up script then you will need to run the script manually each time you set new variables.



Whatever method you choose, make sure your $ env setting is working correctly.
Better cek it again by restarting your instance within the shell or using the stop and start button in your console.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 2:45

























answered Mar 8 at 23:42









ChetabahanaChetabahana

3,92612347




3,92612347












  • What if a machine is recreated after deployment?

    – Kamil Lelonek
    Mar 9 at 8:54











  • You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

    – Chetabahana
    Mar 9 at 23:04


















  • What if a machine is recreated after deployment?

    – Kamil Lelonek
    Mar 9 at 8:54











  • You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

    – Chetabahana
    Mar 9 at 23:04

















What if a machine is recreated after deployment?

– Kamil Lelonek
Mar 9 at 8:54





What if a machine is recreated after deployment?

– Kamil Lelonek
Mar 9 at 8:54













You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

– Chetabahana
Mar 9 at 23:04






You can use Instance Templates. It.allows you to define the instance properties to use when creating new VM instances with identical configurations including environment variables.

– Chetabahana
Mar 9 at 23:04




















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52792051%2fhow-to-use-environment-variables-in-compute-engine-on-google-cloud-platform%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко