@@ -51,6 +51,8 @@ def manages_dns(config, app):
5151 'aws-profile' , 'aws-region' , 'aws-subnet-id' , 'aws-instance-type' , 'aws-image-id' ,
5252 'aws-root-volume-size-gb' , 'aws-root-volume-type' , 'aws-nested-virtualization' ,
5353 'aws-threads-per-core' ,
54+ # A pre-existing machine; the application supplies its provider object.
55+ 'existing-ip' , 'existing-host-key' ,
5456}
5557
5658PROVIDER_DEFAULTS = {
@@ -65,6 +67,7 @@ def manages_dns(config, app):
6567 'gcp-nic-type' : 'VIRTIO_NET' , 'gcp-local-ssd-count' : 0 },
6668 'aws' : {'aws-instance-type' : 't3.small' , 'aws-root-volume-size-gb' : 50 ,
6769 'aws-root-volume-type' : 'gp3' , 'aws-nested-virtualization' : False },
70+ 'existing' : {},
6871}
6972
7073
@@ -119,10 +122,10 @@ def normalize(raw, *, path, env=None, resolve=True, aliases=None, defaults=None,
119122 overlaid = read_pars ({** DEFAULTS , ** raw }, environment )
120123 provider = overlaid .get ('provider-compute' )
121124 if not isinstance (provider , str ) or provider not in PROVIDER_DEFAULTS :
122- raise DeployError ('Supported compute providers are oci, digitalocean, gcp, hcloud and aws .' )
125+ raise DeployError ('Supported compute providers are oci, digitalocean, gcp, hcloud, aws and existing .' )
123126 # Apply defaults only to the selected provider, including environment overrides.
124127 defaults = PROVIDER_DEFAULTS [provider ]
125- prefixes = ('oci-' , 'digitalocean-' , 'gcp-' , 'hcloud-' , 'aws-' )
128+ prefixes = ('oci-' , 'digitalocean-' , 'gcp-' , 'hcloud-' , 'aws-' , 'existing-' )
126129 foreign = tuple (prefix for prefix in prefixes if prefix != provider + '-' )
127130 if any (key .startswith (foreign ) for key in raw ):
128131 raise DeployError ('Compute configuration contains fields for a different provider.' )
@@ -155,6 +158,8 @@ def normalize(raw, *, path, env=None, resolve=True, aliases=None, defaults=None,
155158
156159def scope (c ):
157160 provider = c .get ('provider-compute' , 'oci' )
161+ if provider == 'existing' :
162+ return {'provider' : provider , 'address' : c ['existing-ip' ]}
158163 if provider == 'hcloud' :
159164 return {'provider' : provider , 'location' : c ['hcloud-location' ], 'network' : 'none' }
160165 if provider == 'aws' :
@@ -195,18 +200,29 @@ def validate_aws(c):
195200 raise DeployError ('aws-threads-per-core must be 1 or 2.' )
196201
197202
203+ def validate_existing (c ):
204+ try :
205+ if ipaddress .IPv4Address (c ['existing-ip' ]).compressed != c ['existing-ip' ]:
206+ raise ValueError ()
207+ except (ValueError , TypeError ):
208+ raise DeployError ('existing-ip must be an IPv4 address.' ) from None
209+ if not re .fullmatch (r'SHA256:[A-Za-z0-9+/]{43}' , c ['existing-host-key' ]):
210+ raise DeployError ('existing-host-key must be an ed25519 SHA256: fingerprint.' )
211+
212+
198213def validate (c ):
199214 from .kms import validate as validate_kms
200215 validate_kms (c )
201216 if c ['schema-version' ] != 1 :
202217 raise DeployError ('Only configuration schema 1 is supported.' )
203218 provider = c ['provider-compute' ]
204219 if provider not in PROVIDER_DEFAULTS :
205- raise DeployError ('Supported compute providers are oci, digitalocean, gcp, hcloud and aws .' )
220+ raise DeployError ('Supported compute providers are oci, digitalocean, gcp, hcloud, aws and existing .' )
206221 if not re .fullmatch (r'[a-z][a-z0-9-]{0,39}' , str (c .get ('profile' , '' ))):
207222 raise DeployError ('Profile must be a lowercase identifier of at most 40 characters.' )
208223 required = {
209224 'hcloud' : ['hcloud-server-type' , 'hcloud-location' , 'hcloud-image' ],
225+ 'existing' : ['existing-ip' , 'existing-host-key' ],
210226 'aws' : ['aws-profile' , 'aws-region' , 'aws-subnet-id' , 'aws-instance-type' , 'aws-root-volume-type' ],
211227 'oci' : ['oci-config-file-profile' , 'oci-compartment-id' , 'oci-subnet-id' , 'oci-availability-domain' ],
212228 'digitalocean' : ['digitalocean-account-id' , 'digitalocean-region' ,
@@ -221,6 +237,8 @@ def validate(c):
221237 raise DeployError ('Invalid compute provider identifier.' )
222238 if provider == 'aws' :
223239 validate_aws (c )
240+ if provider == 'existing' :
241+ validate_existing (c )
224242 if provider == 'hcloud' and c .get ('compute-network-mode' ) != 'none' :
225243 raise DeployError ('Hetzner supports compute-network-mode none only.' )
226244 if 'digitalocean-vpc-id' in c and (not isinstance (c ['digitalocean-vpc-id' ], str ) or not re .fullmatch (r'[A-Za-z0-9-]+' , c ['digitalocean-vpc-id' ])):
0 commit comments