mammoth-memory-47255
02/24/2025, 2:17 PMgreat-park-73778
02/24/2025, 2:26 PMconfig:
myproject:servers:
- name: "Server1"
ip: "192.168.1.1"
location: "New York"
- name: "Server2"
ip: "192.168.1.2"
location: "London"
- name: "Server3"
ip: "192.168.1.3"
location: "Tokyo"
Typescript
import * as pulumi from "@pulumi/pulumi";
const config = new pulumi.Config();
const servers: { name: string, ip: string, location: string }[] = config.getObject("servers") || [];
servers.forEach((server, index) => {
console.log(`Server ${index + 1}:`);
console.log(` Name: ${server.name}`);
console.log(` IP: ${server.ip}`);
console.log(` Location: ${server.location}`);
});
C#
public class Server
{
public string Name { get; set; }
public string Ip { get; set; }
public string Location { get; set; }
}
var config = new Config();
var servers = config.GetObject<List<Server>>("servers") ?? new List<Server>();
foreach (var server in servers)
{
Console.WriteLine($"Server: {server.Name}, IP: {server.Ip}, Location: {server.Location}");
}
mammoth-memory-47255
02/24/2025, 2:31 PMgetObject
can get arrays as well?mammoth-memory-47255
02/24/2025, 2:32 PMAt this time, configuration specifications are not supported for structured configuration.This is unfortunate 😕
great-park-73778
02/24/2025, 2:35 PMconfig:
myproject:servers: '[{}]'
Sorry man dont have much more.No matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by