generated from terraform-modules/template_aws_submodules
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
59 deletions.
There are no files selected for viewing
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
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 |
|---|---|---|
| @@ -1,36 +1,93 @@ | ||
| locals { | ||
| keypair_name = format("ec2-ssh-%v%v", local._prefixes["eks"], var.cluster_name) | ||
| timestamp = formatdate("YYYYMMDD", time_static.timestamp.rfc3339) | ||
| } | ||
|
|
||
| # two-step process to create | ||
| # terraform apply -target=null_resource.generate_keypair | ||
| # terraform apply | ||
| # when done, add to git | ||
| # cd setup | ||
| # echo inf-ec2-keypair >> .gitignore | ||
| # git-secret add inf-ec2-keypair | ||
| # git-secret hide | ||
| # git add inf-ec2-keypair.{pub,secret} | ||
| # git commit -m'add ec2-keypair: inf-ec2-keypair' inf-ec2-keypair.{pub,secret} .gitignore | ||
|
|
||
| # inf-keypair | ||
| resource "null_resource" "generate_keypair" { | ||
| provisioner "local-exec" { | ||
| command = "test -d setup || mkdir setup" | ||
| } | ||
| provisioner "local-exec" { | ||
| working_dir = "./setup" | ||
| command = "ssh-keygen -f ${local.keypair_name} -N '' -t rsa -b 2048 -C '${local.keypair_name}@${var.cluster_name}.${local.vpc_domain_name}'" | ||
| } | ||
| } | ||
| resource "time_static" "timestamp" {} | ||
|
|
||
| ## # two-step process to create | ||
| ## # terraform apply -target=null_resource.generate_keypair | ||
| ## # terraform apply | ||
| ## # when done, add to git | ||
| ## # cd setup | ||
| ## # echo inf-ec2-keypair >> .gitignore | ||
| ## # git-secret add inf-ec2-keypair | ||
| ## # git-secret hide | ||
| ## # git add inf-ec2-keypair.{pub,secret} | ||
| ## # git commit -m'add ec2-keypair: inf-ec2-keypair' inf-ec2-keypair.{pub,secret} .gitignore | ||
| ## | ||
| ## # inf-keypair | ||
| ## resource "null_resource" "generate_keypair" { | ||
| ## provisioner "local-exec" { | ||
| ## command = "test -d setup || mkdir setup" | ||
| ## } | ||
| ## provisioner "local-exec" { | ||
| ## working_dir = "./setup" | ||
| ## command = "ssh-keygen -f ${local.keypair_name} -N '' -t rsa -b 2048 -C '${local.keypair_name}@${var.cluster_name}.${local.vpc_domain_name}'" | ||
| ## } | ||
| ## } | ||
| ## | ||
| ## resource "aws_key_pair" "cluster_keypair" { | ||
| ## key_name = local.keypair_name | ||
| ## public_key = file("setup/${local.keypair_name}.pub") | ||
| ## depends_on = [null_resource.generate_keypair] | ||
| ## } | ||
| ## | ||
| ## output "cluster_keypair" { | ||
| ## description = "EC2 keypair for EKS Cluster" | ||
| ## value = aws_key_pair.cluster_keypair.key_name | ||
| ## } | ||
|
|
||
| module "key_pair" { | ||
| source = "terraform-aws-modules/key-pair/aws" | ||
|
|
||
| key_name = local.keypair_name | ||
| create_private_key = true | ||
|
|
||
| resource "aws_key_pair" "cluster_keypair" { | ||
| key_name = local.keypair_name | ||
| public_key = file("setup/${local.keypair_name}.pub") | ||
| depends_on = [null_resource.generate_keypair] | ||
| tags = merge( | ||
| var.tags, | ||
| { | ||
| "Name" = local.keypair_name | ||
| "launch_time" = time_static.timestamp.rfc3339 | ||
| "launch_vpc" = local.vpc_label | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| output "cluster_keypair" { | ||
| description = "EC2 keypair for EKS Cluster" | ||
| value = aws_key_pair.cluster_keypair.key_name | ||
| description = "EC2 Key Pair Name" | ||
| value = module.key_pair.key_pair_name | ||
| } | ||
|
|
||
| resource "local_sensitive_file" "ssh_private_key" { | ||
| content = format("%v\n", module.key_pair.private_key_openssh) | ||
| directory_permission = "0700" | ||
| file_permission = "0600" | ||
| filename = format("%v/%v", null_resource.setup_directory.triggers.directory, null_resource.setup_directory.triggers.keypair_name) | ||
| } | ||
|
|
||
| resource "local_sensitive_file" "ssh_public_key" { | ||
| content = format("%v\n", module.key_pair.public_key_openssh) | ||
| directory_permission = "0700" | ||
| file_permission = "0600" | ||
| filename = format("%v/%v.pub", null_resource.setup_directory.triggers.directory, null_resource.setup_directory.triggers.keypair_name) | ||
| } | ||
|
|
||
| resource "local_file" "gitignore" { | ||
| content = format("%v\n", basename(local_sensitive_file.ssh_private_key.filename)) | ||
| directory_permission = "0700" | ||
| file_permission = "0600" | ||
| filename = format("%v/%v", null_resource.setup_directory.triggers.directory, ".gitignore") | ||
| } | ||
|
|
||
| resource "local_sensitive_file" "gitsecret_script" { | ||
| content = templatefile("${path.module}/templates/manage-git-secret.sh.tpl", { | ||
| ssh_key_directory = null_resource.setup_directory.triggers.directory | ||
| ssh_private_key_filename = local_sensitive_file.ssh_private_key[0].filename | ||
| ssh_public_key_filename = local_sensitive_file.ssh_public_key[0].filename | ||
| }) | ||
| directory_permission = "0700" | ||
| file_permission = "0755" | ||
| filename = format("%v/%v", null_resource.setup_directory.triggers.directory, "manage-git-secret.sh") | ||
| } | ||
|
|
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
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
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
9 changes: 0 additions & 9 deletions
9
examples/full-cluster-tf-upgrade/1.25/variables.vpc.auto.tfvars.make-link
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
examples/full-cluster-tf-upgrade/1.25/variables.vpc.tf.make-link
This file was deleted.
Oops, something went wrong.