lemon-ambulance-1111
12/03/2023, 5:30 PMpython
import pulumi
from pulumi_aws import ec2
# Define your Pulumi stack
class MyStack(pulumi.Stack):
def __init__(self):
super().__init__()
# Get configuration values from Pulumi
config = pulumi.Config()
# Get necessary configuration values from Pulumi template.yaml
instance_type = config.require("instanceType")
ami = config.require("ami")
# Create an AWS EC2 instance
instance = ec2.Instance(
"my-instance",
instance_type=instance_type,
ami=ami,
tags={"Name": "MyInstance"},
)
# Export the instance ID for reference
self.instance_id = instance.id
# Create an instance of the stack
stack = MyStack()
# Export the instance ID
pulumi.export("instanceId", stack.instance_id)
Pulumi.template.yaml
config:
awsregion
default: us-west-2
instanceType:
description: "EC2 instance type"
default: "t2.micro"
ami:
description: "AMI ID for the instance"
default: "ami-12345678" # Replace with an appropriate AMI ID
```
Pulumi.yaml
name: my-pulumi-project
runtime: python
description: My Pulumi Projectdry-keyboard-94795
12/03/2023, 6:46 PMconfig.require_object(...)
instead, which is needed for getting structured data from the configdry-keyboard-94795
12/03/2023, 6:49 PMsalmon-account-74572
12/05/2023, 5:10 PMPulumi.template.yaml
, which would only be used if you had a Pulumi stack named “template”. Pulumi templates only work with pulumi new
, so my advice to you would be…
1. Use pulumi stack init
to create a stack.
2. Use pulumi stack select <name>
to select the stack you just created.
3. Use pulumi config set <key> <value>
to set the configuration values (like pulumi config set instanceType t2.micro
).
4. Then run pulumi up
.