Simplified main. Added AMI module.

This commit is contained in:
Curtis
2021-11-26 16:06:19 -05:00
parent 51c44e705b
commit 358a1c5f81
14 changed files with 390 additions and 84 deletions
+58
View File
@@ -0,0 +1,58 @@
locals {
amis = {
amzn2 = {
owner-id = "137112412989"
name = "amzn2-ami-hvm-2*x86_64-gp2"
},
ubuntu = {
owner-id = "099720109477"
name = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"
},
centos7 = {
owner-id = "125523088429"
name = "CentOS 7.*x86_64"
},
centos8 = {
owner-id = "125523088429"
name = "CentOS 8.*x86_64"
},
arch = {
owner-id = "093273469852"
name = "arch-linux-lts-hvm*x86_64-ebs"
},
rhel7 = {
owner-id = "309956199498"
name = "RHEL-7.*HVM*x86_64*GP2"
},
rhel8 = {
owner-id = "309956199498"
name = "RHEL-8.*HVM*x86_64*GP2"
}
}
}
data "aws_ami" "amis" {
for_each = local.amis
most_recent = true
owners = [each.value.owner-id]
filter {
name = "name"
values = [each.value.name]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
filter {
name = "architecture"
values = ["x86_64"]
}
filter {
name = "root-device-type"
values = ["ebs"]
}
}
+3
View File
@@ -0,0 +1,3 @@
output "amis" {
value = tomap({ for type, ami in data.aws_ami.amis : type => ami.id })
}
@@ -0,0 +1,9 @@
data "template_file" "user-datas" {
template = file("${var.cloud-init-template}")
vars = {
admin-passwd = "${var.root-admin-passwd}"
admin-pub-key = "${var.root-admin-pub-key}"
hostname = "${var.hostname-prefix}-${count.index}"
}
count = var.num
}
@@ -0,0 +1,3 @@
output "user-datas" {
value = data.template_file.user-datas
}
@@ -0,0 +1,22 @@
variable "cloud-init-template" {
default = "../../cloud_init.cfg"
description = "The path to the cloud-init config template."
type = string
}
variable "hostname-prefix" {
description = "This prefix wil be applied as a prefix for the hostnames."
}
variable "num" {
description = "The number of user-datas to create with these parameters."
}
variable "root-admin-passwd" {
description = "This value will be substituted for any occurence of 'admin-password' in the cloud-init config template."
}
variable "root-admin-pub-key" {
description = "This value will be substituted for any occurence of 'admin-pub-key' in the cloud-init config template."
}
-4
View File
@@ -8,10 +8,6 @@ terraform {
}
}
provider "libvirt" {
uri = var.libvirt-connection-url
}
resource "libvirt_volume" "node-images" {
name = "${var.name-prefix}-${count.index}"
pool = var.pool-name