Add Fedora CoreOS Custom Image to DigitalOcean - Terraform

By Priyash Patil | 2 min read | Updated: Aug 15, 2024 2PM UTC

CoreOS is a Linux distribution optimized for running containerized applications. It is built to provide an automated, secure, and efficient environment for applications leveraging containerized workflows. CoreOS includes features like automatic updates and distributed system optimization tools, making it an excellent choice for cloud infrastructure.

For more information, visit the Fedora CoreOS Documentation.

Prerequisites

Before you begin, make sure you have:

The CoreOS image URL we’ll use for this tutorial:

https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/40.20240728.3.0/x86_64/fedora-coreos-40.20240728.3.0-digitalocean.x86_64.qcow2.gz

Make sure to grab the correct URL from https://www.fedoraproject.org/coreos/download?stream=stable

Method 1: Using DigitalOcean GUI

  1. Navigate to Custom Images
      - Log in to your DigitalOcean account.
      - Go to the left-hand panel and select “Backups & Snapshots” followed by “Custom Images”.
  2. Upload the CoreOS Image
      - Click on “Import via URL”.
      - Fill in the details, including the image URL as specified above, name, distribution type (“Fedora” in this case), and target datacenter region.
      - Click “Import Image” to start the import process.
  3. Verify
      - Once uploaded, the image should appear under “Custom Images”.
      - You can now create a Droplet using this custom CoreOS image.

Method 2: Using the DigitalOcean API

To use the DigitalOcean API, you’ll first need to generate an API key from your DigitalOcean account under “API” settings. With your API key ready, you can upload the CoreOS image using a cURL command. Here’s a sample command for your reference:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
  "name": "coreos-image",
  "url": "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/40.20240728.3.0/x86_64/fedora-coreos-40.20240728.3.0-digitalocean.x86_64.qcow2.gz",
  "distribution": "CoreOS",
  "region": "nyc3"
}' "https://api.digitalocean.com/v2/images"

After running the command, you can verify the upload by listing your custom images using the API.

Method 3: Using Doctl

For those who prefer using CLI tools, doctl is an excellent option. Begin by installing doctl following DigitalOcean’s Doctl Documentation. Once installed, you can upload your custom CoreOS image with the following command:

doctl compute image create coreos-image --url https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/40.20240728.3.0/x86_64/fedora-coreos-40.20240728.3.0-digitalocean.x86_64.qcow2.gz --region nyc3 --distribution CoreOS

To confirm the upload, list your images using doctl compute image list.

Method 4: Using Terraform

Terraform offers a way to manage infrastructure as code. First, install Terraform from the official website and set it up. Create a main.tf file with the following content to configure the deployment:

provider "digitalocean" {
    token = "YOUR_API_TOKEN"
}

resource "digitalocean_custom_image" "coreos_image" {
    name         = "coreos-image"
    url          = "https://builds.coreos.fedoraproject.org/prod/streams/stable/builds/40.20240728.3.0/x86_64/fedora-coreos-40.20240728.3.0-digitalocean.x86_64.qcow2.gz"
    region       = "nyc3"
    distribution = "CoreOS"
}

Run terraform init to initialize the configuration, followed by terraform apply to execute it. After applying the configuration, you can confirm the upload via the DigitalOcean console or API.

Conclusion

Adding a custom CoreOS image to DigitalOcean is straightforward and can be achieved using multiple methods: the GUI, API, Doctl, and Terraform. Each method caters to different user preferences, whether you prefer graphical interfaces, API calls, or managing infrastructure as code.

References

Keep the Conversation Going

I hope you found this post helpful! If you have any questions or feedback, feel free to reach out. You can also find me on X (Twitter) @priyashpatil for additional insights and updates on my latest content.

Related

Featured on laravel-news.com and benjamincrozat.com.

Optimized image uploads with CKEditor and Laravel

By Priyash Patil on Friday, 03 November 2023

Bootstrap 5 Remove Unused CSS with Vite and PurgeCSS

By Priyash Patil on Wednesday, 17 January 2024

Laravel Vite Deploy Assets to Global CDN

By Priyash Patil on Friday, 19 January 2024

Laravel file upload with validation example

By Priyash Patil on Thursday, 25 January 2024