I want to build a CI pipeline where the infrastructure stage provisions with Terraform a container-optimised operating system instance on Google Compute Engine before the Dockerized application is uploaded to Artifact Registry and deployed for the first time.
My Terraform config:
data "google_compute_image" "cos" {
family = "cos-stable"
project = "cos-cloud"
}
resource "google_compute_instance" "container_optimized_os_vm" {
name = "container-optimized-os-vm"
machine_type = "f1-micro"
allow_stopping_for_update = true
network_interface {
network = "default"
}
boot_disk {
initialize_params {
image = data.google_compute_image.cos.self_link
}
}
metadata = {
google-logging-enabled = "true"
gce-container-declaration =<<EOT
spec:
containers:
- image: image-repository/image-name:latest
name: containervm
securityContext:
privileged: false
stdin: false
tty: false
volumeMounts: []
restartPolicy: Always
volumes: []
EOT
}
}
My command to deploy the latest version of my image from Artifact Registry:
gcloud compute instances update-container container-optimized-os-vm \
--zone europe-west2-b \
--container-image "europe-west2-docker.pkg.dev/my-project-id/my-image-repository-name/my-image-name:latest"
When I omit the gce-container-declaration
metadata, I get the following error:
ERROR: (gcloud.compute.instances.update-container) Instance doesn't have gce-container-declaration metadata key - it is not a container.
I want to be able to provision the instance without specifying an image in gce-container-declaration
—is this possible? My worry is that when infrastructure changes are detected, the image in gce-container-declaration
will be deployed instead of my application's image.