0
votes

I have a working GCP-Deployment-Manager setup, consisting of a .jinja instance template and a config.yaml file.

Using the Google Cloud Console, I also have created a GCP reserved IP address. Now I want to assign that IP address to the newly deployed instance at deployment creation time.

Where must I add the value of this static IP address?

  • In the config.yaml file?
  • In the instance-template.jinja file?
  • in the gcloud deployment-manager deployments create ... command ?

And in which format?

I want to start my deployment such that it uses that static IP address from the very beginning. I already know how to change the ephemeral IP address to the reserved IP address, but that is an extra step of work, and it messes up the SSH keys configuration.

All deployment-manager script examples that I've seen before (examples) only create a new reserved IP address from scratch, it does not really "re-use" an existing one created previously.

I can post my config files here if requested, but maybe some expert can answer this question anyway.

UPDATE 6 hours later:

I have added this to the beginning of my instance-template.jinja file. Works for me:

{% set STATIC_IP = "my-ip-name" %}

resources:
- name: {{ STATIC_IP }}
  type: compute.v1.address
  properties:
    region: {{ properties["region"] }}

Maybe there is a more elegant way to do this, perhaps by passing in the name from within the config.yaml file (similar to "region" above)

1

1 Answers

1
votes

Okay, so a caveat here; this is not tested, merely theory.

Since you're defining a property that is going to belong to a resource, the place to define the property is in the resource config - that is, the config.yaml.

I'm not sure exactly what you're deploying, but let's say for giggles that you're deploying a Compute Instance. You may want to take a look at this GCP doc for reference on the layout of a config.yaml file (it has Compute + BigQuery as its samples).

You'd want to check out the Compute API Reference for a list of properties, to find the exact name of the IP address property. It's probably actually a subproperty, my best guess is networkInterfaces[].networkIP.

(Also take a look at GCP's Supported Resource Types doc for a master list of links to all of the resources available, in case I guessed wrong and you're not deploying a Compute instance.)

I really hope this helps you out a little! Check back and let us know how it went!