PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 5, 2022

[FIXED] How can I get cache_nodes address from ElastiCache in Terraform?

 September 05, 2022     amazon-elasticache, amazon-web-services, redis, terraform     No comments   

Issue

In Terraform, I am creating a single ElastiCache cluster:

resource "aws_elasticache_cluster" "api" {
  cluster_id           = var.cluster_id
  engine               = var.engine
  node_type            = var.node_type
  num_cache_nodes      = 1
  parameter_group_name = "default.redis3.2"
  engine_version       = "3.2.4"
  port                 = 6379
  subnet_group_name    = var.subnet_group_name
}

I am wondering how I can access the address attribute exported by cache_nodes

Is either of the following sufficient?

output "redis_host1" {
  value = aws_elasticache_cluster.api.cache_nodes["address"]
}

output "redis_host2" {
  value = aws_elasticache_cluster.api.cache_nodes.address
}

Just looking for some clarification, please.


Solution

cache_nodes is a list. So you have to specify index of the node first, e.g.:

output "redis_host1" {
  value = aws_elasticache_cluster.api.cache_nodes[0].address
}

output "redis_host2" {
  value = aws_elasticache_cluster.api.cache_nodes[1].address
}

or just return addresses as list:

output "redis_hosts" {
  value = aws_elasticache_cluster.api.cache_nodes[*].address
}


Answered By - Marcin
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing