3

I've created a deployment manager template in python which generates the resource names at runtime so as to create multiple deployments with the same template on google cloud platform. I need to expose external IP address of web server through output after successful deployment. I've added following in my python template:

def GenerateConfig(context):
    outputs = []
    resources = [
        {   
    }       ]
    outputs.append({'name': name, 
                    'value': value})

return {'resources': resources, 'outputs': outputs}

The problem is, the output is not getting displayed on the console, however, I can see it in the deployment layout.

  • Your displayed config seems appropriate to me and I see no reason why it should not be displayed in the Console. Perhaps you can consider similar implementation as explained [here](https://cloud.google.com/deployment-manager/docs/step-by-step-guide/using-multiple-templates#create_a_template_that_uses_the_network_firewall_and_virtual_machine_templates) – oakinlaja Apr 03 '18 at 19:10

2 Answers2

2

It took me a bit to figure this one out. In order for your outputs to be displayed on the console you need include the outputs in your schema file. So if your template is named template.py and looks like:

from lib.helper import Helper

def GenerateConfig(context):
  outputs = []
  resources = [
    {
      "name": "resource-1",
      "type": "resource.py"
    }
  ]
  outputs.append({'name': "myField", 
                  'value': "$(ref.resource-1.someValue)"})
  outputs.append({'name': "myOtherField", 
                  'value': "$(ref.resource-1.someOtherValue)"})

  return {'resources': resources, 'outputs': outputs}

You would then have a schema file named template.py.schema with the contents:

imports:
- path: "lib/helper.py"
- path: "templates/resource.py"
  name: "resource.py"

outputs:
  myField:
  myOtherField:

It's very late, but I hope this helps someone!

Bonus Tip: When using a Python file as the template, you have to use the schema file to specify your includes (even libraries!), as shown in the above example.

Reference: Exposing Information Using Outputs

Nik
  • 472
  • 3
  • 12
0

Your displayed config seems appropriate to me and I see no reason why it should not be displayed in the Console. Perhaps you can consider similar implementation as explained here

oakinlaja
  • 826
  • 6
  • 10