CompositionalIT / farmer

Repeatable Azure deployments with ARM templates - made easy!
https://compositionalit.github.io/farmer
MIT License
523 stars 157 forks source link

Adds Image Templates for building and publishing VM images. #1015

Closed ninjarobot closed 1 year ago

ninjarobot commented 1 year ago

The changes in this PR are as follows:

I have read the contributing guidelines and have completed the following:

If I haven't completed any of the tasks above, I include the reasons why here:

Below is a minimal example configuration that includes the new features, which can be used to deploy to Azure:

open Farmer
open Farmer.Builders

arm {
    location Location.EastUS

    add_resources
        [
            gallery {
                name "mygallery"
                description "Example Image Gallery"
            }
            imageTemplate {
                name "Ubuntu2004WithJava"
                add_identity msi
                source_platform_image Vm.UbuntuServer_2004LTS

                add_customizers
                    [
                        shellCustomizer {
                            name "install-jdk"

                            inline_statements
                                [
                                    "set -eux"
                                    "sudo apt-get update"
                                    "sudo apt-get -y upgrade"
                                    "sudo apt-get -y install openjdk-17-jre-headless"
                                ]
                        }
                    ]

                add_distributors
                    [
                        sharedImageDistributor {
                            gallery_image_id
                                (ResourceType("Microsoft.Compute/galleries/images", "2020-09-30")
                                    .resourceId (
                                        ResourceName "mygallery",
                                        ResourceName "java-server-os"
                                    )
                                )
                            add_replication_regions [ Location.EastUS ]
                            add_tags [
                                "image-type", "java"
                            ]
                        }
                    ]
            }
        ]
}
ninjarobot commented 1 year ago

@isaacabraham could you review this? I originally was just going to add the ImageTemplate resource to be able to generate VM images (no portal support), but the gallery feature also seemed useful, I added that as well.

isaacabraham commented 1 year ago

Thanks for doing this :-)