Cloud-init
Cloud-init is a multi-distribution package that handles the early initialization of cloud instances.
Cloud-init is the industry standard multi-distribution method for cross-platform cloud instance initialization.
It is commonly used in cloud computing environments to perform various tasks during the instance’s first boot:
- User Data: When a new instance is launched in a cloud environment, the user provides user data consisting of a script or cloud-init directives with the instructions to configure the instance.
- Instance Launch: AWS injects the user data into the instance metadata.
- Cloud-init Execution: During the first boot of the instance, cloud-init reads the user data and executes the specified actions and tasks, such as setting up SSH keys, installing packages, or configuring users.
- Configurations: cloud-init processes the user data using modules, each responsible for a specific aspect of configuration.
- DataSource: cloud-init relies on a DataSource to retrieve information about the instance and its environment. AWS provides a metadata service with details like instance ID, hostname, and user data.
- Output and Logs: the results of the cloud-init execution are logged in /var/log/cloud-init.log or /var/log/cloud-init-output.log. Additionally, the early configuration of the instance can be inspected with the console output in the AWS Console.
- Completion: Once cloud-init completes its tasks, the instance is ready for use with the configured settings.
Cloud-Init and SSH Public Keys #
During instance launch, Cloud-init appends the AWS stored Public Key to the instance authorized_keys file inside the ~/.ssh/ directory.
Official Cloud-Init documentation.
See tutorials using Cloud-Init:
More tutorials that use Cloud-init
- Terraform Provisioners and EC2 user_data: When to Use Each (and Alternatives)
- Terraform and OpenTofu on OpenStack: Getting Started with the OpenStack Provider
- Terraform and OpenTofu on Alibaba Cloud: Getting Started with the Alicloud Provider
- Terraform and OpenTofu on DigitalOcean: Droplets, VPC and Firewall
- AWS with Terraform Tutorial: AWS EC2 Instances (12)