Created
March 11, 2020 09:56
-
-
Save ryu1kn/98a995e35b73ec144ce02f6d51a7243a to your computer and use it in GitHub Desktop.
Terraform, instantiate the same module multiple times
This file contains hidden or 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
provider "aws" { | |
region = "ap-southeast-2" | |
} | |
resource "aws_s3_bucket" "my_bucket" { | |
bucket = "test-bucket-whatever-1jfibabl" | |
} | |
module "file_a" { | |
source = "./mod-a" | |
bucket_name = aws_s3_bucket.my_bucket.id | |
file_path = "../foo.txt" | |
} | |
module "file_b" { | |
source = "./mod-a" | |
bucket_name = aws_s3_bucket.my_bucket.id | |
file_path = "../bar.txt" | |
} |
This file contains hidden or 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
export AWS_PROFILE := your-aws-profile | |
auto_approve_target = apply destroy | |
init apply destroy: | |
cd infra && terraform $@ $(if $(filter $@,$(auto_approve_target)),-auto-approve) |
This file contains hidden or 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 should be named as mod-a/main.tf | |
variable "file_path" {} | |
variable "bucket_name" {} | |
locals { | |
path_in_bucket = "foo/${basename(var.file_path)}" | |
} | |
resource "aws_s3_bucket_object" "object" { | |
bucket = var.bucket_name | |
key = local.path_in_bucket | |
source = var.file_path | |
} | |
output "path_in_bucket" { | |
value = local.path_in_bucket | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment