I am creating ec2 Instance using Terraform and I wanted to update gateway, dns_server in the ec2. I use the following user_data in aws_instance resource of Terraform Code.
user_data = <<-EOT
#cloud-config
write_files:
- path: /etc/cloud.json
owner: root:root
permissions: '0644'
content: |
{
"IPaddress": "172.5.134.231",
"netmask": "255.255.255.0",
"gateway": "12.5.134.2",
"dns_servers": ["12.5.134.20"],
"fqdn": "test.sequence",
"ntp": ["ntp.test.sequence"],
"password": "${var.catalyst_center}"
}
EOT
also I tried the following user_data
user_data = base64encode(templatefile("${path.module}/templates/catalyst_center_user_data.tpl", {
PASSWORD = var.catalyst_center
IP_ADDRESS = "172.5.134.231"
SUBNET = "255.255.255.0"
GATEWAY = "12.5.134.2"
DNS_SERVER = "12.5.134.20"
HOSTNAME = "test.sequence"
})
)
}
where the tpl file contains
{
"IPaddress": "${IP_ADDRESS}",
"netmask": "${SUBNET}",
"gateway": "${GATEWAY}",
"dns_servers": ["${DNS_SERVER}"],
"fqdn" : "${HOSTNAME}",
"ntp": ["ntp.test.sequence"],
"password" : "${PASSWORD}"
}
In both the ways, EC2 is getting created but when I perform the command sudo maglev-config update Gateway and DNS Server values are still empty.