How to include firewall in VM instance creation by DeploymentManager in GCP

A.JRJ picture A.JRJ · Jun 2, 2018 · Viewed 7.3k times · Source

my yaml template is as follows, I want to add firewall property to allow http traffic:

resources:

    - name: deployed-vm2222
      type: compute.v1.instance
      properties:
        zone: us-central1-f           
        machineType: https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/machineTypes/f1-micro
        disks:
        - deviceName: boot
          type: PERSISTENT
          boot: true
          autoDelete: true

Answer

Fady Ibrahim picture Fady Ibrahim · Feb 16, 2019

In the firewall, we use:

targetTags: ["http"]

Then, in the instance, we use:

tags:
    items: ["http"]

The complete file can be as shown:

resources:
- name: default-allow-http
  type: compute.v1.firewall
  properties:
    targetTags: ["http"]
    sourceRanges: ["0.0.0.0/0"]
    allowed:
      - IPProtocol: TCP
        ports: ["80"]    
- name: vm-test
  type: compute.v1.instance
  properties:
    zone: xxxx
    machineType: xxxx
    tags:
        items: ["http"]
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        diskName: xxxx
        sourceImage: xxxx
    networkInterfaces:
    - network: xxxx
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT