Added aws-ami module.
This commit is contained in:
@@ -12,25 +12,25 @@ terraform {
|
|||||||
# cloud-init
|
# cloud-init
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
# data "template_file" "master-node-user-datas" {
|
data "template_file" "master-node-user-datas" {
|
||||||
# template = file("${path.module}/cloud_init.cfg")
|
template = file("${path.module}/cloud_init.cfg")
|
||||||
# vars = {
|
vars = {
|
||||||
# admin-passwd = "${var.root-admin-passwd}"
|
admin-passwd = "${var.root-admin-passwd}"
|
||||||
# admin-pub-key = "${var.root-admin-pub-key}"
|
admin-pub-key = "${var.root-admin-pub-key}"
|
||||||
# hostname = "${var.vm-name-prefix}-master-${count.index}"
|
hostname = "${var.vm-name-prefix}-master-${count.index}"
|
||||||
# }
|
}
|
||||||
# count = var.master-nodes
|
count = var.master-nodes
|
||||||
# }
|
}
|
||||||
#
|
|
||||||
# data "template_file" "worker-node-user-datas" {
|
data "template_file" "worker-node-user-datas" {
|
||||||
# template = file("${path.module}/cloud_init.cfg")
|
template = file("${path.module}/cloud_init.cfg")
|
||||||
# vars = {
|
vars = {
|
||||||
# admin-passwd = "${var.root-admin-passwd}"
|
admin-passwd = "${var.root-admin-passwd}"
|
||||||
# admin-pub-key = "${var.root-admin-pub-key}"
|
admin-pub-key = "${var.root-admin-pub-key}"
|
||||||
# hostname = "${var.vm-name-prefix}-worker-${count.index}"
|
hostname = "${var.vm-name-prefix}-worker-${count.index}"
|
||||||
# }
|
}
|
||||||
# count = var.worker-nodes
|
count = var.worker-nodes
|
||||||
# }
|
}
|
||||||
|
|
||||||
data "template_file" "amzn2-node-user-datas" {
|
data "template_file" "amzn2-node-user-datas" {
|
||||||
template = file("${path.module}/cloud_init.cfg")
|
template = file("${path.module}/cloud_init.cfg")
|
||||||
@@ -92,6 +92,10 @@ provider "aws" {
|
|||||||
region = "us-east-2"
|
region = "us-east-2"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "aws-amis" {
|
||||||
|
source = "./modules/aws-amis"
|
||||||
|
}
|
||||||
|
|
||||||
module "aws-network" {
|
module "aws-network" {
|
||||||
source = "./modules/aws-network"
|
source = "./modules/aws-network"
|
||||||
name-prefix = var.vm-name-prefix
|
name-prefix = var.vm-name-prefix
|
||||||
@@ -165,6 +169,10 @@ module "centos8-nodes" {
|
|||||||
name-prefix = "${var.vm-name-prefix}-centos8"
|
name-prefix = "${var.vm-name-prefix}-centos8"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "amis" {
|
||||||
|
value = module.aws-amis.amis
|
||||||
|
}
|
||||||
|
|
||||||
# module "master-nodes" {
|
# module "master-nodes" {
|
||||||
# source = "./modules/aws-nodes"
|
# source = "./modules/aws-nodes"
|
||||||
# ami = var.base-image
|
# ami = var.base-image
|
||||||
|
|||||||
@@ -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"]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
output "amis" {
|
||||||
|
value = tomap({ for type, ami in data.aws_ami.amis : type => ami.id })
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user