Héctor Valls
Héctor Valls

Reputation: 26084

Get file content as a Terraform output

I have a Terraform configuration where I start a systemd service on an AWS EC2 instance. I need to grep that service's log and export it to be a Terraform output.

When hello.service is started, it logs a line like this (among many other):

Root Key: F4BF9F7FCBEDABA0392F108C59D8F4A38B38

I need that line to be a Terraform output. Something like this:

resource "aws_instance" "instance" {

    provisioner "remote-exec" {
        //start hello.service
    }

}

output "rootKey" {
    value = "${}" //??
}

I want rootKey output to be the result of:

journalctl -u hello.service | grep "Root Key"

being executed at aws_instance.instance

How can I get it?

Upvotes: 1

Views: 1618

Answers (2)

Joost Döbken
Joost Döbken

Reputation: 4075

You can also use the github module created by Matti Paksula: https://github.com/matti/terraform-shell-resource

the repo has a good description and many examples to get started

Upvotes: 0

manojlds
manojlds

Reputation: 301477

One way to do this would be with the external data source and a wrapper script that does the journalctl -u hello.service | grep "Root Key" part to give you back the root key.

https://www.terraform.io/docs/providers/external/data_source.html

Upvotes: 1

Related Questions