hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.79k stars 9.14k forks source link

aws_instance to any output resourse depends_on reverse fails on restore if tf state still stores deleted instance #17106

Closed vassav-nn closed 8 months ago

vassav-nn commented 3 years ago

Hi there,

Terraform CLI and Terraform AWS Provider Version

0.12.28 provider.aws: version = "~> 3.23"

Affected Resource(s)

Please list the resources as a list, for example:

Expected Behavior

Restore ec2 instances and recreate of dns recors for code like:

modules/aws/ec2 uses public resource "aws_instance" "this"

module "ec2_servers" {
  source                 = "../../modules/aws/ec2"
  instance_count         = var.aws.srv.count > 0 ? var.aws.srv.count : 0
  ... other params ...
}

resource "aws_route53_record" "srv" {
  count   = var.aws.srv.count > 0 ? var.aws.srv.count : 0
  zone_id = data.aws_route53_zone.dns.zone_id
  name    = "srv${count.index}.${data.aws_route53_zone.dns.name}"
  type    = "A"
  ttl     = "300"
  records = ["${module.ec2_servers.private_ip[count.index]}"]
  depends_on = [module.ec2_servers]
}

Actual Behavior

Got error

on srv.tf line 178, in resource "aws_route53_record" "srv":
 178:   records = ["${module.ec2_servers.private_ip[count.index]}"]
----------------
count.index is 1
module.ec2_servers.private_dns is tuple with 1 element
 The given key does not identify an element in this collection value.

Same for use any output resourse

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply Creates resources

  2. manually terminate es2 and delete records

  3. terraform apply

Important Factoids

Err can be not reproduces if depends resource is exists, it vill restore ec2 and upd record

github-actions[bot] commented 9 months ago

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

github-actions[bot] commented 7 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.