This template sets up an AWS CloudHSM v2 cluster within a new VPC and two subnets across different availability zones.

Terraform Template

data "aws_availability_zones" "available" {
}

resource "aws_cloudhsm_v2_cluster" "cloudhsm_v2_cluster" {
  hsm_type = "hsm1.medium"
  subnet_ids = aws_subnet.cloudhsm_v2_subnets[*].id

  tags = {
    Name = "example-aws_cloudhsm_v2_cluster"
  }
}

resource "aws_subnet" "cloudhsm_v2_subnets" {
  availability_zone = element(data.aws_availability_zones.available.names, count.index)
  cidr_block = element(var.subnets, count.index)
  count = 2
  map_public_ip_on_launch = false

  tags = {
    Name = "example-aws_cloudhsm_v2_cluster"
  }
  vpc_id = aws_vpc.cloudhsm_v2_vpc.id
}

resource "aws_vpc" "cloudhsm_v2_vpc" {
  cidr_block = "10.0.0.0/16"

  tags = {
    Name = "example-aws_cloudhsm_v2_cluster"
  }
}