forked from lm-academy/terraform-course
-
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.
feat(08-input-vars-locals-outputs): add files
- Loading branch information
1 parent
857b01e
commit cc3137b
Showing
9 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -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) | ||
# } |
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,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 | ||
} |
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,3 @@ | ||
additional_tags = { | ||
ValuesFrom = "override.tfvars" | ||
} |
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,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" | ||
} |
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 @@ | ||
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) | ||
} |
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,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 | ||
} | ||
} |
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,10 @@ | ||
ec2_instance_type = "t2.micro" | ||
|
||
ec2_volume_config = { | ||
size = 10 | ||
type = "gp2" | ||
} | ||
|
||
additional_tags = { | ||
ValuesFrom = "terraform.tfvars" | ||
} |
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,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 | ||
} |