Skip to content

Commit

Permalink
feat(08-input-vars-locals-outputs): add files
Browse files Browse the repository at this point in the history
  • Loading branch information
lauromueller committed Mar 4, 2024
1 parent 857b01e commit cc3137b
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 0 deletions.
45 changes: 45 additions & 0 deletions 08-input-vars-locals-outputs/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions 08-input-vars-locals-outputs/compute.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"] # Owner is Canonical

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-*-22.04-amd64-server-*"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

# resource "aws_instance" "compute" {
# ami = data.aws_ami.ubuntu.id
# instance_type = var.ec2_instance_type

# root_block_device {
# delete_on_termination = true
# volume_size = var.ec2_volume_config.size
# volume_type = var.ec2_volume_config.type
# }

# tags = merge(local.common_tags, var.additional_tags)
# }
10 changes: 10 additions & 0 deletions 08-input-vars-locals-outputs/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
output "s3_bucket_name" {
value = aws_s3_bucket.project_bucket.bucket
sensitive = true
description = "The name of the S3 bucket"
}

output "sensitive_var" {
sensitive = true
value = var.my_sensitive_value
}
3 changes: 3 additions & 0 deletions 08-input-vars-locals-outputs/override.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
additional_tags = {
ValuesFrom = "override.tfvars"
}
18 changes: 18 additions & 0 deletions 08-input-vars-locals-outputs/provider.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = "~> 1.7.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}

random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}

provider "aws" {
region = "eu-west-1"
}
9 changes: 9 additions & 0 deletions 08-input-vars-locals-outputs/s3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "random_id" "project_bucket_suffix" {
byte_length = 4
}

resource "aws_s3_bucket" "project_bucket" {
bucket = "${local.project}-${random_id.project_bucket_suffix.hex}"

tags = merge(local.common_tags, var.additional_tags)
}
16 changes: 16 additions & 0 deletions 08-input-vars-locals-outputs/shared-locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
locals {
project = "08-input-vars-locals-outputs"
project_owner = "terraform-course"
cost_center = "1234"
managed_by = "Terraform"
}

locals {
common_tags = {
project = local.project
project_owner = local.project_owner
cost_center = local.cost_center
managed_by = local.managed_by
sensitive_tag = var.my_sensitive_value
}
}
10 changes: 10 additions & 0 deletions 08-input-vars-locals-outputs/terraform.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ec2_instance_type = "t2.micro"

ec2_volume_config = {
size = 10
type = "gp2"
}

additional_tags = {
ValuesFrom = "terraform.tfvars"
}
32 changes: 32 additions & 0 deletions 08-input-vars-locals-outputs/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "ec2_instance_type" {
type = string
description = "The type of the managed EC2 instances."

validation {
condition = contains(["t2.micro", "t3.micro"], var.ec2_instance_type)
error_message = "Only supports t2.micro and t3.micro"
}
}

variable "ec2_volume_config" {
type = object({
size = number
type = string
})
description = "The size and type of the root block volume for EC2 instances."

default = {
size = 10
type = "gp3"
}
}

variable "additional_tags" {
type = map(string)
default = {}
}

variable "my_sensitive_value" {
type = string
sensitive = true
}

0 comments on commit cc3137b

Please sign in to comment.