https://pulumi.com logo
Title
f

fancy-spoon-7206

07/18/2022, 5:18 PM
Is there a simple way to export a slice of a struct?
type subnet struct {
		Id pulumi.StringOutput
		Az string
	}

	publicSubnet := make([]subnet, 0, 1)
	for index, az := range azs {
		publicSubnet = append(publicSubnet, subnet{
			Id: PublicSubnets.Index(<http://pulumi.Int|pulumi.Int>(index)),
			Az: az,
		})
	}
I would like to export publicSubnet, but that is not valid. The idea is to get an Outputs similar to
{
  "publicSubnets": [
    {
      "id": "subnet-02d7930bd",
      "az": "us-east-2a"
    },
    {
      "id": "subnet-0a89e59bb",
      "az": "us-east-2b"
    },
    {
      "id": "subnet-04658194f",
      "az": "us-east-2c"
    }
  ],
  "privateSubnets": [
    {
      "id": "subnet-00a9f3a9d6",
      "az": "us-east-2a"
    },
    {
      "id": "subnet-026eed9351,
      "az": "us-east-2b"
    },
    {
      "id": "subnet-0bfabcc5f666637c1",
      "az": "us-east-2c"
    }
  ]
}
b

bored-oyster-3147

07/19/2022, 11:44 PM
You need to make your subnet array an InputList<> or InputArray<> type, I don't remember what it's called in your sdk. But pulumi provides an Input collection type and as the error says, your element is not of the Input type.
Or the Output collection type more specifically, but Inputs cast to Outputs so both would work here.