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!
- 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
📣
- All the commands are based on LINUX
- If you are a Windows user, please note that you might need to adjust some instructions!
- Please refer to the official site for gcloud and pulumi for more details about the installation
- Please leverage Anaconda to setup your python environment.
- Download and initialize your environment
```bash
$ python3 -m venv venv
$ source venv/bin/activate
$ pip3 install -r requirements.txt
```
-
Create a new stack:
$ pulumi stack init dev
-
Configure the project:
$ pulumi config set gcp:project YOURGOOGLECLOUDPROJECT $ pulumi config set gcp:zone asia-east1-a
-
Try the unit tests!
$pytest -s --disable-pytest-warnings tests/*
-
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
-
Curl the HTTP server:
$ curl $(pulumi stack output instance_external_ip) <html> <body> <h1>Welcome to KSWS today!<h1> </body> </html>
-
Cleanup
```
$ pulumi destroy
$ pulumi stack rm
```