resources:
  - name: clgvpc-@deploymentId
    type: compute.v1.network
    properties:
      autoCreateSubnetworks: false

  - name: clgsubnet-@deploymentId
    type: compute.v1.subnetwork
    properties:
      network: $(ref.clgvpc-@deploymentId.selfLink)
      ipCidrRange: 10.1.0.0/24
      region: us-central1

  - name: allow-ssh-@deploymentId
    type: compute.v1.firewall
    properties:
      network: $(ref.clgvpc-@deploymentId.selfLink)
      sourceRanges: ['0.0.0.0/0']
      allowed:
      - IPProtocol: tcp
        ports: [22]
      targetTags: ['ssh']  

  - name: allow-http-https-@deploymentId
    type: compute.v1.firewall
    properties:
      network: $(ref.clgvpc-@deploymentId.selfLink)
      sourceRanges: ['0.0.0.0/0']
      allowed:
      - IPProtocol: tcp
        ports: [80, 443]
      targetTags: ['http-server', 'https-server']

  - name: labvm-@deploymentId
    type: compute.v1.instance
    properties:
      zone: us-central1-a
      machineType: zones/us-central1-a/machineTypes/e2-medium
      disks:
      - deviceName: boot
        type: PERSISTENT
        boot: true
        autoDelete: true
        initializeParams:
          sourceImage: projects/centos-cloud/global/images/centos-stream-9-v20240613
          diskSizeGb: 20
      networkInterfaces:
      - network: $(ref.clgvpc-@deploymentId.selfLink)
        subnetwork: $(ref.clgsubnet-@deploymentId.selfLink)
        accessConfigs:
        - name: External NAT
          type: ONE_TO_ONE_NAT
      tags:
        items: ['ssh']
      metadata:
        items:
        - key: startup-script
          value: |
            #!/bin/bash
            sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication yes/' /etc/ssh/sshd_config
            systemctl restart sshd
            useradd labuser
            echo -e "Password.1!!\nPassword.1!!"  |  passwd labuser

outputs:
  - name: vpcName
    value: $(ref.clgvpc-@deploymentId.name)

  - name: vpcId
    value: $(ref.clgvpc-@deploymentId.id)

  - name: subnetName
    value: $(ref.clgsubnet-@deploymentId.name)

  - name: subnetId
    value: $(ref.clgsubnet-@deploymentId.id)

  - name: vmPublicIp
    value: $(ref.labvm-@deploymentId.networkInterfaces[0].accessConfigs[0].natIP)

  - name: vmPrivateIp
    value: $(ref.labvm-@deploymentId.networkInterfaces[0].networkIP)

  - name: vmUsername
    value: "labuser"

  - name: vmPassword
    value: "Password.1!!"