Skip to content

Instantly share code, notes, and snippets.

@clouditlab
Created April 2, 2023 18:01
Show Gist options
  • Save clouditlab/866ef8b9eca02104c7f076d4befc4e72 to your computer and use it in GitHub Desktop.
Save clouditlab/866ef8b9eca02104c7f076d4befc4e72 to your computer and use it in GitHub Desktop.
Talos using Terraform in AWS
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 3.0"
name = "talos-demo"
cidr = "10.0.0.0/18"
public_subnets = ["10.0.0.0/24"]
azs = ["eu-central-1a"]
}
resource "aws_security_group" "security_group" {
vpc_id = module.vpc.vpc_id
egress {
from_port = 0
to_port = 0
protocol = "-1"
description = "Egress everywhere"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
description = "Ingress everywhere"
cidr_blocks = ["0.0.0.0/0"]
}
}
data "aws_ami" "talos" {
most_recent = true
filter {
name = "name"
values = ["talos-v1.3.5-eu-central-1-amd64"]
}
owners = ["540036508848"]
}
resource "aws_instance" "ec2" {
ami = data.aws_ami.talos.id
instance_type = "t3.small"
subnet_id = module.vpc.public_subnets[0]
private_ip = "10.0.0.5"
associate_public_ip_address = "true"
vpc_security_group_ids = [aws_security_group.security_group.id]
user_data = talos_machine_configuration_controlplane.machineconfig_cp.machine_config
tags = {
Name = "talos-demo"
}
}
output "talos_talosconfig" {
value = talos_client_configuration.talosconfig.talos_config
sensitive = true
}
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
}
talos = {
source = "siderolabs/talos"
version = "0.1.1"
}
}
required_version = ">= 1.0"
}
resource "talos_machine_secrets" "machine_secrets" {
}
resource "talos_machine_configuration_controlplane" "machineconfig_cp" {
cluster_name = "talos-demo"
cluster_endpoint = "https://10.0.0.5:6443"
machine_secrets = talos_machine_secrets.machine_secrets.machine_secrets
config_patches = [
file("${path.module}/talos-patch.yaml")
]
docs_enabled = false
examples_enabled = false
kubernetes_version = "1.24.3"
talos_version = "v1.3.5"
}
resource "talos_client_configuration" "talosconfig" {
cluster_name = "talos-demo"
machine_secrets = talos_machine_secrets.machine_secrets.machine_secrets
endpoints = [aws_instance.ec2.public_ip]
nodes = ["10.0.0.5"]
}
machine:
type: init
cluster:
allowSchedulingOnControlPlanes: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment