Search code examples
templatesgoogle-cloud-platformgoogle-deployment-manager

Problem while configure a Firewall and a Startup Script with Deployment Manager template


I want to configure a Firewall and a Startup Script with Deployment Manager template in .yaml file

Below are the steps I need to perform

  1. A new Deployment Manager deployment has been created
  2. The deployment includes a virtual machine that has an embedded startup-script
  3. The virtual machine that has a startup-script also has a tag item called http
  4. A firewall rule exists that allows port 80 (http) traffic and is applied using a tag with a value of http
  5. The virtual machine responds to web requests using the Apache web server
  6. Check that Deployment manager includes startup script and firewall resources

Below is the sample file i have created, but while deploying the file its showing that step 3 (The virtual machine that has a startup-script also has a tag item called http) was not configured.

Please help me if I missed any thing.

- name: my-vm
  type: compute.v1.instance
  properties:
    zone: us-central1-a
    machineType: zones/us-central1-a/machineTypes/n1-standard-1
    sourceRanges: ["0.0.0.0/0"]
    targetTags: ["webserver"]
    allowed:
    - IPProtocol: TCP
    ports: ["80"]
    metadata:
      items:
      - key: startup-script
        value: |
         #! /bin/bash
         apt-get update
         apt-get install -y apache2
         cat <<EOF > /var/www/html/index.html
         <html><body><h1>Welcome to Apache</h1>
         <p>This page was created from a simple startup script!</p>
         </body></html>
    disks:
    - deviceName: boot
      type: PERSISTENT
      boot: true
      autoDelete: true
      initializeParams:
        sourceImage: https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-9-stretch-v20180814
    networkInterfaces:
    - network: https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-dee231a39b26c176/global/networks/default
      accessConfigs:
      - name: External NAT
        type: ONE_TO_ONE_NAT

Solution

  • The option "value" should be a string format.

    For example:

    metadata:
          items:
          - key: startup-script
            value: "apt-get update \n apt-get install -y apache2"