> ## Documentation Index
> Fetch the complete documentation index at: https://cloud.strettch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Deploy a web server

> Provision a compute instance with Terraform, then install Nginx and serve a page — end to end.

A complete walkthrough: define a compute instance in Terraform, apply it, connect over SSH, and serve a web page with Nginx.

> [!NOTE]
>
> New to the provider? Run through the [Quickstart](https://cloud.strettch.com/docs/terraform/quickstart.md) and [Authentication](https://cloud.strettch.com/docs/terraform/authentication.md) first — this guide assumes Terraform is installed and `STRETTCH_CLOUD_API_KEY` is set.

## What you'll build

* A compute instance with a public IP
* SSH access with your own key
* Nginx serving a page over HTTP

**1. Set up the project**

Create a new directory with three files:

```hcl main.tf theme={null}
terraform {
  required_providers {
    strettchcloud = {
      source  = "strettch-cloud/strettchcloud"
      version = "~> 1.0"
    }
  }
}

provider "strettchcloud" {
  # api_key is read from STRETTCH_CLOUD_API_KEY
}

resource "strettchcloud_compute" "web" {
  host_name      = "web-01"
  image          = "UBUNTU-24.04"
  region         = "KGL-1"
  specification  = "S-1C-1G"
  public_keys    = [var.ssh_public_key]
  with_public_ip = true
  tags           = ["web", "demo"]
}
```

```hcl variables.tf theme={null}
variable "ssh_public_key" {
  description = "Your SSH public key (contents of e.g. ~/.ssh/id_ed25519.pub)."
  type        = string
}
```

```hcl outputs.tf theme={null}
output "public_ip" {
  value = strettchcloud_compute.web.ipv4
}
```

**2. Provide your credentials**

Set your API key and keep your SSH public key handy:

```bash theme={null}
export STRETTCH_CLOUD_API_KEY="<your api key>"
```

> [!TIP]
>
> Don't have an SSH key yet? Generate one with `ssh-keygen`, then your public key is at `~/.ssh/id_ed25519.pub`. See [SSH Keys](https://cloud.strettch.com/docs/services/compute/ssh-keys.md) for the full walkthrough.

**3. Initialize and apply**

Download the provider and create the instance, passing your public key in:

```bash theme={null}
terraform init
terraform apply -var="ssh_public_key=$(cat ~/.ssh/id_ed25519.pub)"
```

Review the plan, type `yes`, and Terraform prints the `public_ip` when the instance is up.

**4. Connect over SSH**

Strettch Cloud exposes SSH on port **222**. Connect as `root`:

```bash theme={null}
ssh root@$(terraform output -raw public_ip) -p 222
```

**5. Install Nginx**

On the instance, install and start Nginx:

```bash theme={null}
apt update && apt install -y nginx
```

Replace the default page with your own:

```bash theme={null}
echo "<h1>Hello from Strettch Cloud 🚀</h1>" > /var/www/html/index.html
```

**6. Verify**

Open `http://<your-public-ip>` in a browser — you'll see your page. Your web server is live, defined entirely in Terraform.

**7. Tear it down**

When you're finished, destroy everything you created:

```bash theme={null}
terraform destroy -var="ssh_public_key=$(cat ~/.ssh/id_ed25519.pub)"
```

***

## Make it repeatable

Because the whole server is now described in code, you can:

* **Version it** — commit `main.tf`, `variables.tf`, and `outputs.tf` to Git.
* **Review changes** — run `terraform plan` before every change to see exactly what will happen.
* **Reproduce it** — apply the same files to stand up an identical instance any time, or for a second environment.

> [!TIP]
>
> Avoid hardcoding `image`, `region`, or `specification`. Look them up as data sources instead — see [Look up catalog values](https://cloud.strettch.com/docs/terraform/quickstart.md#look-up-catalog-values) in the Quickstart.

***

## Next steps

> [card] [Resources & data sources](https://cloud.strettch.com/docs/terraform/resources.md)
>
> The full catalog of what the provider can manage.

> [card] [Full reference](https://registry.terraform.io/providers/strettch-cloud/strettchcloud/latest/docs)
>
> Every argument and attribute on the Terraform Registry.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.