https://pulumi.com logo
#golang
Title
r

refined-pilot-45584

06/19/2023, 2:34 PM
How does one append or add new items to a custom Pulumi Array Type? For example if I have a Group of Network Endpoint Backends and I want to keep adding multiple NEGs to a Group. I can’t use “append” as it says append will only work with a Slice, naturally.
b

billowy-army-68599

06/19/2023, 3:23 PM
@refined-pilot-45584 you need to use the
BackendArrayInput{}
type, which will allow you to append to an array:
Copy code
var iTypes = pulumi.StringArray{}
iTypes = append(iTypes, pulumi.String("t3.medium"))
r

refined-pilot-45584

06/19/2023, 3:43 PM
Thanks for the pointer again; I must admit I feel kind of stupid on this one. But I am not certain I follow the approach. I am attempting to solve in the following way.
Copy code
var BackendServiceBackendArray = &compute.BackendServiceBackendArray{}
		// LOOP START
			// DYNAMIC STUFF Create new Array Item

			newItem := &compute.BackendServiceBackendArrayInput{
				&compute.BackendServiceBackendArgs{ 
					// CONTENT
				},
			}

			// Append Item to Existing Array
			BackendServiceBackendArray = append(BackendServiceBackendArray, NewItem)
		// END LOOP
I am not 100% sure if I am using the BackendArrayInput type in the correct location here;
b

billowy-army-68599

06/19/2023, 3:49 PM
can you share your full code, so I can recreate and fix?
r

refined-pilot-45584

06/19/2023, 3:57 PM
I can. Standby.
3 Views