https://github.com/philippechepy/terraform-initial-provisioning
https://github.com/philippechepy/terraform-initial-provisioning
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/philippechepy/terraform-initial-provisioning
- Owner: PhilippeChepy
- Created: 2021-12-13T21:15:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-27T18:59:03.000Z (over 4 years ago)
- Last Synced: 2026-01-02T10:56:33.963Z (6 months ago)
- Language: HCL
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Easily deploy files and run commands on remote host
This module allows one to easily deploy files and execute commands on a remote host (either before
or after provisioning files).
Example usage:
```terraform
module "etcd" {
source = "git@github.com:PhilippeChepy/terraform-initial-provisioning.git"
for_each = var.hostnames
connection = merge(
{ host = exoscale_compute.etcd[each.value].ip_address },
var.connection
)
# It's possible to run commands before copying files to the remote
# pre_exec = [
# ]
files = {
"/etc/etcd/tls/server-ca.pem" = {
content = var.certificates.ca_certificate
owner = "etcd"
group = "etcd"
mode = "0644"
}
"/etc/etcd/tls/server-cert.pem" = {
content = var.certificates.server_certificates[each.value]
owner = "etcd"
group = "etcd"
mode = "0644"
}
"/etc/etcd/tls/server-cert.key" = {
content = var.certificates.server_private_keys[each.value]
owner = "etcd"
group = "etcd"
mode = "0600"
}
"/etc/etcd/tls/peer-ca.pem" = {
content = var.certificates.ca_certificate
owner = "etcd"
group = "etcd"
mode = "0644"
}
"/etc/etcd/tls/peer-cert.pem" = {
content = var.certificates.peer_certificates[each.value]
owner = "etcd"
group = "etcd"
mode = "0644"
}
"/etc/etcd/tls/peer-cert.key" = {
content = var.certificates.peer_private_keys[each.value]
owner = "etcd"
group = "etcd"
mode = "0600"
}
"/etc/default/etcd" = {
content = templatefile("${path.module}/templates/etcd", {
hostname = each.value,
etcd_ip_address = exoscale_compute.etcd[each.value].ip_address,
etcd_ip_cluster = join(",", [for peer in var.hostnames : "${peer}=https://${exoscale_compute.etcd[peer].ip_address}:2380"])
})
owner = "etcd"
group = "etcd"
mode = "0644"
}
}
post_exec = [
"sudo systemctl enable etcd",
"sudo systemctl start etcd"
]
}
```
## Requirements
No requirements.
## Providers
The following providers are used by this module:
## Modules
No modules.
## Resources
The following resources are used by this module:
- [null_resource.files](https://registry.terraform.io/providers/hashicorp/null/latest/docs/resources/resource) (resource)
## Required Inputs
The following input variables are required:
### [connection](#input\_connection)
Description: An object describing how to connect to target server.
Type:
```hcl
object({
host = string
user = string
private_key = string
})
```
Description: A map of files to provision (key = full path of a file, value = file content and ownership/mode).
Type:
```hcl
map(object({
content = string
owner = string
group = string
mode = string
}))
```
## Optional Inputs
The following input variables are optional (have default values):
### [post\_exec](#input\_post\_exec)
Description: A list of commands to execute after provisioning files.
Type: `list(string)`
Default: `[]`
### [pre\_exec](#input\_pre\_exec)
Description: A list of commands to execute before provisioning files.
Type: `list(string)`
Default: `[]`
## Outputs
No outputs.