Skip to main content

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:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set gcp-py-instance-nginx
cd pulumi-examples/gcp-py-instance-nginx

Starting point for building the Pulumi NGINX server sample in Google Cloud Platform. This example deploys two GCP virtual machines:

Prerequisites#

  1. Install Pulumi
  2. Configure GCP credentials
  3. Install Python

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init dev
  2. Configure the project:

    Terminal window
    export GOOGLE_PROJECT=YOURPROJECTID; export GOOGLE_REGION=asia-east1; export GOOGLE_ZONE=asia-east1-a;
    export GOOGLE_CREDENTIALS=YOURGCPCREDENTIALS
  3. Install dependencies:

    Terminal window
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
  4. Run pulumi up to preview and deploy changes:

    Terminal window
    pulumi up
    Updating (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 created
    Outputs:
    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 created
    Duration: 59s
  5. 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:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.