0

I'm trying to delete some firewall rules (default ones) only if they exist using GCP Deployment manager config below but i'm getting some errors, any help would be appreciated:

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) 

Here is the yaml file:

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

resources:

- name: default_vpc_list
  type: default_vpc_list.jinja

And the erro r i get with this code:

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']

UPDATE: Adopted a workaround and set the runtimePolicy: CREATE, to be triggered only when resource is created:

- 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) 
Vasile V.
  • 21
  • 6
  • I am assuming that ur defaultRouterlist is still a list action on the routers... It might be helpful if u could include that part as well bcoz ur problem was about firewalls and ur final update is about router – niklodeon Mar 22 '20 at 00:30

1 Answers1

0

Workaround found to run the delete only on CREATE resource is triggered,not needed to do the listing anymore, see above the Update.

Vasile V.
  • 21
  • 6