GCP VM Deployment: How to update yaml config properties dynamically while creating a VM
We have a nodejs application which creates VM on GCP using config file (.yaml) and templates. Now I want to update few properties in the yaml/template based on the user input from UI while creating the VM. How can we update the config properties dynamically? Thanks in advance for any suggestions.
google-api google-cloud-platform gcloud google-api-nodejs-client google-deployment-manager
add a comment |
We have a nodejs application which creates VM on GCP using config file (.yaml) and templates. Now I want to update few properties in the yaml/template based on the user input from UI while creating the VM. How can we update the config properties dynamically? Thanks in advance for any suggestions.
google-api google-cloud-platform gcloud google-api-nodejs-client google-deployment-manager
add a comment |
We have a nodejs application which creates VM on GCP using config file (.yaml) and templates. Now I want to update few properties in the yaml/template based on the user input from UI while creating the VM. How can we update the config properties dynamically? Thanks in advance for any suggestions.
google-api google-cloud-platform gcloud google-api-nodejs-client google-deployment-manager
We have a nodejs application which creates VM on GCP using config file (.yaml) and templates. Now I want to update few properties in the yaml/template based on the user input from UI while creating the VM. How can we update the config properties dynamically? Thanks in advance for any suggestions.
google-api google-cloud-platform gcloud google-api-nodejs-client google-deployment-manager
google-api google-cloud-platform gcloud google-api-nodejs-client google-deployment-manager
asked Nov 20 '18 at 10:40
user2106568user2106568
816
816
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
GCP deployment Manager does not have a way to do this dynamically. You'd have to add an additional layer (like the click to deploy marketplace) which allows users to select variables before applying the config file. DM does not have something that does this.
add a comment |
It seems like you have two options:
1) The jinja template way
Instead of a config file, you define a jinja template:
resources:
# my-template.jinja
resources:
- name: my-resource
type: some-type
properties:
prop1: {{ properties['foo'] }}
prop2: {{ properties['bar'] }}
Then, you can invoke it like so and the variables foo and bar will get mapped to the provided properties:
gcloud deployment-manager deployments create <my-deployment>
--template my-template.jinja
--properties foo:user-custom-value,bar:another-value
2) The old-schoold template way
We are replacing the custom values in the text itself, instead of using a render engine (like jinja2 is)
# my-template.yaml
resources:
- name: my-resource
type: some-type
properties:
prop1: REPLACE-PROP-1
prop2: REPLACE-PROP-2
Replace the text as you may, you can use sed
if you are running a shell script, or from node/javascript itself
const replaces = [
{name: 'REPLACE-PROP-1', value: 'user-custom-value'},
{name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
.map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
Or use sed
sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
And finally deploy the config:
gcloud deployment-manager deployments create <my-deployment>
--config my-template.yaml
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391199%2fgcp-vm-deployment-how-to-update-yaml-config-properties-dynamically-while-creati%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
GCP deployment Manager does not have a way to do this dynamically. You'd have to add an additional layer (like the click to deploy marketplace) which allows users to select variables before applying the config file. DM does not have something that does this.
add a comment |
GCP deployment Manager does not have a way to do this dynamically. You'd have to add an additional layer (like the click to deploy marketplace) which allows users to select variables before applying the config file. DM does not have something that does this.
add a comment |
GCP deployment Manager does not have a way to do this dynamically. You'd have to add an additional layer (like the click to deploy marketplace) which allows users to select variables before applying the config file. DM does not have something that does this.
GCP deployment Manager does not have a way to do this dynamically. You'd have to add an additional layer (like the click to deploy marketplace) which allows users to select variables before applying the config file. DM does not have something that does this.
answered Nov 20 '18 at 14:49
Patrick WPatrick W
8421210
8421210
add a comment |
add a comment |
It seems like you have two options:
1) The jinja template way
Instead of a config file, you define a jinja template:
resources:
# my-template.jinja
resources:
- name: my-resource
type: some-type
properties:
prop1: {{ properties['foo'] }}
prop2: {{ properties['bar'] }}
Then, you can invoke it like so and the variables foo and bar will get mapped to the provided properties:
gcloud deployment-manager deployments create <my-deployment>
--template my-template.jinja
--properties foo:user-custom-value,bar:another-value
2) The old-schoold template way
We are replacing the custom values in the text itself, instead of using a render engine (like jinja2 is)
# my-template.yaml
resources:
- name: my-resource
type: some-type
properties:
prop1: REPLACE-PROP-1
prop2: REPLACE-PROP-2
Replace the text as you may, you can use sed
if you are running a shell script, or from node/javascript itself
const replaces = [
{name: 'REPLACE-PROP-1', value: 'user-custom-value'},
{name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
.map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
Or use sed
sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
And finally deploy the config:
gcloud deployment-manager deployments create <my-deployment>
--config my-template.yaml
add a comment |
It seems like you have two options:
1) The jinja template way
Instead of a config file, you define a jinja template:
resources:
# my-template.jinja
resources:
- name: my-resource
type: some-type
properties:
prop1: {{ properties['foo'] }}
prop2: {{ properties['bar'] }}
Then, you can invoke it like so and the variables foo and bar will get mapped to the provided properties:
gcloud deployment-manager deployments create <my-deployment>
--template my-template.jinja
--properties foo:user-custom-value,bar:another-value
2) The old-schoold template way
We are replacing the custom values in the text itself, instead of using a render engine (like jinja2 is)
# my-template.yaml
resources:
- name: my-resource
type: some-type
properties:
prop1: REPLACE-PROP-1
prop2: REPLACE-PROP-2
Replace the text as you may, you can use sed
if you are running a shell script, or from node/javascript itself
const replaces = [
{name: 'REPLACE-PROP-1', value: 'user-custom-value'},
{name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
.map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
Or use sed
sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
And finally deploy the config:
gcloud deployment-manager deployments create <my-deployment>
--config my-template.yaml
add a comment |
It seems like you have two options:
1) The jinja template way
Instead of a config file, you define a jinja template:
resources:
# my-template.jinja
resources:
- name: my-resource
type: some-type
properties:
prop1: {{ properties['foo'] }}
prop2: {{ properties['bar'] }}
Then, you can invoke it like so and the variables foo and bar will get mapped to the provided properties:
gcloud deployment-manager deployments create <my-deployment>
--template my-template.jinja
--properties foo:user-custom-value,bar:another-value
2) The old-schoold template way
We are replacing the custom values in the text itself, instead of using a render engine (like jinja2 is)
# my-template.yaml
resources:
- name: my-resource
type: some-type
properties:
prop1: REPLACE-PROP-1
prop2: REPLACE-PROP-2
Replace the text as you may, you can use sed
if you are running a shell script, or from node/javascript itself
const replaces = [
{name: 'REPLACE-PROP-1', value: 'user-custom-value'},
{name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
.map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
Or use sed
sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
And finally deploy the config:
gcloud deployment-manager deployments create <my-deployment>
--config my-template.yaml
It seems like you have two options:
1) The jinja template way
Instead of a config file, you define a jinja template:
resources:
# my-template.jinja
resources:
- name: my-resource
type: some-type
properties:
prop1: {{ properties['foo'] }}
prop2: {{ properties['bar'] }}
Then, you can invoke it like so and the variables foo and bar will get mapped to the provided properties:
gcloud deployment-manager deployments create <my-deployment>
--template my-template.jinja
--properties foo:user-custom-value,bar:another-value
2) The old-schoold template way
We are replacing the custom values in the text itself, instead of using a render engine (like jinja2 is)
# my-template.yaml
resources:
- name: my-resource
type: some-type
properties:
prop1: REPLACE-PROP-1
prop2: REPLACE-PROP-2
Replace the text as you may, you can use sed
if you are running a shell script, or from node/javascript itself
const replaces = [
{name: 'REPLACE-PROP-1', value: 'user-custom-value'},
{name: 'REPLACE-PROP-2', value: 'another-custom-value'},
];
const templateYaml = fs.readFileSync('my-template.yaml','utf-8');
const customYaml = replaces
.map(r => templateYaml.replace(RegExp(r.name,'g'), r.value);
Or use sed
sed -ie 's/REPLACE-PROP-1/user-custom-value/g' my-template.yaml
sed -ie 's/REPLACE-PROP-2/another-cst-value/g' my-template.yaml
And finally deploy the config:
gcloud deployment-manager deployments create <my-deployment>
--config my-template.yaml
answered Jan 16 at 12:44
dinigodinigo
1,5941929
1,5941929
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391199%2fgcp-vm-deployment-how-to-update-yaml-config-properties-dynamically-while-creati%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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