如何使用Deployment Manager将服务帐户添加到实例模板

时间:2018-04-25 01:53:51

标签: google-cloud-platform google-deployment-manager

我正在尝试根据此处1中给出的示例创建简单的VM。 我想将自定义服务帐户2添加到此VM。 我的配置看起来像这样

def GenerateConfig(context):
"""Create instance with disks."""

resources = [{
    'type': 'compute.v1.instance',
    'name': 'vm-' + context.env['deployment'],
    'properties': {
        'zone': context.properties['zone'],
        'disks': [{
            'deviceName': 'boot',
            'type': 'PERSISTENT',
            'boot': True,
            'autoDelete': True,
            'initializeParams': {
                'diskName': 'disk-' + context.env['deployment'],
             }
        }],
        'networkInterfaces': [{
            'network': '...',       
            'subnetwork': '...',                       
            'no-address': True,
        }],
        'tags':{
            'items': [context.env['deployment']]
        },
        'service-account': ''.join(['custom-compute@',
                                    context.env['project'],
                                    '.iam.gserviceaccount.com']),
        'scopes': ['https://www.googleapis.com/auth/devstorage.read_only',
                   'https://www.googleapis.com/auth/logging.write',
                   'https://www.googleapis.com/auth/monitoring.write',
                   'https://www.googleapis.com/auth/trace.append']

    }
}]
return {'resources': resources}

我能够成功创建部署。但是,当我描述新创建的实例时,它没有与vm相关联的任何“服务帐户”。

我找不到任何将服务帐户添加到Deployment Manager模板的示例。我也尝试使用“serviceAccount”键而不是“service-account”而没有任何成功。 有谁知道我错过了什么?

1 个答案:

答案 0 :(得分:1)

我找到了引用DM reference docs。 所需的更改是

'serviceAccounts': [{
    'email': '....',
    'scopes': '...' 
 }]
相关问题