Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-install, post-install hooks to install-ptfe.sh #79

Merged
merged 6 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Local .terraform directories
*.env
*.tfstate*
*.tfvars
**/.terraform/*

work/
work/
1 change: 1 addition & 0 deletions .terraform-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
latest:^0.12
6 changes: 4 additions & 2 deletions config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ data "template_file" "cloud_config" {
repl_cidr = var.repl_cidr
ca_bundle_url = var.ca_bundle_url
import_key = var.import_key
startup_script = base64encode(var.startup_script)
role = count.index == 0 ? "main" : "primary"
distro = var.distribution
rptfeconf = base64encode(data.template_file.repl_ptfe_config.rendered)
replconf = base64encode(data.template_file.repl_config.rendered)
postinstall_script = var.postinstall_script
preinstall_script = var.preinstall_script
}
}

Expand Down Expand Up @@ -106,6 +107,8 @@ data "template_file" "cloud_config_secondary" {
airgap_installer_url = var.airgap_package_url == "" ? "" : local.internal_airgap_url
ca_bundle_url = var.ca_bundle_url
import_key = var.import_key
postinstall_script = var.postinstall_script
preinstall_script = var.preinstall_script
}
}

Expand All @@ -128,4 +131,3 @@ data "template_file" "ssh_config" {
keyfile_path = module.common.ssh_priv_key_file
}
}

3 changes: 2 additions & 1 deletion docs/inputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
| postgresql\_extra\_params | additional connection string parameters (must be url query params) | `string` | `""` | no |
| postgresql\_password | password to connect to external postgresql database as | `string` | `""` | no |
| postgresql\_user | user to connect to external postgresql database as | `string` | `""` | no |
| postinstall\_script | A custom shell script which will be invoked after TFE is installed. The value must start with a shebang line in order to be executed. | `string` | `"#!/bin/bash\n\necho 'A post-install script was not provided.'\n"` | no |
| prefix | Name prefix for resource names and tags | `string` | `"tfe"` | no |
| preinstall\_script | A custom shell script which will be invoked before TFE is installed. The value must start with a shebang line in order to be executed. | `string` | `"#!/bin/bash\n\necho 'A pre-install script was not provided.'\n"` | no |
| primary\_instance\_type | ec2 instance type | `string` | `"m4.xlarge"` | no |
| private\_zone | set to true if your route53 zone is private | `string` | `false` | no |
| release\_sequence | Replicated release sequence number to install - this locks the install to a specific release | `string` | `""` | no |
Expand All @@ -42,7 +44,6 @@
| secondary\_count | The number of secondary cluster nodes to run | `string` | `5` | no |
| secondary\_instance\_type | ec2 instance type (Defaults to `primary_instance_type` if not set.) | `string` | `""` | no |
| ssh\_user | the user to connect to the instance as | `string` | `""` | no |
| startup\_script | shell script to run when primary instance boots the first time | `string` | `""` | no |
| subnet\_tags | tags to use to match subnets to use | `map(string)` | `{}` | no |
| tags | Map of tags to add to all resources | `map(string)` | `{}` | no |
| update\_route53 | whether or not to automatically update route53 records for the cluster | `string` | `true` | no |
Expand Down
16 changes: 14 additions & 2 deletions templates/cloud-config-secondary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ write_files:
content: ${airgap_installer_url}
%{ endif }

- path: /var/lib/cloud/scripts/per-once/install-ptfe.sh
- path: /var/lib/cloud/scripts/per-once/000-pre-install.sh
owner: root:root
permissions: "0555"
permissions: "0500"
encoding: b64
content: ${base64encode(preinstall_script)}

- path: /var/lib/cloud/scripts/per-once/001-install-ptfe.sh
owner: root:root
permissions: "0500"
encoding: b64
content: ${install_ptfe_sh}

- path: /var/lib/cloud/scripts/per-once/002-post-install.sh
owner: root:root
permissions: "0500"
encoding: b64
content: ${base64encode(postinstall_script)}

- path: /etc/ptfe/proxy-url
owner: root:root
permissions: "0400"
Expand Down
18 changes: 11 additions & 7 deletions templates/cloud-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,24 @@ write_files:
permissions: "0444"
content: "${role_id}"

%{ if startup_script != "" }
- path: /var/lib/cloud/scripts/per-once/000-user-startup-script.sh
- path: /var/lib/cloud/scripts/per-once/000-pre-install.sh
owner: root:root
permissions: "0555"
permissions: "0500"
encoding: b64
content: ${startup_script}
%{ endif }
content: ${base64encode(preinstall_script)}

- path: /var/lib/cloud/scripts/per-once/install-ptfe.sh
- path: /var/lib/cloud/scripts/per-once/001-install-ptfe.sh
owner: root:root
permissions: "0555"
permissions: "0500"
encoding: b64
content: ${install_ptfe_sh}

- path: /var/lib/cloud/scripts/per-once/002-post-install.sh
owner: root:root
permissions: "0500"
encoding: b64
content: ${base64encode(postinstall_script)}

- path: /etc/ptfe/proxy-url
owner: root:root
permissions: "0400"
Expand Down
3 changes: 2 additions & 1 deletion templates/ssh_config
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Host default
PasswordAuthentication no
IdentityFile ${keyfile_path}
IdentitiesOnly yes
LogLevel FATAL
LogLevel FATAL
ForwardAgent yes
26 changes: 19 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ variable "ssh_user" {
default = ""
}

variable "startup_script" {
type = string
description = "shell script to run when primary instance boots the first time"
default = ""
}

variable "subnet_tags" {
type = map(string)
description = "tags to use to match subnets to use"
Expand Down Expand Up @@ -187,6 +181,25 @@ variable "tags" {
default = {}
}

variable "postinstall_script" {
default = <<-EOD
#!/bin/bash

echo 'A post-install script was not provided.'
EOD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this isn't an explicit suggestion or a blocking question, but do we as a team have an opinionated stance on heredoc format over using file() for non templated things, this script is small enough to not run into any issues, but to align expectations I'm wondering if we want to put all these in the files/ dir as like postinstall.default.sh

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that sounds reasonable!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does b87a7fc look?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

description = "A custom shell script which will be invoked after TFE is installed. The value must start with a shebang line in order to be executed."
type = string
}

variable "preinstall_script" {
default = <<-EOD
#!/bin/bash

echo 'A pre-install script was not provided.'
EOD
description = "A custom shell script which will be invoked before TFE is installed. The value must start with a shebang line in order to be executed."
type = string
}

### ================================ External Services Support

Expand Down Expand Up @@ -331,4 +344,3 @@ resource "random_string" "setup_token" {
upper = false
special = false
}