EC2 · Compute

EC2Instance

Manage EC2 instances and their declared runtime configuration.

Generic driverUniform lifecycle
Scope
Regional
Spec fields
11
Outputs
8
Lookup
Supported

Resource definition

What this resource looks like

This is the CUE shape a Praxis template uses to declare a EC2Instance. The resource key is local to the template; metadata.name supplies its stable Praxis identity.

CUE example
resources: app: {
  apiVersion: "praxis.io/alpha"
  kind: "EC2Instance"
  metadata: {name: "payments-api", labels: {}}
  spec: {
    region: "us-west-2"
    imageId: "ami-0123456789abcdef0"
    instanceType: "t3.small"
    subnetId: "${resources.appSubnet.outputs.subnetId}"
    securityGroupIds: ["${resources.appSecurity.outputs.groupId}"]
    tags: environment: "prod"
  }
}

Desired state

Configuration

The spec block accepts 11 fields. 5 are required by the schema; fields with defaults can be omitted.

regionRequired

Region.

string
String
imageIdRequired

Image ID.

string & (=~"^ami-[a-f0-9]{8,17}$" | =~"^ssm:
Enum
instanceTypeRequired

Instance Type.

string
String
keyNameOptional

Key Name.

string
String
subnetIdRequired

Subnet ID.

string
String
securityGroupIdsOptional

Security Group IDs.

[...string] | *[]
ListDefault []
userDataOptional

User Data.

string
String
iamInstanceProfileOptional

Iam Instance Profile.

string
String
rootVolumeOptional

Root Volume.

{ sizeGiB: int & >=1 & <=16384 | *20 volumeType: "gp2" | "gp3" | "io1" | "io2" | "st1" | "sc1" | *"gp3" encrypted: bool | *true }
Object
monitoringOptional

Monitoring.

bool | *false
BooleanDefault false
tagsRequired

Tags.

[string]: string
Map

Observed values

Outputs

Praxis records these values after observation. A dependent resource can read one with ${resources.<name>.outputs.<field>}.

instanceIdString
privateIpAddressString
publicIpAddressString · optional
privateDnsNameString
arnString
stateString
subnetIdString
vpcIdString

Read without ownership

Data-source lookup

A data block reads an existing EC2Instance and exposes its outputs without storing lifecycle state. The generic filter surface accepts id, name, and tag; supported combinations depend on the AWS identity used by this resource.

CUE data source
data: existing: {
  kind: "EC2Instance"
  region: "us-west-2"
  filter: {
    name: "replace-with-provider-name"
  }
}
Documented selectorsidnametag

Understand data sources and filters →

Adopt existing infrastructure

Import

Import persists Praxis state for an existing AWS resource. For this kind, supply: EC2 instance ID and region. The example starts in observed mode so Praxis reports drift without correcting it.

CLI
praxis import EC2Instance \
  --id <provider-identifier> \
  --region us-west-2 \
  --account production \
  --observe

Choose managed or observed ownership →

Canonical contract

Complete CUE schema

The field guide above is derived from this definition. The schema remains the source of truth for accepted values, defaults, validation constraints, and outputs in the current alpha revision.

Show the complete schema
schemas/aws/ec2/ec2.cue
package ec2

#EC2Instance: {
	apiVersion: "praxis.io/alpha"
	kind:       "EC2Instance"

	metadata: {
		name: string & =~"^[a-zA-Z0-9][a-zA-Z0-9._-]{0,254}$"
		labels: [string]: string
	}

	spec: {
		region:       string
		imageId:      string & (=~"^ami-[a-f0-9]{8,17}$" | =~"^ssm:///")
		instanceType: string
		keyName?:     string
		subnetId:     string
		securityGroupIds: [...string] | *[]
		userData?:           string
		iamInstanceProfile?: string
		rootVolume?: {
			sizeGiB:    int & >=1 & <=16384 | *20
			volumeType: "gp2" | "gp3" | "io1" | "io2" | "st1" | "sc1" | *"gp3"
			encrypted:  bool | *true
		}
		monitoring: bool | *false
		tags: [string]: string
	}

	outputs?: {
		instanceId:       string
		privateIpAddress: string
		publicIpAddress?: string
		privateDnsName:   string
		arn:              string
		state:            string
		subnetId:         string
		vpcId:            string
	}
}

View this schema on GitHub →