I am trying to write a systemd service
file using ignition provider
of terraform
like below for ubuntu OS
# Systemd unit data resource containing the unit definition
data "ignition_systemd_unit" "example" {
name = "example.service"
content = "[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target"
}
# Ingnition config include the previous defined systemd unit data resource
data "ignition_config" "example" {
systemd = [
data.ignition_systemd_unit.example.rendered,
]
}
# Create a CoreOS server using the Igntion config.
resource "aws_instance" "web" {
# ...
user_data = data.ignition_config.example.rendered
}
and in azurerm_linux_virtual_machine
i gave like below
custom_data = data.ignition_config.example.rendered
I am getting an error like below
Error: expected "custom_data" to be a base64 string, got {"ignition":{"config":{},"timeouts":{},"version":"2.1.0"},"networkd":{},"passwd":{},"storage":{},"systemd":{"units":[{"contents":"[Service]\nType=oneshot\nExecStart=/usr/bin/echo Hello World\n\n[Install]\nWantedBy=multi-user.target","enabled":true,"name":"example.service"}]}}
How can i create a systemd service
file using terraform
and also what am i missing with above config, will this ignition
work only with centos
? Any help on this would be appreciated
For the error message, you could use base64encode function to apply Base64 encoding to a string.
custom_data = base64encode(data.ignition_config.example.rendered)