Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixops-aws
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7e0f25872fff
Choose a base ref
...
head repository: NixOS/nixops-aws
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ce9e0ae63981
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Nov 27, 2020

  1. Allow Route53 recordsets to point at EIPs

    Allow the values in a route53 recordset to be ElasticIP resources, in
    the same way that they are allowed to be machine resources, and resolve
    the ip address of the ElasticIP when creating the recordset
    glittershark authored and adisbladis committed Nov 27, 2020
    Copy the full SHA
    de62c23 View commit details
  2. Copy the full SHA
    a457c87 View commit details
  3. Merge pull request #118 from glittershark/route53-eip

    Allow Route53 recordsets to point at EIPs
    adisbladis authored Nov 27, 2020
    Copy the full SHA
    ce9e0ae View commit details
Showing with 40 additions and 14 deletions.
  1. +10 −4 .github/workflows/ci.yaml
  2. +5 −1 nixops_aws/nix/route53-recordset.nix
  3. +25 −9 nixops_aws/resources/route53_recordset.py
14 changes: 10 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Nix
uses: cachix/install-nix-action@v8
uses: cachix/install-nix-action@v12
- name: Build
run: 'nix-build -I nixpkgs=channel:nixos-unstable --quiet release.nix -A nixops-aws.x86_64-linux --show-trace'
# Run black v19.10b0 and ensure no diff, using a pinned channel to ensure the
@@ -25,24 +25,30 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Nix
uses: cachix/install-nix-action@v8
uses: cachix/install-nix-action@v12
- name: Black
run: 'nix-shell ./shell.nix --run "black --check ."'
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
flake8:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Nix
uses: cachix/install-nix-action@v8
uses: cachix/install-nix-action@v12
- name: Flake8
run: 'nix-shell ./shell.nix --run "flake8 nixops_aws"'
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
mypy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Nix
uses: cachix/install-nix-action@v8
uses: cachix/install-nix-action@v12
- name: Mypy
run: 'nix-shell ./shell.nix --run "mypy nixops_aws"'
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
6 changes: 5 additions & 1 deletion nixops_aws/nix/route53-recordset.nix
Original file line number Diff line number Diff line change
@@ -81,7 +81,11 @@ with (import ./lib.nix lib);
};

recordValues = mkOption {
type = types.listOf (types.either types.str (resource "machine"));
type = types.listOf (types.oneOf [
types.str
(resource "machine")
(resource "elastic-ip")
]);

apply = l: map (x: if (builtins.isString x) || ( x == null) then x else "res-" + x._name) l;

34 changes: 25 additions & 9 deletions nixops_aws/resources/route53_recordset.py
Original file line number Diff line number Diff line change
@@ -6,8 +6,9 @@
import boto3
import nixops.util
import nixops.resources
import nixops.deployment
import nixops_aws.ec2_utils
from . import route53_hosted_zone, route53_health_check
from . import route53_hosted_zone, route53_health_check, elastic_ip
from .route53_hosted_zone import Route53HostedZoneState
from .route53_health_check import Route53HealthCheckState
from nixops_aws.backends.ec2 import EC2State
@@ -218,18 +219,32 @@ def create(self, defn, check, allow_reboot, allow_recreate): # noqa: C901
)
)

def resolve_machine_ip(v):
def resolve_ip(v):
if v.startswith("res-"):
m = self.depl.get_machine(v[4:], EC2State)
if not m.public_ipv4:
raise Exception(
"cannot create record set for a machine that has not yet been created"
)
return m.public_ipv4
name = v[4:]
res = self.depl.active_resources.get(name)
if res is None:
raise Exception(f"Resource ‘{name}’ does not exist")

if isinstance(res, EC2State):
m: EC2State = res
if not m.public_ipv4:
raise Exception(
"cannot create record set for a machine that has not yet been created"
)
return m.public_ipv4
elif isinstance(res, elastic_ip.ElasticIPState):
eip: elastic_ip.ElasticIPState = res
if not eip.public_ipv4:
raise Exception(
"cannot create record set for an ElasticIP that has not yet been created"
)
return eip.public_ipv4
# elif v.startswith
else:
return v

defn.record_values = [resolve_machine_ip(m) for m in defn.record_values]
defn.record_values = [resolve_ip(m) for m in defn.record_values]

changed = (
self.record_values != defn.record_values
@@ -350,4 +365,5 @@ def create_after(self, resources, defn):
if isinstance(r, route53_hosted_zone.Route53HostedZoneState)
or isinstance(r, route53_health_check.Route53HealthCheckState)
or isinstance(r, nixops.backends.MachineState)
or isinstance(r, elastic_ip.ElasticIPState)
}