Skip to content

Deploying from Hydra with Terraform #72

Open
@grahamc

Description

@grahamc

Description

It'd be slick to implement the concepts from https://determinate.systems/posts/hydra-deployment-source-of-truth in Terraform.

Specifically:

  • Get the build information for a job's latest successful build, and latest successful build from a completed evaluation
  • Get information about a specific constituent of an aggregate job

New or Affected Resource(s)

data "hydra_job"
data "hydra_job_aggregate_constituent"

Potential Terraform Configuration

Deploying from a job:

data "hydra_job" "latest_myapp" {
    project = "myapp"
    jobset = "main"
    job = "myapp"
    wait_for_all_jobs = true # latest-successful ... consider a better name?
}

resource "aws_instance" "web" {
  # ...

  provisioner "remote-exec" {
    command = "nix-env -p /nix/var/nix/profiles/myapp --set '${data.hydra_job.latest_myapp.outputs.out.path}'"
  }
}

Deploy the constituent of an aggregate job:

data "hydra_job_aggregate_constituent" "serverconfig" {
    project = "myapp"
    jobset = "main"
    job = "release_gate"
    constituent = "serverconfig"
    wait_for_all_jobs = true
}

resource "aws_instance" "web" {
  # ...

  provisioner "remote-exec" {
    inline = [
      "nix-env --profile /nix/var/nix/profiles/system --set '${data.hydra_job_aggregate_constituent.serverconfig.outputs.out.path}'",
      "/nix/var/nix/profiles/system/bin/switch-to-configuration switch",
    ]
  }
}

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions