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
Running the App#
-
Create a new stack:
Terminal window pulumi stack init gcp-instance-nginx -
Configure the project:
Terminal window export GOOGLE_PROJECT=YOURPROJECTID; export GOOGLE_REGION=asia-east1; export GOOGLE_ZONE=asia-east1-a;export GOOGLE_CREDENTIALS=YOURGCPCREDENTIALS -
Run
pulumi upto preview and deploy changes:Terminal window pulumi upPreviewing update (dev):Type Name Plan+ pulumi:pulumi:Stack gcp-instance-nginx-dev create+ ├─ gcp:compute:Address poc create+ ├─ gcp:compute:Network poc create+ ├─ gcp:compute:Address poc-container-instance create+ ├─ gcp:compute:Firewall poc create+ ├─ gcp:compute:Instance poc create+ └─ gcp:compute:Instance poc-container-instance createResources:+ 7 to createDo you want to perform this update? yesUpdating (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)<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><title>Test Page for the Nginx HTTP Server on Fedora</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><style type="text/css">/*<![CDATA[*/body {background-color: #fff;color: #000;font-size: 0.9em;font-family: sans-serif,helvetica;margin: 0;padding: 0;}:link {color: #c00;}:visited {color: #c00;}a:hover {color: #f50;}h1 {text-align: center;margin: 0;padding: 0.6em 2em 0.4em;background-color: #294172;color: #fff;font-weight: normal;font-size: 1.75em;border-bottom: 2px solid #000;}h1 strong {font-weight: bold;font-size: 1.5em;}h2 {text-align: center;background-color: #3C6EB4;font-size: 1.1em;font-weight: bold;color: #fff;margin: 0;padding: 0.5em;border-bottom: 2px solid #294172;}hr {display: none;}.content {padding: 1em 5em;}.alert {border: 2px solid #000;}img {border: 2px solid #fff;padding: 2px;margin: 2px;}a:hover img {border: 2px solid #294172;}.logos {margin: 1em;text-align: center;}/*]]>*/</style></head><body><h1>Welcome to <strong>nginx</strong> on Fedora!</h1><div class="content"><p>This page is used to test the proper operation of the<strong>nginx</strong> HTTP server after it has beeninstalled. If you can read this page, it means that theweb server installed at this site is workingproperly.</p><div class="alert"><h2>Website Administrator</h2><div class="content"><p>This is the default <tt>index.html</tt> page thatis distributed with <strong>nginx</strong> onFedora. It is located in<tt>/usr/share/nginx/html</tt>.</p><p>You should now put your content in a location ofyour choice and edit the <tt>root</tt> configurationdirective in the <strong>nginx</strong>configuration file<tt>/etc/nginx/nginx.conf</tt>.</p></div></div><div class="logos"><a href="http://nginx.net/"><imgsrc="nginx-logo.png"alt="[ Powered by nginx ]"width="121" height="32" /></a><a href="http://fedoraproject.org/"><imgsrc="poweredby.png"alt="[ Powered by Fedora ]"width="88" height="31" /></a></div></div></body></html> -
Destroy the created resources:
Terminal window pulumi destroyPreviewing destroy (dev):Type Name Plan- pulumi:pulumi:Stack gcp-instance-nginx-dev delete- ├─ gcp:compute:Firewall poc delete- ├─ gcp:compute:Instance poc delete- ├─ gcp:compute:Instance poc-container-instance delete- ├─ gcp:compute:Address poc-container-instance delete- ├─ gcp:compute:Network poc delete- └─ gcp:compute:Address poc deleteOutputs:- 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 to deleteDo you want to perform this destroy? yesDestroying (dev):Type Name Status- pulumi:pulumi:Stack gcp-instance-nginx-dev deleted- ├─ gcp:compute:Firewall poc deleted- ├─ gcp:compute:Instance poc deleted- ├─ gcp:compute:Instance poc-container-instance deleted- ├─ gcp:compute:Network poc deleted- ├─ gcp:compute:Address poc-container-instance deleted- └─ gcp:compute:Address poc deletedOutputs:- 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 deletedDuration: 3m9s -
Destroy the stack:
Terminal window pulumi stack rmThis will permanently remove the 'gcp-instance-nginx' stack!Please confirm that this is what you'd like to do by typing ("gcp-instance-nginx"): gcp-instance-nginxStack 'gcp-instance-nginx' has been removed!