admin管理员组

文章数量:1313001

I've refactored my Terraform repo and most of my resources are now created by a new module. The plan wants to delete and recreate the resources which I can't do, so I'm creating moved blocks to migrate the resources in the state (I have no access to the state file).

moved {
from = module.my_zones_ecr.aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

moved {
from = module.my_zones_s3.aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

moved {
from = module.my_zones_splunk_dev[0].aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

The issue is that some resources end up with the same value in the 'to' block, leading to the 'Ambiguous move statement' error.

Error: Ambiguous move statements

  on moved.tf line 771:
     moved {

A statement at moved.tf:756,1 declared that module.my_zones_ecr.aws_route53_zone.my_zone[0] moved to module.custom_eu_west_1.aws_route53_zone.my_zone[0], but this statement instead declares that module.my_zones_splunk_dev[0].aws_route53_zone.my_zone[0] moved there. Each resource instance can have moved from only one source instance.

I've already tried to specify unique addresses but it won't work:

moved {
from = module.my_zones_ecr.aws_route53_zone.my_zone[0]
to = module.regional_eu_west_1.ecr_aws_route53_zone.hosted_zone[0]

moved {
from = module.my_zones_s3.aws_route53_zone.my_zone[0]
to = module.regional_eu_west_1.s3_aws_route53_zone.hosted_zone[0]
}

Error:

Error: Resource type mismatch
This statement declares a move from module.hosted_zones_ecr.aws_route53_zone.hosted_zone[0] to
module.regional_eu_west_1.ecr_aws_route53_zone.hosted_zone[0], which is a resource instance of a different type.
Error: Resource type mismatch
This statement declares a move from module.hosted_zones_s3.aws_route53_zone.hosted_zone[0] to
module.regional_eu_west_1.s3_aws_route53_zone.hosted_zone[0], which is a resource instance of a different type.

I've refactored my Terraform repo and most of my resources are now created by a new module. The plan wants to delete and recreate the resources which I can't do, so I'm creating moved blocks to migrate the resources in the state (I have no access to the state file).

moved {
from = module.my_zones_ecr.aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

moved {
from = module.my_zones_s3.aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

moved {
from = module.my_zones_splunk_dev[0].aws_route53_zone.my_zone[0]
to = module.custom_eu_west_1.aws_route53_zone.my_zone[0]
}

The issue is that some resources end up with the same value in the 'to' block, leading to the 'Ambiguous move statement' error.

Error: Ambiguous move statements

  on moved.tf line 771:
     moved {

A statement at moved.tf:756,1 declared that module.my_zones_ecr.aws_route53_zone.my_zone[0] moved to module.custom_eu_west_1.aws_route53_zone.my_zone[0], but this statement instead declares that module.my_zones_splunk_dev[0].aws_route53_zone.my_zone[0] moved there. Each resource instance can have moved from only one source instance.

I've already tried to specify unique addresses but it won't work:

moved {
from = module.my_zones_ecr.aws_route53_zone.my_zone[0]
to = module.regional_eu_west_1.ecr_aws_route53_zone.hosted_zone[0]

moved {
from = module.my_zones_s3.aws_route53_zone.my_zone[0]
to = module.regional_eu_west_1.s3_aws_route53_zone.hosted_zone[0]
}

Error:

Error: Resource type mismatch
This statement declares a move from module.hosted_zones_ecr.aws_route53_zone.hosted_zone[0] to
module.regional_eu_west_1.ecr_aws_route53_zone.hosted_zone[0], which is a resource instance of a different type.
Error: Resource type mismatch
This statement declares a move from module.hosted_zones_s3.aws_route53_zone.hosted_zone[0] to
module.regional_eu_west_1.s3_aws_route53_zone.hosted_zone[0], which is a resource instance of a different type.
Share Improve this question edited Feb 1 at 18:01 parax asked Jan 31 at 20:55 paraxparax 1611 gold badge2 silver badges12 bronze badges 2
  • 1 Why are two addresses in the state being moved to the same address? – Matthew Schuchard Commented Jan 31 at 21:04
  • How did you even have three resources before that all referred to the same thing? What you are doing doesn't really make sense. Did you create something outside of Terraform and then import it 3 times to 3 different resources? You probably need to just pass a zoneID into each of those modules, or use a data source instead of a resource inside those modules. registry.terraform.io/providers/hashicorp/aws/latest/docs/… – Mark B Commented Feb 1 at 19:59
Add a comment  | 

1 Answer 1

Reset to default 0

In your attempt to make the addresses unique you have written the to addresses incorrectly, making Terraform think that you are intending to change the resource type.

For example, the resource type portion of the address module.regional_eu_west_1.ecr_aws_route53_zone.hosted_zone[0] is ecr_aws_route53_zone, which is different than the from address's aws_route53_zone.

To produce two unique addresses that are valid you'll need to include the ecr and s3 naming conventions either as part of the module name or as part of the resource name. From your addresses it seems like your intention is for the module to represent "everything in a region" rather than being service-specific and so I'm going to guess that the resource type name is the more appropriate solution for you in this case:

moved {
  from = module.my_zones_ecr.aws_route53_zone.my_zone[0]
  to   = module.regional_eu_west_1.aws_route53_zone.ecr[0]

moved {
  from = module.my_zones_s3.aws_route53_zone.my_zone[0]
  to   = module.regional_eu_west_1.aws_route53_zone.s3[0]
}

The two addresses I've written above assume that your regional module will contain two blocks declared with the following headers:

resource "aws_route53_zone" "ecr" {
  # ...
}

resource "aws_route53_zone" "s3" {
  # ...
}

Note that in the Terraform language it's always required to write the resource type and the resource name together when referring to the resource: aws_route53_zone.ecr and aws_route53_zone.s3. Therefore including information about the resource type as part of the name is redundant, and that is why I chose the short names "ecr" and "s3" here. You might choose to read these addresses out loud as "the Route53 zone for ECR" and "the Route53 zone for S3".

本文标签: hclAmbiguous move statement errors in TerraformStack Overflow