Skip to content

augustincl/iac_intro_w_pulumi

Repository files navigation

Start your first Pulumi with tests

This project includes a basic webserver hosted by ngnix with GCP!

resource type value
Instance type e2-small
Region asia-east1
network standard

This project will leverage the above context to provide the examples for unit tests and property tests. It introduces a tiny tool called testinfra. Based on this tool, we could make some convenient tools for us to check the infrastructure.

Enjoy it!

Prerequisite

  • This project leverages GCP. Please setup your gcloud SDK
  • You should leverage gcloud command to setup your application token
  • Python 3.7+. ⚠️ DO NOT USE VERSION 2.x
  • Pulumi

📣

  1. All the commands are based on LINUX
  2. If you are a Windows user, please note that you might need to adjust some instructions!
  3. Please refer to the official site for gcloud and pulumi for more details about the installation
  4. Please leverage Anaconda to setup your python environment.

Running the App

  1. Download and initialize your environment

⚠️ For Windows users, please leverage Anaconda to create your virtual environment. Then, use command to install requirements.txt

```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```
  1. Create a new stack:

    $ pulumi stack init dev
    
  2. Configure the project:

    $ pulumi config set gcp:project YOURGOOGLECLOUDPROJECT
    $ pulumi config set gcp:zone asia-east1-a
    
  3. Try the unit tests!

    $pytest -s --disable-pytest-warnings tests/*
    
  4. Run pulumi up --policy-pack policy_tests to preview and deploy changes:

    $ pulumi up -y
    Previewing update (dev):
        Type                     Name                    Plan       Info
    +   pulumi:pulumi:Stack      iac_intro_w_pulumi-dev  create
    +   ├─ gcp:compute:Address   addr-4-intro            create
    +   ├─ gcp:compute:Network   network-4-intro         create
    +   ├─ gcp:compute:Firewall  firewall-4-intro        create
    +   └─ gcp:compute:Instance  instance-4-intro        create
    
    Resources:
        + 5 create
    
    Policy Packs run:
        Name                               Version
        intro-policy-check (policy_tests)  (local)
    
    Updating (dev):
        Type                     Name                    Status      Info
    +   pulumi:pulumi:Stack      iac_intro_w_pulumi-dev  created
    +   ├─ gcp:compute:Address   addr-4-intro            created
    +   ├─ gcp:compute:Network   network-4-intro         created
    +   ├─ gcp:compute:Firewall  firewall-4-intro        created
    +   └─ gcp:compute:Instance  instance-4-intro        created
    
    Outputs:
        instance_external_ip  : "35.206.226.215"
        instance_name: {...
    
    Resources:
        + 5 created
    
    Policy Packs run:
        Name                               Version
        intro-policy-check (policy_tests)  (local)
    
    Duration: 1m3s
    
  5. Curl the HTTP server:

    $ curl $(pulumi stack output instance_external_ip)
    <html>
        <body>
            <h1>Welcome to KSWS today!<h1>
        </body>
    </html>
    
  6. Cleanup

⚠️ DON'T FORGET TO REMOVE YOUR CREATED RESOURCES, IF YOU DON'T WANT THEM!

```
$ pulumi destroy
$ pulumi stack rm
```

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages