I'm playing with this code and it works very well....
# general
a
I'm playing with this code and it works very well. However, that's just a very plain web server which is started in userdata. What I want to do is include the application which is behind a reverse proxy like Nginx. How do we include the files and directories of my application, nginx etc so it can be part of the ec2 build-deployment that will be deployed by
pulumi up
?
Copy code
for az in aws.get_availability_zones().names:
    server = aws.ec2.Instance(
        f"web-server-{az}",
        instance_type="t2.micro",
        vpc_security_group_ids=[group.id],
        ami=ami.id,
        user_data="""#!/bin/bash
echo \"Hello, World -- from {}!\" > index.html
nohup python3 -m http.server 80 --bind 0.0.0.0 &
""".format(
            az
        ),
        tags={
            "Name": "web-server",
        },
    )
    ips.append(server.public_ip)
    hostnames.append(server.public_dns)

    attachment = aws.lb.TargetGroupAttachment(
        f"web-server-{az}",
        target_group_arn=target_group.arn,
        target_id=server.id,
        port=80,
    )
b
how do you currently do this?
a
I'll check our tooling. It wasn't me who built it. If I recall correctly, i think they were using an imaging tool but I couldn't recall the name
It looks like it maybe part of a hashicorp tool
how are others doing it?
oh, one project of ours is also using userdata. It uses terraform
data cloudinit_config
where it references an external yml file. The yml file has an entry
write_files:
and under it are the path, owner, permissions, encoding and content. I don't know if the yml file content is specific for terraform though
I found something similar but do I just import cloudinit like
import cloudinit
?
Copy code
cloudconfig = cloudinit.get_config(
      base64_encode = False,
      gzip = False,
      parts = [
        cloudinit.GetConfigPartArgs(
          content = "#cloudconfig\npackages:\n- prometheus-node-exporter",
          content_type = "text/cloud-config",
          filename = "init.cfg"
        )
      ]
    )
ah it said 🙂
Copy code
pip3 install pulumi_cloudinit