-
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.
- Loading branch information
Showing
2 changed files
with
74 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,41 @@ | ||
# terraform-module-remote-exec-template | ||
Terraform module to render a template, scp it to a bastion but NOT execute the script | ||
|
||
Inputs - Required: | ||
|
||
- `template_name` - Relative path and file name to the template file to render | ||
- `template_vars` - Map of variables which will be substituted into the template | ||
- `rendered_file_name` - Name of the rendered template file which will be copied onto the vm | ||
- `host` - IP address or DNS resolveable hostname to the bastion/taget vm | ||
- `ssh_private_key` - SSH Private Key File | ||
|
||
|
||
Inputs - Optional: | ||
|
||
- `bastion_user_name` - default = "ubuntu", Name of the user on the bastion/target vm to be used for ssh | ||
- `rendered_file_destination` - default = "/home/ubuntu", Absolute folder of where to copy the rendered file to | ||
|
||
Outputs: | ||
|
||
- `rendered_file_contents` - Outputs the contents of the rendered file | ||
- `rendered_file_location` - Path to the folder and rendered file name | ||
|
||
|
||
Example Usage: | ||
|
||
```hcl | ||
module "stuff" { | ||
source = "github.com/cweibel/terraform-module-remote-exec-template.git?ref=0.0.1" | ||
template_name = "templates/configure-mgmt-bosh-rds.tpl" | ||
template_vars = { | ||
pickles = "mypickles" | ||
} | ||
rendered_file_name = "hijason.sh" | ||
host = module.bastion.box-bastion-public | ||
ssh_private_key = file(var.aws_key_file) | ||
} | ||
output "stuff" {value = module.stuff.rendered_file_contents} | ||
``` |
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,35 @@ | ||
|
||
variable template_name {} # Relative path and file name to the template file to render | ||
variable template_vars {} # Map of variables which will be substituted into the template | ||
variable rendered_file_name {} # Name of the rendered template file which will be copied onto the vm | ||
variable host {} # IP address or DNS resolveable hostname to the bastion/taget vm | ||
variable ssh_private_key {} # SSH Private Key File | ||
|
||
variable bastion_user_name {default = "ubuntu"} # Name of the user on the bastion/target vm to be used for ssh | ||
variable rendered_file_destination {default = "/home/ubuntu"} # Absolute folder name of where to copy the rendered file to | ||
|
||
|
||
data "template_file" "myfile" { | ||
template = file("./${var.template_name}") | ||
vars = var.template_vars | ||
} | ||
|
||
resource "null_resource" "configure_bosh_rds" { | ||
|
||
triggers = { run_every_time = "${uuid()}" } | ||
|
||
# Copy the script to the bastion | ||
provisioner "file" { | ||
content = "${data.template_file.myfile.rendered}" | ||
destination = "${var.rendered_file_destination}/${var.rendered_file_name}" | ||
connection { | ||
type = "ssh" | ||
user = var.bastion_user_name | ||
private_key = var.ssh_private_key | ||
host = var.host | ||
} | ||
} | ||
|
||
|
||
output "rendered_file_contents" {value = data.template_file.myfile.rendered } | ||
output "rendered_file_location" {value = "${var.rendered_file_destination}/${var.rendered_file_name}" } |