provider "aws" { region = "us-west-2" # XXX make this configurable } resource "random_pet" "name" {} # https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws/latest module "s3_bucket" { source = "terraform-aws-modules/s3-bucket/aws" bucket = "nextcloud-${random_pet.name.id}" acl = "private" versioning = { enabled = false } server_side_encryption_configuration = { rule = { apply_server_side_encryption_by_default = { sse_algorithm = "AES256" } bucket_key_enabled = true } } } # https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws/latest module "vpc" { source = "terraform-aws-modules/vpc/aws" name = "nextcloud-vpc" cidr = "10.69.0.0/16" azs = ["us-west-2a"] # private_subnets = ["10.69.101.0/24"] private_subnets = [] public_subnets = ["10.69.1.0/24"] enable_nat_gateway = false enable_vpn_gateway = false } resource "tls_private_key" "n" { algorithm = "RSA" rsa_bits = 4096 } resource "aws_key_pair" "n" { key_name = "nextcloud" public_key = tls_private_key.n.public_key_openssh } resource "local_file" "aws_key" { content = tls_private_key.n.private_key_pem filename = "privkey.pem" } resource "aws_instance" "nextcloud" { ami = "ami-078278691222aee06" instance_type = "t4g.small" subnet_id = module.vpc.public_subnets.0 key_name = aws_key_pair.n.key_name iam_instance_profile = aws_iam_instance_profile.nextcloud.name # associate_public_ip_address = false vpc_security_group_ids = [ module.nextcloud_sg.security_group_id ] user_data = <