suriya
July 27, 2021, 1:00pm
1
I am trying to add tags for existing resources using default_tags. but it is not getting created. but the same is working when creating new resources. not using any other tags for resources.
TF version - 1.0
AWS provider version - v3.51.0
provider "aws" {
region = var.aws-region
default_tags {
tags = {
env = "dev"
owner = "example"
team = "devops"
contact = "devops@example.com
}
}
}
On your existing resources having you tried something similar to:
tags = merge(
var.default_tags,
{
Name = “MyASG”
},
)
}
As you haven’t posted all your code or the error you are receiving, the only thing I can currently assume is you haven’t merged the default tags, in to the resource tags in to your existing resources.
If you have, please provide more details, code, error messages etc. so we can better assist.
Another question would be, are all these existing resources in the same directory as this code your building for default tags?
suriya
August 26, 2021, 1:29pm
3
@jammyshaw
Thanks for your reply on this. I find the issue related to my question. This is only with Redis resource. Looks like AWS api is not currently supporting this. So there is no way to do it via terraform.
opened 07:45PM - 07 Sep 17 UTC
closed 03:51PM - 04 Sep 19 UTC
bug
service/elasticache
### Terraform Version
Terraform v0.10.3
### Affected Resource(s)
AWS Provid… er
- aws_elasticache_replication_group
### Terraform Configuration Files
```
#original
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "bmcachetest"
replication_group_description = "${module.tags.name_prefix}cache"
node_type = "${var.node_type}"
port = 6379
parameter_group_name = "${aws_elasticache_parameter_group.redis.name}"
automatic_failover_enabled = true
subnet_group_name = "${var.cache_subnet_group}"
security_group_ids = ["${data.aws_security_group.redis_sg.id}"]
maintenance_window = "sun:09:00-sun:11:00" # UTC
cluster_mode {
replicas_per_node_group = 1
num_node_groups = 2
}
}
```
Original aws_elasticache_replication_group is created without tags with no tags. Resource is then updated with tags.
```
# Updated resource
resource "aws_elasticache_replication_group" "redis" {
replication_group_id = "bmcachetest"
replication_group_description = "${module.tags.name_prefix}cache"
node_type = "${var.node_type}"
port = 6379
parameter_group_name = "${aws_elasticache_parameter_group.redis.name}"
automatic_failover_enabled = true
subnet_group_name = "${var.cache_subnet_group}"
security_group_ids = ["${data.aws_security_group.redis_sg.id}"]
maintenance_window = "sun:09:00-sun:11:00" # UTC
cluster_mode {
replicas_per_node_group = 1
num_node_groups = 2
}
tags {
Owner = "${module.tags.owner}"
Service = "${module.tags.service}"
Team = "${module.tags.team}"
Environment = "${module.tags.environment}"
Description = "${module.tags.description}"
Terraform = "${path.root}"
autoFailover = "${var.autoFailover}"
Slack = "${var.slack_channel}"
}
}
```
### Terraform output
```
aws_elasticache_parameter_group.redis: Refreshing state... (ID: bm-redis-params)
data.aws_security_group.redis_sg: Refreshing state...
aws_elasticache_replication_group.redis: Refreshing state... (ID: bmcachetest)
module.service.aws_elasticache_replication_group.redis: Modifying... (ID: bmcachetest)
tags.%: "0" => "8"
tags.Description: "" => "userstore cacheops"
tags.Environment: "" => "test"
tags.Owner: "" => "ops@group.com"
tags.Service: "" => "userstoreops"
tags.Slack: "" => "homerecs-jobs-devs"
tags.Team: "" => "ops"
tags.Terraform: "" => "/Users/bm/git/terraform-scripts/services/aws/userstore/test"
tags.autoFailover: "" => "true"
module.service.aws_elasticache_replication_group.redis: Modifications complete after 0s (ID: bmcachetest)
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
```
### Expected Behavior
When updating an aws_elasticache_replication_group existing tags or with new tags node associated with replication group will modify, add, or delete.
### Actual Behavior
When updating an aws_elasticache_replication_group tags are not updated. Terraform state is updated with new tags however tags are not updated on nodes associated with replication group.
### Steps to Reproduce
Please list the steps required to reproduce the issue, for example:
1. Create an aws_elasticache_parameter_group with or without tags
2. `terraform apply`
3. Update aws_elasticache_parameter_group resource with tags.
4. `terraform apply`
5. inspect tags on aws_elasticache_parameter_group
### Factoid
Tags are correctly applied only during creation of resource.
Thanks
Suriya