generated from opsd-io/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* code * docs * r53-vars * r53-records * docs * docs outputs * use data.aws_ec2_instance_type
- Loading branch information
Showing
12 changed files
with
422 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
data "aws_ami" "debian11" { | ||
most_recent = true | ||
owners = ["amazon"] | ||
|
||
filter { | ||
name = "name" | ||
values = ["debian-12-amd64-*"] | ||
} | ||
} | ||
|
||
module "network" { | ||
source = "github.com/opsd-io/terraform-module-aws-network" | ||
|
||
vpc_name = "test-vpc" | ||
cidr_block = "10.100.0.0/16" | ||
|
||
public_subnet_groups = { | ||
"public1" = { | ||
availability_zones = { | ||
"a" = { cidr_block = "10.100.1.0/24" } | ||
"b" = { cidr_block = "10.100.2.0/24" } | ||
"c" = { cidr_block = "10.100.3.0/24" } | ||
} | ||
} | ||
} | ||
} | ||
|
||
resource "aws_key_pair" "me" { | ||
public_key = file("~/.ssh/id_rsa.pub") | ||
} | ||
|
||
module "vm_bastion" { | ||
source = "github.com/opsd-io/terraform-module-aws-instance" | ||
|
||
name = "bastion" | ||
ami_id = data.aws_ami.debian11.id | ||
instance_type = "t2.micro" | ||
subnet_id = module.network.public_subnet_groups["public1"]["a"].id | ||
key_name = aws_key_pair.me.key_name | ||
} | ||
|
||
output "network" { | ||
value = module.network | ||
} | ||
|
||
output "vm_bastion" { | ||
value = module.vm_bastion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Make sure we're using working version (from local directory, not git). | ||
|
||
module "vm_bastion" { | ||
source = "./../.." | ||
} | ||
|
||
module "network" { | ||
source = "/Users/stawi/work/opsd/terraform-module-aws-network" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
provider "aws" { | ||
region = "eu-central-1" | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,97 @@ | ||
# Terraform code goes here | ||
terraform { | ||
required_version = ">= 1.3.1" | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
} | ||
} | ||
|
||
data "aws_ec2_instance_type" "main" { | ||
instance_type = var.instance_type | ||
} | ||
|
||
resource "aws_instance" "main" { | ||
ami = var.ami_id | ||
instance_type = var.instance_type | ||
ebs_optimized = var.ebs_optimized == null ? null : (var.ebs_optimized && data.aws_ec2_instance_type.main.ebs_optimized_support == "supported") | ||
|
||
user_data = var.user_data | ||
user_data_base64 = var.user_data_base64 | ||
user_data_replace_on_change = true # !!!! | ||
|
||
associate_public_ip_address = var.associate_public_ip_address | ||
iam_instance_profile = var.iam_instance_profile | ||
key_name = var.key_name | ||
monitoring = var.monitoring | ||
source_dest_check = var.source_dest_check | ||
subnet_id = var.subnet_id | ||
vpc_security_group_ids = length(var.security_group_ids) > 0 ? var.security_group_ids : null | ||
|
||
# launch_template {} | ||
|
||
private_dns_name_options { | ||
hostname_type = var.hostname_type | ||
enable_resource_name_dns_a_record = var.enable_resource_name_dns_a_record | ||
enable_resource_name_dns_aaaa_record = var.enable_resource_name_dns_aaaa_record | ||
} | ||
|
||
root_block_device { | ||
delete_on_termination = true | ||
encrypted = var.root_volume_encryption == null ? null : (var.root_volume_encryption && data.aws_ec2_instance_type.main.ebs_encryption_support == "supported") | ||
volume_type = var.root_volume_type | ||
volume_size = var.root_volume_size | ||
iops = var.root_iops | ||
tags = merge(var.common_tags, { | ||
Name = "${var.name}-root" | ||
}) | ||
} | ||
|
||
# ebs_block_device {} | ||
|
||
# ephemeral_block_device {} | ||
|
||
tags = merge(var.common_tags, { | ||
Name = var.name | ||
}) | ||
|
||
} | ||
|
||
## Route53 records. | ||
|
||
resource "aws_route53_record" "private_ip" { | ||
count = var.private_zone_id != null ? 1 : 0 | ||
zone_id = var.private_zone_id | ||
name = coalesce(var.private_zone_record_name, var.name) | ||
type = "A" | ||
ttl = var.private_zone_record_ttl | ||
records = [aws_instance.main.private_ip] | ||
} | ||
|
||
resource "aws_route53_record" "public_ip" { | ||
count = var.public_zone_id != null ? 1 : 0 | ||
zone_id = var.public_zone_id | ||
name = coalesce(var.public_zone_record_name, var.name) | ||
type = "A" | ||
ttl = var.public_zone_record_ttl | ||
records = [aws_instance.main.public_ip] | ||
} | ||
|
||
resource "aws_route53_record" "private_cnames" { | ||
for_each = toset(var.private_zone_id != null ? var.private_zone_record_cnames : []) | ||
zone_id = var.private_zone_id | ||
name = each.value | ||
type = "CNAME" | ||
ttl = var.private_zone_record_ttl | ||
records = [aws_route53_record.private_ip[0].fqdn] | ||
} | ||
|
||
resource "aws_route53_record" "public_cnames" { | ||
for_each = toset(var.public_zone_id != null ? var.public_zone_record_cnames : []) | ||
zone_id = var.public_zone_id | ||
name = each.value | ||
type = "CNAME" | ||
ttl = var.public_zone_record_ttl | ||
records = [aws_route53_record.public_ip[0].fqdn] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,28 @@ | ||
# output "variable" { | ||
# description = "output variable description" | ||
# value = variable.main.name | ||
# output "instance" { | ||
# value = aws_instance.main | ||
# } | ||
|
||
output "id" { | ||
description = "The ID of the instance." | ||
value = aws_instance.main.id | ||
} | ||
|
||
output "arn" { | ||
description = "The ARN of the instance." | ||
value = aws_instance.main.arn | ||
} | ||
|
||
output "private_ip" { | ||
description = "The private IP of the instance." | ||
value = aws_instance.main.private_ip | ||
} | ||
|
||
output "public_ip" { | ||
description = "The public IP of the instance." | ||
value = aws_instance.main.public_ip | ||
} | ||
|
||
output "root_volume_id" { | ||
description = "The ID of the root volume." | ||
value = one(aws_instance.main.root_block_device[*].volume_id) | ||
} |
Oops, something went wrong.