professional-service/examples/iaas-image-upload/040-server.tf
Sven Schmidt 89f18bbba0
All checks were successful
Default CI / Check for Open TODOs (push) Successful in 36s
Mirror to Public GitHub / Sync Repository (push) Successful in 51s
Default CI / Secret Scanner (TruffleHog) (push) Successful in 55s
Default CI / Pre-Commit Hooks (push) Successful in 1m50s
examples/iaas-image-upload (#34)
## Summary

- Adds a new self-contained Terraform example under `examples/iaas-image-upload/`
- Demonstrates how to upload a custom VM image to STACKIT using the `stackit_image` resource
- Follows existing repository conventions (numbered file prefixes, license headers, section dividers, `examples/terraform.tfvars.example` subfolder)

## What's included

- `00-provider.tf` — stackitcloud/stackit >= 0.99.0
- `01-variables.tf` — all variables with descriptions, defaults, and input validation
- `02-image.tf` — `stackit_image` resource with UEFI/Secure Boot config and labels
- `03-outputs.tf` — image ID, name, scope, and checksum
- `examples/terraform.tfvars.example` — safe-to-commit placeholder values
- `README.md` — prerequisites, deployment steps, validation, cleanup
- `.gitignore` — excludes `images/`, `keys/`, and `*.tfvars`

## Notes

- Supported disk formats restricted to `qcow2`, `raw`, `iso`
- Image files are gitignored via `images/*` — users place their file locally before `terraform apply`
- `terraform validate` and `pre-commit run --all-files` both pass clean

Co-authored-by: Mauritz Uphoff <mauritz.uphoff@stackit.cloud>
Reviewed-on: #34
Reviewed-by: Mauritz_Uphoff <mauritz.uphoff@digits.schwarz>
Co-authored-by: Sven Schmidt <sven.schmidt@digits.schwarz>
Co-committed-by: Sven Schmidt <sven.schmidt@digits.schwarz>
2026-06-26 07:08:32 +00:00

51 lines
1.7 KiB
HCL

# Copyright 2026 Schwarz Digits Cloud GmbH & Co. KG
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Example: boot a server from the uploaded custom image.
# The image_id is referenced directly from the stackit_image resource above.
resource "stackit_network" "main" {
project_id = var.project_id
name = "${var.server_name}-network"
ipv4_prefix_length = tonumber(split("/", var.network_cidr)[1])
}
resource "stackit_network_interface" "server" {
project_id = var.project_id
network_id = stackit_network.main.network_id
name = "${var.server_name}-nic"
}
resource "stackit_key_pair" "server" {
name = var.keypair_name
public_key = chomp(var.ssh_public_key)
}
resource "stackit_server" "from_custom_image" {
project_id = var.project_id
name = var.server_name
machine_type = var.machine_type
availability_zone = var.availability_zone
keypair_name = stackit_key_pair.server.name
boot_volume = {
source_type = "image"
source_id = stackit_image.custom_image.image_id
size = var.boot_volume_size_gb
}
network_interfaces = [stackit_network_interface.server.network_interface_id]
labels = var.labels
}