Skip to content

Commit

Permalink
feat: added key-pair and spot instance testing
Browse files Browse the repository at this point in the history
  • Loading branch information
theprashantyadav committed Jun 21, 2023
1 parent 887e684 commit 00b23c4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
3 changes: 3 additions & 0 deletions _example/basic_example/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ data "aws_iam_policy_document" "iam-policy" {
}
}

####----------------------------------------------------------------------------------
## Terraform module to create instance module on AWS.
####----------------------------------------------------------------------------------
module "ec2" {
source = "./../../"
name = "ec2"
Expand Down
4 changes: 3 additions & 1 deletion _example/ebs_mount/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ data "aws_iam_policy_document" "iam-policy" {
}
}


####----------------------------------------------------------------------------------
## Terraform module to create ec2 instance module on AWS.
####----------------------------------------------------------------------------------
module "ec2" {
source = "./../../"
name = "ec2"
Expand Down
6 changes: 6 additions & 0 deletions _example/spot_instance/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ module "public_subnets" {
ipv6_cidr_block = module.vpc.ipv6_cidr_block
}

####----------------------------------------------------------------------------------
## Terraform module to create IAm role resource on AWS.
####----------------------------------------------------------------------------------
module "iam-role" {
source = "clouddrove/iam-role/aws"
version = "1.3.0"
Expand Down Expand Up @@ -75,6 +78,9 @@ data "aws_iam_policy_document" "iam-policy" {
}
}

####----------------------------------------------------------------------------------
## Terraform module to create spot instance module on AWS.
####----------------------------------------------------------------------------------
module "spot-ec2" {
source = "./../../"
name = "ec2"
Expand Down
47 changes: 24 additions & 23 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Managed By : CloudDrove
# Description : This Script is used to create EC2, EIP, EBS VOLUME, and VOLUME ATTACHMENT.
# Copyright @ CloudDrove. All Right Reserved.

#Module : Label
#Description : This terraform module is designed to generate consistent label names and
# tags for resources. You can use terraform-labels to implement a strict
# naming convention.
##----------------------------------------------------------------------------------
## Labels module callled that will be used for naming and tags.
##----------------------------------------------------------------------------------
module "labels" {
source = "clouddrove/labels/aws"
version = "1.3.0"
Expand Down Expand Up @@ -161,11 +156,9 @@ data "aws_iam_policy_document" "kms" {

}



#Module : EC2
#Description : Terraform module to create an EC2 resource on AWS with Elastic IP Addresses
# and Elastic Block Store.
##----------------------------------------------------------------------------------
## Below Terraform module to create an EC2 resource on AWS with Elastic IP Addresses and Elastic Block Store.
##----------------------------------------------------------------------------------
#tfsec:ignore:aws-ec2-enforce-http-token-imds
resource "aws_instance" "default" {
count = var.instance_enabled == true ? var.instance_count : 0
Expand Down Expand Up @@ -256,8 +249,9 @@ resource "aws_instance" "default" {
}
}

#Module : EIP
#Description : Provides an Elastic IP resource.
##----------------------------------------------------------------------------------
## Provides an Elastic IP resource..
##----------------------------------------------------------------------------------
resource "aws_eip" "default" {
count = var.instance_enabled == true && var.assign_eip_address == true ? var.instance_count : 0

Expand All @@ -272,8 +266,9 @@ resource "aws_eip" "default" {
)
}

#Module : EBS VOLUME
#Description : Manages a single EBS volume.
##----------------------------------------------------------------------------------
## Manages a single EBS volume.
##----------------------------------------------------------------------------------
resource "aws_ebs_volume" "default" {
count = var.instance_enabled == true && var.ebs_volume_enabled == true ? var.instance_count : 0

Expand All @@ -291,8 +286,9 @@ resource "aws_ebs_volume" "default" {
)
}

#Module : VOLUME ATTACHMENT
#Description : Provides an AWS EBS Volume Attachment as a top level resource, to attach and detach volumes from AWS Instances.
##----------------------------------------------------------------------------------
## Provides an AWS EBS Volume Attachment as a top level resource, to attach and detach volumes from AWS Instances.
##----------------------------------------------------------------------------------
resource "aws_volume_attachment" "default" {
count = var.instance_enabled == true && var.ebs_volume_enabled == true ? var.instance_count : 0

Expand All @@ -301,16 +297,18 @@ resource "aws_volume_attachment" "default" {
instance_id = element(aws_instance.default.*.id, count.index)
}

#Module : IAM INSTANCE PROFILE
#Description : Provides an IAM instance profile.
##----------------------------------------------------------------------------------
## Provides an IAM instance profile.
##----------------------------------------------------------------------------------
resource "aws_iam_instance_profile" "default" {
count = var.instance_enabled == true && var.instance_profile_enabled ? 1 : 0
name = format("%s%sinstance-profile", module.labels.id, var.delimiter)
role = var.iam_instance_profile
}

#Module : ROUTE53
#Description : Provides a Route53 record resource.
##----------------------------------------------------------------------------------
## Below resource will create ROUTE-53 resource for memcached.
##----------------------------------------------------------------------------------
resource "aws_route53_record" "default" {
count = var.instance_enabled == true && var.dns_enabled ? var.instance_count : 0
zone_id = var.dns_zone_id
Expand All @@ -320,6 +318,9 @@ resource "aws_route53_record" "default" {
records = [element(aws_instance.default.*.private_dns, count.index)]
}

##----------------------------------------------------------------------------------
## Below Provides an EC2 Spot Instance Request resource. This allows instances to be requested on the spot market..
##----------------------------------------------------------------------------------
resource "aws_spot_instance_request" "default" {
count = var.spot_instance_enabled == true ? var.spot_instance_count : 0

Expand Down

0 comments on commit 00b23c4

Please sign in to comment.