3

I have a python template as shown below for a compute instance type along with other needed config.yaml file.

... CONTROLLER_MACHINE_TYPE='n1-standard-8' controller_template = { 'name': 'controller-it', 'type': 'it_template.py', 'properties': { 'machineType': CONTROLLER_MACHINE_TYPE, 'dockerImage': CONTROLLER_IMAGE, 'dockerEnv': { 'ADC_LISTEN_QUEUE': 'controller-subscriber' }, 'zone': ZONE, 'network': NETWORK_NAME, 'saEmail': SA_EMAIL } }

it_template.py contents

def GenerateConfig(context):
    resources = [{
        'name': context.env['name'],
        'type': 'compute.v1.instanceTemplate',
        'properties': {
            'zone': context.properties['zone'],
            'properties': {
                "machineType": context.properties['machineType'],
                "metadata": {
                    "items": [{
                        "key": 'gce-container-declaration',
                        "value": GenerateManifest(context)
                    }]
                }, ...

I have deployed it with the environment named qa. Now after sometime I realized that I need to change the machine type of this instance. For eg instead of n1-standard-8, I want my qa environment to update the type of machine for this resource.

However I don't see any example which mentions about updating the property of any resource.

Can we update the property of a resource in an environment using gcp deployment manager? Or I need to add a new resource with another name and desired machine type property?

Update

As suggested by @jordi Miralles, I modified my template to have machineType as n1-standard-16 and tried to update the deployment.

But I got below error

cloud deployment-manager deployments update qa --config dm_config.yaml The fingerprint of the deployment is KkD38j9KYiBTiaIW8SltbA== Waiting for update [operation-1525444590548-56b623ef1b421-b4733efd-53174d1b]...failed.
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1525444590548-56b623ef1b421-b4733efd-53174d1b]: errors: - code: NO_METHOD_TO_UPDATE_FIELD message: No method found to update field 'properties' on resource 'controller-it' of type 'compute.v1.instanceTemplate'. The resource may need to be recreated with the new field.

Please help.

1 Answer 1

1

You can update resources in your deployment manager, there is no need to create a new one with a different name if you want to change a resource. See updating a deployment

You can use your existing deployment yaml file with the changes you want to apply and then update your existing deployment:

gcloud deployment-manager deployments update [EXISTING DEPLOYMENT] --config [UPDATED YAML]

Take into account that your instance must be stopped. All other implications on changing machine type apply. Also, no data on any of your persistent disks will be lost.

Remember to turn on the instances when the update finishes!

2
  • Thanks for your response. As suggested I updated the deployment but got the error. I have update it in main contents above. Commented May 4, 2018 at 14:53
  • Take a look at this answer from serverfault, it may be useful for you: serverfault.com/questions/726490/…
    – Tux
    Commented Jun 7, 2018 at 10:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.