OCI Compute
cloudspells.providers.oci.compute
Compute Instance spell for CloudSpells.
Provides ComputeInstance, which deploys a single OCI VM into a chosen VCN
subnet and attaches one or more block volumes for persistent storage.
Key behaviours:
- Defaults to Oracle Linux 8 (latest image for the chosen shape).
- Deploys to the VCN's private subnet by default (not directly internet-facing).
- Adds a minimal SSH ingress rule to the appropriate security list (port 22 from the public subnet CIDR for bastion-host access).
- Auto-generates an RSA 4096-bit SSH key pair when no key is supplied; the keys are exported as Pulumi secrets.
- Accepts a list of
VolumeSpecobjects to attach any number of block volumes; defaults to a single 100 GiB balanced-performance data volume. - Calls
Vcn.finalize_networkautomatically.
Exports
ComputeInstance: Single-VM component resource with multi-volume support.
ComputeInstance
Bases: BaseResource, AbstractCompute
OCI Compute Instance with one or more attached block volumes.
Creates a single VM in the chosen VCN subnet together with the block
volumes described by the volumes parameter. Each VolumeSpec in the
list produces one oci.core.Volume and one oci.core.VolumeAttachment;
all are created at the same time as the instance.
Attributes:
| Name | Type | Description |
|---|---|---|
vcn |
Vcn | VcnRef
|
The |
shape |
Input[str]
|
Compute shape (e.g. |
ocpus |
Input[float]
|
Number of OCPUs allocated to the instance. |
memory_in_gbs |
Input[float]
|
RAM in GiB allocated to the instance. |
ssh_public_key |
str
|
OpenSSH public key installed in |
ssh_private_key |
str | None
|
Corresponding private key string, or |
image_id |
Input[str] | None
|
OCID of the boot image used by the instance. |
boot_volume_size_in_gbs |
Input[int]
|
Size of the boot volume in GiB. |
volumes_spec |
list[VolumeSpec]
|
Resolved list of |
instance |
Instance
|
The underlying |
block_volumes |
list[Volume]
|
Ordered list of |
volume_attachments |
list[VolumeAttachment]
|
Ordered list of |
id |
Output[str]
|
|
auto_generated_keys |
bool
|
|
fault_domain |
str | None
|
Fault domain the instance is placed in, or |
hostname_label |
str | None
|
DNS hostname for the primary VNIC, or |
preserve_boot_volume |
bool
|
Whether the boot volume is retained after instance termination. |
Usage patterns:
-
Minimal — single default data volume, auto-generated SSH keys:
python vcn = Vcn(name="lab", compartment_id=comp_id, stack_name="prod") instance = ComputeInstance( name="web", vcn=vcn, compartment_id=comp_id, ) private_key = instance.get_ssh_private_key() -
Multiple volumes with explicit performance tiers:
python instance = ComputeInstance( name="app", vcn=vcn, compartment_id=comp_id, volumes=[ VolumeSpec(size_in_gbs=200, label="app"), VolumeSpec(size_in_gbs=500, label="db", vpus_per_gb=VolumeSpec.PERF_HIGH), VolumeSpec(size_in_gbs=100, label="logs", vpus_per_gb=VolumeSpec.PERF_LOW), ], ) db_vol_id = instance.get_volume_id("db") -
Custom shape and boot volume:
python instance = ComputeInstance( name="heavy", vcn=vcn, compartment_id=comp_id, shape="VM.Standard.E4.Flex", ocpus=8, memory_in_gbs=128, boot_volume_size_in_gbs=100, volumes=[VolumeSpec(size_in_gbs=1000, label="data", vpus_per_gb=VolumeSpec.PERF_HIGH)], )
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 | |
block_volume: oci.core.Volume
property
Return the first (primary) block volume.
Provides backward compatibility for code that references
instance.block_volume directly. For multi-volume setups use
block_volumes or get_volume instead.
Returns:
| Type | Description |
|---|---|
Volume
|
The first |
volume_attachment: oci.core.VolumeAttachment
property
Return the first (primary) volume attachment.
Provides backward compatibility for code that references
instance.volume_attachment directly. For multi-volume setups use
volume_attachments or get_volume_attachment instead.
Returns:
| Type | Description |
|---|---|
VolumeAttachment
|
The first |
__init__(name: str, compartment_id: pulumi.Input[str], vcn: Vcn | VcnRef, stack_name: str | None = None, ssh_public_key: pulumi.Input[str] | None = None, shape: pulumi.Input[str] = 'VM.Standard.E4.Flex', ocpus: pulumi.Input[float] = 1, memory_in_gbs: pulumi.Input[float] = 16, image_id: pulumi.Input[str] | None = None, os_name: str = 'oracle', subnet: SubnetTier = SUBNET_PRIVATE, boot_volume_size_in_gbs: pulumi.Input[int] = 50, boot_volume_vpus_per_gb: int = 10, volumes: Sequence[VolumeSpec] | None = None, nsg_ids: list[pulumi.Input[str]] | None = None, nsg: Nsg | None = None, user_data: str | bytes | None = None, defined_tags: dict[str, Any] | None = None, fault_domain: str | None = None, hostname_label: str | None = None, private_ip: str | None = None, skip_source_dest_check: bool = False, is_pv_encryption_in_transit: bool = False, preserve_boot_volume: bool = False, recovery_action: str | None = None, baseline_ocpu_utilization: str | None = None, dedicated_vm_host_id: str | None = None, capacity_reservation_id: str | None = None, opts: pulumi.ResourceOptions | None = None) -> None
Create a compute instance with one or more attached block volumes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logical name for the instance (e.g. |
required |
compartment_id
|
Input[str]
|
OCID of the OCI compartment to deploy into. |
required |
vcn
|
Vcn | VcnRef
|
|
required |
stack_name
|
str | None
|
Pulumi stack name. Defaults to
|
None
|
ssh_public_key
|
Input[str] | None
|
OpenSSH public key string to install on the
instance. When |
None
|
shape
|
Input[str]
|
OCI compute shape (default: |
'VM.Standard.E4.Flex'
|
ocpus
|
Input[float]
|
Number of OCPUs (default: |
1
|
memory_in_gbs
|
Input[float]
|
Memory in GiB (default: |
16
|
image_id
|
Input[str] | None
|
Explicit boot image OCID. When provided, |
None
|
os_name
|
str
|
Friendly OS name used to auto-discover the latest
image when |
'oracle'
|
subnet
|
SubnetTier
|
Which VCN tier to place the instance in. Use the
constants |
SUBNET_PRIVATE
|
boot_volume_size_in_gbs
|
Input[int]
|
Boot volume size in GiB (default:
|
50
|
volumes
|
Sequence[VolumeSpec] | None
|
Ordered list of |
None
|
nsg_ids
|
list[Input[str]] | None
|
List of Network Security Group OCIDs to attach to the
instance VNIC. When |
None
|
nsg
|
Nsg | None
|
Shorthand for single-NSG deployments. When supplied, sets
|
None
|
boot_volume_vpus_per_gb
|
int
|
Boot volume performance tier. Use
|
10
|
user_data
|
str | bytes | None
|
Cloud-init script as a plain |
None
|
defined_tags
|
dict[str, Any] | None
|
OCI defined tags applied to the instance and all
block volumes, in |
None
|
fault_domain
|
str | None
|
Explicit fault domain for placement
(e.g. |
None
|
hostname_label
|
str | None
|
DNS hostname registered for the primary VNIC.
Must be unique within the subnet. When |
None
|
private_ip
|
str | None
|
Explicit private IP address for the primary VNIC.
Must fall within the selected subnet's CIDR. When |
None
|
skip_source_dest_check
|
bool
|
Disable the source/destination check on
the primary VNIC. Set to |
False
|
is_pv_encryption_in_transit
|
bool
|
Encrypt data in transit between
the instance and paravirtualized-attached volumes.
Defaults to |
False
|
preserve_boot_volume
|
bool
|
Keep the boot volume after the instance
is terminated. Defaults to |
False
|
recovery_action
|
str | None
|
Live-migration recovery action. Pass
|
None
|
baseline_ocpu_utilization
|
str | None
|
Burstable-instance CPU baseline.
One of |
None
|
dedicated_vm_host_id
|
str | None
|
OCID of the dedicated VM host to place
this instance on. When |
None
|
capacity_reservation_id
|
str | None
|
OCID of the capacity reservation to
consume. When |
None
|
opts
|
ResourceOptions | None
|
Pulumi resource options forwarded to the component. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Example
# Role-based shorthand — subnet inferred from NSG role
web = ComputeInstance("web-1", compartment_id=comp_id, vcn=vcn, nsg=web_nsg)
db = ComputeInstance("db-1", compartment_id=comp_id, vcn=vcn, nsg=db_nsg,
volumes=[VolumeSpec(size_in_gbs=200, label="data")])
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | |
export() -> None
Export standard compute instance stack outputs.
Publishes instance OCID, private IP, all block volume OCIDs, and SSH
public key under keys derived from the spell's logical name. The SSH
private key is exported as a Pulumi secret only when it was
auto-generated. Each volume is exported under
{name}_{label}_volume_id.
Example
instance = ComputeInstance(
name="app",
vcn=vcn,
compartment_id=comp_id,
volumes=[
VolumeSpec(size_in_gbs=100, label="data"),
VolumeSpec(size_in_gbs=500, label="db"),
],
)
instance.export()
# Exports: app_id, app_private_ip,
# app_data_volume_id, app_db_volume_id,
# app_ssh_public_key,
# app_ssh_private_key (secret, only if auto-generated)
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
get_private_ip() -> pulumi.Output[str]
Return the private IP address of the instance.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
594 595 596 597 598 599 600 | |
get_instance_id() -> pulumi.Output[str]
Return the OCID of the compute instance.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
602 603 604 605 606 607 608 | |
get_block_volume_id() -> pulumi.Output[str]
Return the OCID of the first (primary) block volume.
Provided for backward compatibility. For multi-volume setups use
get_volume_id or get_all_volume_ids.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
610 611 612 613 614 615 616 617 618 619 | |
get_volume_id(label: str) -> pulumi.Output[str]
Return the OCID of the block volume with the given label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If no volume with the given label exists. |
Example
db_vol_id = instance.get_volume_id("db")
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 | |
get_disk_id(label: str) -> pulumi.Output[str]
Return the OCID of the block volume with the given label.
Satisfies AbstractCompute.get_disk_id. Delegates to
get_volume_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If no volume with the given label exists. |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | |
get_volume(label: str) -> oci.core.Volume
Return the oci.core.Volume resource with the given label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
Volume
|
The |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no volume with the given label exists. |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
get_volume_attachment(label: str) -> oci.core.VolumeAttachment
Return the oci.core.VolumeAttachment resource with the given label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
VolumeAttachment
|
The |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no volume with the given label exists. |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
get_all_volume_ids() -> list[pulumi.Output[str]]
Return a list of OCIDs for all attached block volumes.
The list order matches the order of the volumes parameter passed
at construction time.
Returns:
| Type | Description |
|---|---|
list[Output[str]]
|
List of |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
696 697 698 699 700 701 702 703 704 705 | |
get_ssh_public_key() -> str
Return the SSH public key installed on the instance.
Returns:
| Type | Description |
|---|---|
str
|
OpenSSH public key string (auto-generated or caller-supplied). |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
707 708 709 710 711 712 713 | |
get_ssh_private_key() -> str | None
Return the SSH private key if it was auto-generated.
Returns:
| Type | Description |
|---|---|
str | None
|
PEM-encoded private key string when keys were auto-generated, |
str | None
|
or |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/compute.py
715 716 717 718 719 720 721 722 | |