Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Local .terraform directories
**/.terraform/*
**/.terraform.lock.hcl

# .tfstate files
*.tfstate
Expand Down
37 changes: 37 additions & 0 deletions .tflint.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
rule "terraform_unused_declarations" {
enabled = true
}

rule "terraform_deprecated_index" {
enabled = true
}

rule "terraform_documented_variables" {
enabled = true
}

rule "terraform_typed_variables" {
enabled = true
}

rule "terraform_module_pinned_source" {
enabled = true
}

rule "terraform_naming_convention" {
enabled = true
}

rule "terraform_unused_required_providers" {
enabled = true
}

rule "terraform_required_version" {
enabled = true
}

plugin "aws" {
enabled = true
source = "github.com/terraform-linters/tflint-ruleset-aws"
version = "0.12.0"
}
24 changes: 24 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
locals {

create_new_ssh_key = var.create_ssh_keypair && (length(var.ssh_public_key) > 0)

}

# Generate SSH keypair
resource "tls_private_key" "generated_ssh_key_pair" {
count = local.create_new_ssh_key ? 1 : 0
algorithm = "RSA"
}

resource "aws_key_pair" "ssh" {
count = var.create_ssh_keypair ? 1 : 0

key_name_prefix = var.name
public_key = try(tls_private_key.generated_ssh_key_pair[0].public_key_openssh, var.ssh_public_key)

tags = merge(
{ "Name" = var.name },
var.tags,
var.key_pair_tags,
)
}
Empty file added outputs.tf
Empty file.
62 changes: 62 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
variable "name" {
description = "Name to be used on all the resources as identifier"
type = string
default = ""
}

variable "cloud_provider" {
description = "The cloud provider this module will be used against."
type = string
default = "aws"
validation {
condition = contains(["aws"], var.cloud_provider)
error_message = "Allowed values for input_parameter are \"aws\"."
}
}

variable "create_ssh_keypair" {
description = "Controls if SSH Keypair should be created."
type = bool
default = true
}

variable "ssh_public_key" {
description = "If \"create_ssh_keypair\" is set to true, use this variable if you want to use a pre-existing SSH Public Key. If not specified a new one will be created."
type = string
default = ""
validation {
condition = length(var.ssh_public_key) == 0 || can(regex("(AAAAB3NzaC1yc2EA|AAAAC3NzaC1lZDI1NTE5)", var.ssh_public_key))
error_message = "An invalid SSH key has been specified in \"var.ssh_public_key\". Please check https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html for instructions."
}
}

variable "ssh_key_pair" {
description = "If \"create_ssh_keypair\" is set to false, use this variable to specify a pre-existing cloud key-pair. Mutually exclusive with \"create_ssh_keypair\"."
type = string
default = ""
}

variable "tags" {
description = "A map of tags to add to all resources"
type = map(string)
default = {}
}

variable "key_pair_tags" {
description = "Additional tags for the Key Pair"
type = map(string)
default = {}
}

variable "cloudinit_packages" {
description = "A list of packages required by cloud-init to perform the software launch."
type = list(string)
default = [
"awscli",
"jq",
"unzip",
"python3-pip",
"python3-venv",
"python3-docker",
]
}
10 changes: 10 additions & 0 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.63"
}
}
}