https://pulumi.com logo
#general
Title
# general
l

lemon-ambulance-1111

12/03/2023, 5:30 PM
Hi team, i am trying to get configuration from below template yaml. When i run pulumi up it's not picking the configuration and throwing a error like instancetype is not set main.py
Copy code
python
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 Project
d

dry-keyboard-94795

12/03/2023, 6:46 PM
Can you try with
config.require_object(...)
instead, which is needed for getting structured data from the config
Though there's a few things I'm unsure of in the code you've posted. Can you share the guide you're following please?
s

salmon-account-74572

12/05/2023, 5:10 PM
You have your configuration in a file named
Pulumi.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
.
3 Views