install third-party software on EC2 alternat instances
eddycek opened this issue · 2 comments
Hello, first of all I would like to thank you for your work on Alternat. Well done!
Now to the problem I'm solving. I need to install third party software on an EC2 instance of Alternat. Specifically Datadog monitoring through which I want to monitor enhanced networking metrics and other system metrics.
By default, things like this are inserted on EC2 via a user data script that you use yourself. But as a Terraform module user I have no way to add my own script. In our fork we temporarily solved this by adding a variable, something like:
variable "nat_instance_user_data_post_install" {
type = string
description = "Additional nat instance user data scripts"
default = ""
}
variable then appears in the data config (1debit/alternat/modules/terraform-aws-alternat/main.tf#L172)
data "cloudinit_config" "config" {
for_each = { for obj in var.vpc_az_maps : obj.az => obj.route_table_ids }
gzip = true
base64_encode = true
part {
content_type = "text/x-shellscript"
content = templatefile("${path.module}/alternat.conf.tftpl", {
eip_allocation_ids_csv = join(",", local.nat_instance_eip_ids),
route_table_ids_csv = join(",", each.value)
})
}
part {
content_type = "text/x-shellscript"
content = file("${path.module}/../../scripts/alternat.sh")
}
part {
content_type = "text/x-shellscript"
content = var.nat_instance_user_data_post_install
}
}
when defining a module, we then use a similar definition:
nat_instance_user_data_post_install = templatefile("${path.module}/templates/user_data_nat_instance.tpl", {
DD_SITE = var.datadog_site
DD_API_KEY = var.datadog_api_key
})
user_data_nat_instance.tpl
contains a separate installation of the Datadog agent, it is a easy bash script with a few commands. This is how any third party software for monitoring or other user needs should be installed.
Do you plan to add similar functionality in the future? Do you find our solution reasonable, or do you have another idea how to install third-party software?
Thanks in advance for your time!
This is great, thanks! Would you be willing to submit this feature in a PR? The only thing I think we should change is to make it optional with a dynamic
block:
dynamic "part" {
for_each = var. nat_instance_user_data_post_install != "" ? : [1] : []
content {
content_type = "text/x-shellscript"
content = var.nat_instance_user_data_post_install
}
}
(That's off the top of my head, the syntax may be off.)
Also, let's add the example you provided to the example invocation in README.md
.
Thanks again!
Great, I'll do a PR I just don't have a specific ETA, I'm busy right now.