GCP Deployment Manager-删除防火墙规则(如果存在)

时间:2018-12-11 13:12:50

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

仅当使用以下GCP部署管理器配置存在某些防火墙规则(默认规则)时,我才尝试删除它们,但是我遇到一些错误,我们将不胜感激:

default_vpc_list.jinja:

       resources:

    - name: def_firw
      action: gcp-types/compute-v1:compute.firewalls.list  
      properties:
        filter: (name = "default*")


    {% if "($(ref.def_firw.items[0]))"|length > 0 %}     
    - name: firewall-delete-internal
      action: gcp-types/compute-v1:compute.firewalls.delete
      metadata:
        dependsOn: 
        - def_firw
      properties:
        firewall: $(ref.def_firw.items[0].name)
    {% endif %}

    outputs:
    - name: fw_rules
      value: $(ref.def_firw.items[0].name) 

这是Yaml文件:

imports:
- path: jinja/default_vpc_list.jinja
  name: default_vpc_list.jinja

resources:

- name: default_vpc_list
  type: default_vpc_list.jinja

和错误 我收到以下代码:

The reference 'items[0].name' is not found, reason: The resource 'def_firw' exists, but the reference value does not, details: Missing property in path $['ref']['def_firw']['items']

更新: 通过了一种解决方法,并将runtimePolicy:CREATE设置为仅在创建资源时触发:

- name: delete-default-private-route
  action: gcp-types/compute-v1:compute.routes.delete
  metadata:
    dependsOn: 
    - defaultRoutelist  
    runtimePolicy:
    - CREATE
  properties:
    route: $(ref.defaultRoutelist.items[0].name) 

1 个答案:

答案 0 :(得分:0)

已发现仅在CREATE资源上运行删除操作的解决方法,不再需要执行列表,请参见更新上方。