Skip to content

Commit ce9e0ae

Browse files
authored
Merge pull request #118 from glittershark/route53-eip
Allow Route53 recordsets to point at EIPs
2 parents 7e0f258 + a457c87 commit ce9e0ae

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

.github/workflows/ci.yaml

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: Checkout
1212
uses: actions/checkout@v2
1313
- name: Nix
14-
uses: cachix/install-nix-action@v8
14+
uses: cachix/install-nix-action@v12
1515
- name: Build
1616
run: 'nix-build -I nixpkgs=channel:nixos-unstable --quiet release.nix -A nixops-aws.x86_64-linux --show-trace'
1717
# Run black v19.10b0 and ensure no diff, using a pinned channel to ensure the
@@ -25,24 +25,30 @@ jobs:
2525
- name: Checkout
2626
uses: actions/checkout@v2
2727
- name: Nix
28-
uses: cachix/install-nix-action@v8
28+
uses: cachix/install-nix-action@v12
2929
- name: Black
3030
run: 'nix-shell ./shell.nix --run "black --check ."'
31+
env:
32+
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
3133
flake8:
3234
runs-on: ubuntu-latest
3335
steps:
3436
- name: Checkout
3537
uses: actions/checkout@v2
3638
- name: Nix
37-
uses: cachix/install-nix-action@v8
39+
uses: cachix/install-nix-action@v12
3840
- name: Flake8
3941
run: 'nix-shell ./shell.nix --run "flake8 nixops_aws"'
42+
env:
43+
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
4044
mypy:
4145
runs-on: ubuntu-latest
4246
steps:
4347
- name: Checkout
4448
uses: actions/checkout@v2
4549
- name: Nix
46-
uses: cachix/install-nix-action@v8
50+
uses: cachix/install-nix-action@v12
4751
- name: Mypy
4852
run: 'nix-shell ./shell.nix --run "mypy nixops_aws"'
53+
env:
54+
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"

nixops_aws/nix/route53-recordset.nix

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ with (import ./lib.nix lib);
8181
};
8282

8383
recordValues = mkOption {
84-
type = types.listOf (types.either types.str (resource "machine"));
84+
type = types.listOf (types.oneOf [
85+
types.str
86+
(resource "machine")
87+
(resource "elastic-ip")
88+
]);
8589

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

nixops_aws/resources/route53_recordset.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import boto3
77
import nixops.util
88
import nixops.resources
9+
import nixops.deployment
910
import nixops_aws.ec2_utils
10-
from . import route53_hosted_zone, route53_health_check
11+
from . import route53_hosted_zone, route53_health_check, elastic_ip
1112
from .route53_hosted_zone import Route53HostedZoneState
1213
from .route53_health_check import Route53HealthCheckState
1314
from nixops_aws.backends.ec2 import EC2State
@@ -218,18 +219,32 @@ def create(self, defn, check, allow_reboot, allow_recreate): # noqa: C901
218219
)
219220
)
220221

221-
def resolve_machine_ip(v):
222+
def resolve_ip(v):
222223
if v.startswith("res-"):
223-
m = self.depl.get_machine(v[4:], EC2State)
224-
if not m.public_ipv4:
225-
raise Exception(
226-
"cannot create record set for a machine that has not yet been created"
227-
)
228-
return m.public_ipv4
224+
name = v[4:]
225+
res = self.depl.active_resources.get(name)
226+
if res is None:
227+
raise Exception(f"Resource ‘{name}’ does not exist")
228+
229+
if isinstance(res, EC2State):
230+
m: EC2State = res
231+
if not m.public_ipv4:
232+
raise Exception(
233+
"cannot create record set for a machine that has not yet been created"
234+
)
235+
return m.public_ipv4
236+
elif isinstance(res, elastic_ip.ElasticIPState):
237+
eip: elastic_ip.ElasticIPState = res
238+
if not eip.public_ipv4:
239+
raise Exception(
240+
"cannot create record set for an ElasticIP that has not yet been created"
241+
)
242+
return eip.public_ipv4
243+
# elif v.startswith
229244
else:
230245
return v
231246

232-
defn.record_values = [resolve_machine_ip(m) for m in defn.record_values]
247+
defn.record_values = [resolve_ip(m) for m in defn.record_values]
233248

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

0 commit comments

Comments
 (0)