snippetterraformMinor
How to provide multiple configs for EC2 node using Terraform and cloud-init?
Viewed 0 times
providenodeinitec2andcloudconfigsformultiplehow
Problem
I need to use several configs on my EC2 node using Terraform.
node declaration:
But when it's being bootstrapped I see only
How to make it work properly? May be I have wrong extensions for my configs? Or I just do not trigger its' launching? Thanks in advance.
after hours of troubleshooting i found out that there might be something wrong with encoding.
```
[root@ip-172-31-29-73 ec2-user]# cat /var/log/cloud-init.log
Aug 10 09:45:24 ip-172-31-29-73 cloud-init: Cloud-init v. 0.7.6 running 'init-local' at Thu, 10 Aug 2017 13:45:24 +0000. Up 5.79 seconds.
Aug 10 09:45:31 ip-172-31-29-73 cloud-init: Cloud-init v. 0.7.6 running 'init' at Thu, 10 Aug 2017 13:45:31 +0000. Up 12.31 seconds.
Aug
data "template_cloudinit_config" "puppetserver_config" {
gzip = true
base64_encode = true
part {
filename = "initial.sh"
content_type = "text/x-shellscript"
content = "${data.template_file.initial_config.rendered}"
}
part {
filename = "puppetserver_config.cfg"
content_type = "text/cloud-config"
content = "${data.template_file.puppetserver_config.rendered}"
}
}
data "template_file" "puppetserver_config" {
template = "${file("${path.module}/puppetserver_config.tpl")}"
}
data "template_file" "initial_config" {
template = "${file("${path.module}/initial_config.sh")}"
}node declaration:
resource "aws_instance" "puppetserver" {
depends_on = ["aws_security_group.puppetserver"]
count = 1
key_name = "${var.key_name}"
ami = "${data.aws_ami.centos7.id}"
instance_type = "${var.instance_type}"
user_data = "${data.template_cloudinit_config.puppetserver_config.rendered}"
security_groups = ["${aws_security_group.puppetserver.name}"]
tags {
Name = "puppet"
}
}But when it's being bootstrapped I see only
initial_config worked. puppetserver_config is ignored.How to make it work properly? May be I have wrong extensions for my configs? Or I just do not trigger its' launching? Thanks in advance.
after hours of troubleshooting i found out that there might be something wrong with encoding.
/var/log/cloud-init.log says:```
[root@ip-172-31-29-73 ec2-user]# cat /var/log/cloud-init.log
Aug 10 09:45:24 ip-172-31-29-73 cloud-init: Cloud-init v. 0.7.6 running 'init-local' at Thu, 10 Aug 2017 13:45:24 +0000. Up 5.79 seconds.
Aug 10 09:45:31 ip-172-31-29-73 cloud-init: Cloud-init v. 0.7.6 running 'init' at Thu, 10 Aug 2017 13:45:31 +0000. Up 12.31 seconds.
Aug
Solution
It sounds like you want to do some configuration management upstream from the terraform. I would suggest following a pattern of writing Packer templates to build and provision the AMIs before running the terraform plan and apply. By judiciously applying tags to the image name, you can write a
Your pipeline will be a bit longer (you need to add the packer build step to it), but your configuration will be more reliable and easier to maintain.
Note: I realise that this does not answer your actual question -- it is more along the lines of "don't do what you want, do something else. My opinion is that since terraform is for provisioning infrastructure, it is something of an abuse to extend its use too far into configuration management, and it would be better to use something more suited to the job.
data statement to reliably find it.Your pipeline will be a bit longer (you need to add the packer build step to it), but your configuration will be more reliable and easier to maintain.
Note: I realise that this does not answer your actual question -- it is more along the lines of "don't do what you want, do something else. My opinion is that since terraform is for provisioning infrastructure, it is something of an abuse to extend its use too far into configuration management, and it would be better to use something more suited to the job.
Context
StackExchange DevOps Q#1693, answer score: 2
Revisions (0)
No revisions yet.