- HCL 100%
PowerVS connection pattern demo #
Terraform code (and companion blog series) demonstrating three different ways to connect an on-premises network to an IBM Cloud Power Virtual Server (PowerVS) workspace:
- A VPC site-to-site VPN gateway
- A VPC client-to-site VPN server
- A VPC virtual server instance running Tailscale
Earlier drafts of this series also planned a VPC VSI running OPNsense, a classic Juniper vSRX gateway, and a wrap-up/comparison post. Both have been dropped to keep the series to a tight, shippable five posts — this README reflects that current scope, not the original one.
The series #
| # | Post | Covers | Terraform |
|---|---|---|---|
| 1 | Setting the scene | VPC, PowerVS workspaces, Transit Gateway, S2S vs. C2S VPN, Tailscale, Terraform — concepts only, nothing deployed | none |
| 2 | Foundation | VPC, subnets, security groups, Transit Gateway, PowerVS workspace, outbound internet access via a route-mode NLB | post-2/ |
| 3 | Site-to-site VPN | VPC VPN gateway, on-prem peer configuration | post-3/ |
| 4 | Client-to-site VPN | VPC VPN server, OpenVPN client setup | post-4/ |
| 5 | Tailscale | VSI subnet router, Tailscale mesh, subnet advertisement | post-5/ |
Post 1 has no Terraform — it's the concepts post that sets up the other four. Posts 3–5 are independent of each other but all depend on post 2: each one adds exactly one connection method on top of the same VPC/PowerVS foundation, so its Terraform diff stays small and its blog post can focus on the one new concept instead of re-explaining subnets every time.
Each post directory has its own README.md covering what that post builds
and how to run it — this file is just the map.
Repository structure #
powervs-connection-pattern-demo/
├── README.md # you are here
├── HANDOFF.md # current state + next-steps for a fresh session picking this up
├── fnox.toml # shared secret store (ibmcloud_api_key) — one vault, whole repo
├── .gitignore # excludes *.tfstate and *.tfvars — state and secrets never get committed
├── diagrams/
│ └── post-2-network-plumbing.svg
├── post-1/
│ └── POST-1-OUTLINE.md # concepts post — no Terraform
├── post-2/
│ ├── README.md
│ ├── mise.toml
│ ├── provider.tf
│ ├── versions.tf
│ ├── variables.tf
│ ├── vpc.tf
│ ├── subnets.tf
│ ├── security_groups.tf
│ ├── transit_gateway.tf
│ ├── powervs.tf
│ ├── nlb.tf # outbound internet access — new, not yet written
│ ├── outputs.tf
│ ├── terraform.tfvars.example
│ └── terraform.tfstate # local backend, gitignored — the state posts 3-5 read from
├── post-3/
│ ├── README.md
│ ├── mise.toml
│ └── *.tf # reads post-2's outputs via terraform_remote_state
├── post-4/
│ ├── README.md
│ ├── mise.toml
│ └── *.tf
└── post-5/
├── README.md
├── mise.toml
└── *.tf
The post-1–post-5 folders already exist. The .tf files are still flat
at the repo root, mid-migration into post-2/ — see HANDOFF.md for the
exact next steps and why that's deliberately left for a session with real
mise/fnox/IBM Cloud access to finish, rather than done sight-unseen.
Because terraform.tfstate is gitignored (correctly — state can contain
sensitive values), it does not travel with the repo to a new machine.
Post 2 needs a fresh mise run apply on any new machine before posts 3–5's
terraform_remote_state lookups have anything to read.
How the shared state works #
Each post directory is its own Terraform working directory with its own
local state file — posts 3, 4, and 5 do not share one combined state
file with post 2 or with each other. Instead, each of posts 3–5 reads
post 2's state via a terraform_remote_state data source pointing at post
2's local terraform.tfstate:
# post-3/data.tf
data "terraform_remote_state" "foundation" {
backend = "local"
config = {
path = "${path.module}/../post-2/terraform.tfstate"
}
}
# then, anywhere in post-3's config:
# data.terraform_remote_state.foundation.outputs.vpc_id
# data.terraform_remote_state.foundation.outputs.gateway_subnet_id
# data.terraform_remote_state.foundation.outputs.transit_gateway_id
Why a reference instead of one shared state file for everything: terraform destroy operates on whatever's in the state file it's pointed at. One
combined state file across all five posts means running destroy from
inside, say, post-4/ would put post 2's VPC and PowerVS
workspace on the chopping block too — exactly the blast-radius problem this
series' whole "small, focused diffs" premise is trying to avoid. Separate
state files, cross-referenced by data source, means each post can be applied
or destroyed independently without touching what the others depend on.
Prerequisites #
miseinstalled — each post'smise.tomlpins its own Terraform version, so you don't need Terraform installed separately;mise installhandles it per-directoryfnoxinstalled and configured with a secret namedibmcloud_api_key— the repo-rootfnox.tomlis the one vault every post'smise run plan/applypulls from- An IBM Cloud resource group ID (
ibmcloud resource groups) - Your PowerVS entitlement/quota already approved for the target zone — a manual step in the IBM Cloud console/support-ticket process; Terraform can't do this part for you
Running any single post #
Every post directory follows the same pattern. From inside the post's directory:
cd post-2 # or post-3, post-4, post-5
cp terraform.tfvars.example terraform.tfvars
# edit terraform.tfvars — see that post's README for which variables it needs
mise install # installs the pinned terraform version for this post
mise run plan # review what will be created — read this output carefully
mise run apply # actually create it (billable resources)
Posts 3–5 need post 2 applied first (they read its state — see above).
Beyond that, check each post's own README.md for what it specifically
needs: post 3 wants your on-prem peer gateway details, post 4 wants your VPN
client's expected CIDR, post 5 wants a Tailscale API key and tailnet ID.
Tearing down #
Tear down in reverse order — posts 3, 4, and 5 (in any order relative to each other) before post 2:
cd post-5 && mise run destroy
cd post-4 && mise run destroy
cd post-3 && mise run destroy
cd post-2 && mise run destroy
Destroying post 2 first leaves posts 3–5's terraform_remote_state lookups
pointing at a state file that no longer describes real infrastructure —
their own resources (VPN gateways, servers, VSIs) would still exist and
still cost money, just with no clean Terraform path back to them.
Terraform as a learning tool #
Since this series doubles as a Terraform learning tool, each file's header
comment calls out why a particular pattern was used, not just what it
does — e.g. why address_prefix_management = "manual" in vpc.tf, why
for_each over a map in security_groups.tf instead of four separate
resource blocks. Later posts introduce a few new patterns for the first
time (modules, terraform_remote_state) once there's enough repeated
structure to justify them.
Known rough edges to verify against current docs #
Terraform provider arguments for PowerVS and load-balancer resources
(ibm_resource_instance service/plan names, ibm_pi_network arguments,
ibm_is_lb route-mode arguments) have moved before. Before you apply in
any post, it's worth a quick check against the IBM Cloud provider registry
docs for
the specific resources that post uses — called out in the blog posts
themselves as an "APIs evolve, always verify" teaching moment rather than
glossed over.