https://pulumi.com logo
Title
a

ambitious-salesmen-39356

12/17/2020, 7:10 PM
I'm having a similar experience to @creamy-engine-1851 - it is sometimes difficult to figure out how to get the data out of many of these custom types. As an example, retrieving the cluster cachenode DNS addresses from an AWS elasticache cluster is baffling me at the moment. The object is of type
elasticache.ClusterCacheNodeArrayOutput
and despite the fact that it appears to be just a slice of maps, it's not iterable.
Also, confusingly, the docs:
CacheNodes
[]ClusterCacheNode
List of node objects including id, address, port and availability_zone. Referenceable e.g. as ${aws_elasticache_cluster.bar.cache_nodes.0.address}
appear to suggest referencing via terraform syntax? lol.
Probably has a lot to do with me being in over my head with Go, admittedly.
b

billowy-army-68599

12/17/2020, 7:35 PM
@ambitious-salesmen-39356 it's not iterable because it's an output, if you wrap it in an Apple func you can iterate with it. What are you trying to do exactly?
a

ambitious-salesmen-39356

12/17/2020, 7:35 PM
Just get any and all DNS addresses out of the cluster. Memcached exposes it as a top level output, redis doesn't
b

billowy-army-68599

12/17/2020, 7:37 PM
are you trying to pass them to another resource?
a

ambitious-salesmen-39356

12/17/2020, 7:38 PM
yeah a route53 record and probably as a stack export as well.
b

billowy-army-68599

12/17/2020, 7:38 PM
can you share the code you have?
a

ambitious-salesmen-39356

12/17/2020, 7:38 PM
Well, what I was trying to do is not viable apparently =D
b

billowy-army-68599

12/17/2020, 7:39 PM
ha! maybe some pseudo code for wyat you're trying to do?
a

ambitious-salesmen-39356

12/17/2020, 7:39 PM
if this was python...
deployment.clusterDNS = cluster.CacheNodes[0].address
it's a single node cluster, I'd have to range loop it for a multi-node naturally
I have no formal developer/CS background so I probably struggle more with this sort of thing than most.
b

billowy-army-68599

12/17/2020, 7:42 PM
me neither, we can struggle through this together 🙂 give me a little while I'll try some stuff out
a

ambitious-salesmen-39356

12/17/2020, 7:47 PM
You really have been exceptionally helpful. Sadly I sent in the registration forms for my firstborn many years ago, so I'll have to find something else to name in your honour
😂 1
b

billowy-army-68599

12/17/2020, 8:04 PM
can you share your memcache code @ambitious-salesmen-39356? I'm gonna try figure this out now
a

ambitious-salesmen-39356

12/17/2020, 8:04 PM
redis actually, or this would be easy 🙂
@billowy-army-68599 I actually figured it out: https://www.pulumi.com/docs/intro/concepts/programming-model/#lifting
deployment.clusterDNS *=* cluster.CacheNodes.Index(<http://pulumi.Int|pulumi.Int>(0)).Address().Elem()
b

billowy-army-68599

12/17/2020, 9:29 PM
oh wow, I was just fighting this!
I was using the index and the nodes as well, I'll post my solution in a bit but I'd love to see yours too
a

ambitious-salesmen-39356

12/17/2020, 9:30 PM
I mean, that's it really
r53RecordName := pulumi.String(fmt.Sprintf("<http://redis.%s.veem.com|redis.%s.veem.com>", pulumi.String(ev.Get("name"))))

	_, err = route53.NewRecord(ctx, clusterName, &route53.RecordArgs{
		Name:   r53RecordName,
		Ttl:    <http://pulumi.Int|pulumi.Int>(300),
		Type:   pulumi.String("CNAME"),
		ZoneId: pulumi.String("<REDACTED>"),
		Records: pulumi.StringArray{
			cluster.CacheNodes.Index(<http://pulumi.Int|pulumi.Int>(0)).Address().Elem(),
		},
	}, pulumi.Parent(deployment))
b

billowy-army-68599

12/17/2020, 9:32 PM
love it!
a

ambitious-salesmen-39356

12/17/2020, 9:35 PM
I just pulled it from the programming model docs and prayed ¯\_(ツ)_/¯