Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
cweibel committed Jun 23, 2022
1 parent 7deede2 commit 93a05c3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
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}
```
35 changes: 35 additions & 0 deletions main.tf
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}" }

0 comments on commit 93a05c3

Please sign in to comment.