NGINX server using Compute Engine
Deploy a Nginx Server in a GCP instance
This example lives in the pulumi/examples repository. Check out just this directory to use it:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set gcp-py-instance-nginxcd pulumi-examples/gcp-py-instance-nginxStarting point for building the Pulumi NGINX server sample in Google Cloud Platform. This example deploys two GCP virtual machines:
- a virtual machine running NGINX via a startup script
- a virtual machine running NGINX via a Docker container with Google’s Container-Optimized OS
Prerequisites#
Deploying the example#
-
Create a new stack:
Terminal window pulumi stack init dev -
Configure the project:
Terminal window export GOOGLE_PROJECT=YOURPROJECTID; export GOOGLE_REGION=asia-east1; export GOOGLE_ZONE=asia-east1-a;export GOOGLE_CREDENTIALS=YOURGCPCREDENTIALS -
Install dependencies:
Terminal window python3 -m venv venvsource venv/bin/activatepip install -r requirements.txt -
Run
pulumi upto preview and deploy changes:Terminal window pulumi upUpdating (dev):Type Name Status+ pulumi:pulumi:Stack gcp-instance-nginx-dev created+ ├─ gcp:compute:Address poc created+ ├─ gcp:compute:Network poc created+ ├─ gcp:compute:Address poc-container-instance created+ ├─ gcp:compute:Firewall poc created+ ├─ gcp:compute:Instance poc created+ └─ gcp:compute:Instance poc-container-instance createdOutputs:container_instance_external_ip: "34.66.98.237"container_instance_name : "poc-container-instance-11dddc1"instance_external_ip : "35.192.222.243"instance_name : "poc-4897b20"Resources:+ 7 createdDuration: 59s -
Curl the HTTP server:
Terminal window curl $(pulumi stack output instance_external_ip)This returns the default NGINX test page.
Cleaning up#
Once you’re finished experimenting, destroy your stack and remove it:
pulumi destroypulumi stack rm