Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deployment manager: Not able to expose output through python template

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.

like image 834
Mauli Jadhav Avatar asked Sep 01 '26 04:09

Mauli Jadhav


1 Answers

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

like image 82
Nik Avatar answered Sep 02 '26 22:09

Nik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!