|
6 | 6 | import boto3
|
7 | 7 | import nixops.util
|
8 | 8 | import nixops.resources
|
| 9 | +import nixops.deployment |
9 | 10 | 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 |
11 | 12 | from .route53_hosted_zone import Route53HostedZoneState
|
12 | 13 | from .route53_health_check import Route53HealthCheckState
|
13 | 14 | from nixops_aws.backends.ec2 import EC2State
|
@@ -218,18 +219,32 @@ def create(self, defn, check, allow_reboot, allow_recreate): # noqa: C901
|
218 | 219 | )
|
219 | 220 | )
|
220 | 221 |
|
221 |
| - def resolve_machine_ip(v): |
| 222 | + def resolve_ip(v): |
222 | 223 | 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 |
229 | 244 | else:
|
230 | 245 | return v
|
231 | 246 |
|
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] |
233 | 248 |
|
234 | 249 | changed = (
|
235 | 250 | self.record_values != defn.record_values
|
@@ -350,4 +365,5 @@ def create_after(self, resources, defn):
|
350 | 365 | if isinstance(r, route53_hosted_zone.Route53HostedZoneState)
|
351 | 366 | or isinstance(r, route53_health_check.Route53HealthCheckState)
|
352 | 367 | or isinstance(r, nixops.backends.MachineState)
|
| 368 | + or isinstance(r, elastic_ip.ElasticIPState) |
353 | 369 | }
|
0 commit comments