Error
Error creating application autoscaling target: ValidationException: ECS service doesn’t exist: service/AAA
Encountered this type of dependency issue before, but re-run terraform plan/apply usually can fix it, but not lucky this time :-)
After having a quick look, and found out the module depends_on
(dependency between terraform modules) only officially supported for Terraform version 0.13 - hashicorp/terraform#10462 - but we’re on version 0.12 unfortunately.
Workaround
Found the workaround here:
The key insight here is that variables are nodes in the dependency graph too, and so can use them as a “hub” for passing dependencies across the module boundary.
Example
e.g.
In module A (e.g. with resource aws_appautoscaling_target
)
- Add the following in
variables.yml
:
1 | variable "mod_depends_on" { |
- Add
depends_on
for resource Aaws_appautoscaling_target
(as depends_on can refer directly to variables in Terraform version 0.12)
1 | resource "aws_appautoscaling_target" "target" { |
In module B (e.g. with resource aws_ecs_service
):
Just need to add the following:
1 | mod_depends_on = [module.A] |
Reference:
https://discuss.hashicorp.com/t/tips-howto-implement-module-depends-on-emulation/2305