-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
depends_on module not working as expected #10883
Comments
Modules are only visible in the module they're used. Within your environment module, the "network" module doesn't exist (it exists in the parent). I tried with a couple modules and resources in the same module and did you exact line above and it worked great. |
@mitchellh What is the proper way of handling such cases? I want true isolated modules and also using some modules from 3rd party projects as a dependency which makes impossible to create nested structures. |
Alright to clarify my deleted post, what I did was use a Rakefile, and split my parts of my infrastructure up into multiple plans and apply's. I have one Rake task plan and apply my network specific stuff, then another for my security groups, and a 3rd for my compute infrastructure. That kind of logically splits it up, even though they're in the same main.tf calling those modules. This is my workaround until Terraform has a module depends_on function. This may seem over the top, but it works. namespace :terraform do
namespace :openstack do
desc 'Deploy the Full Stack, erythang'
task deploy: ['terraform:openstack:deploy_infra', 'terraform:openstack:deploy_secgrps', 'terraform:openstack:deploy_compute']
desc 'Use Terraform to deploy the infrastructure'
task deploy_infra: ['terraform:openstack:plan_infra', 'terraform:openstack:apply_infra']
task :plan_infra do
sh %(
terraform plan \
-target=module.splunk_network_infra \
-out=terraform_state/splunk_deployment_infra.tfplan \
-state=terraform_state/terraform_infra.tfstate
)
end
task :apply_infra do
sh %(
terraform apply \
-target=module.splunk_network_infra \
-state-out=terraform_state/terraform_infra.tfstate \
terraform_state/splunk_deployment_infra.tfplan
)
end
desc 'Use Terraform to deploy the security groups'
task deploy_secgrps: ['terraform:openstack:plan_secgrps', 'terraform:openstack:apply_secgrps']
task :plan_secgrps do
sh %(
terraform plan \
-target=module.splunk_security_group \
-out=terraform_state/splunk_deployment_secgrps.tfplan \
-state=terraform_state/terraform_secgrps.tfstate
)
end
task :apply_secgrps do
sh %(
terraform apply \
-target=module.splunk_security_group \
-state-out=terraform_state/terraform_secgrps.tfstate \
terraform_state/splunk_deployment_secgrps.tfplan
)
end
desc 'Use Terraform to deploy the compute instances'
task deploy_compute: ['terraform:openstack:plan_compute', 'terraform:openstack:apply_compute']
task :plan_compute do
sh %(
terraform plan \
-target=module.splunk_instance_01 \
-out=terraform_state/splunk_deployment_compute.tfplan \
-state=terraform_state/terraform_compute.tfstate
)
end
task :apply_compute do
sh %(
terraform apply \
-target=module.splunk_instance_01 \
-state-out=terraform_state/terraform_compute.tfstate \
terraform_state/splunk_deployment_compute.tfplan
)
end
desc 'Destroy the Full Stack, erythang'
task destroy: ['terraform:openstack:destroy_infra', 'terraform:openstack:destroy_secgrps', 'terraform:openstack:destroy_compute']
desc 'Use Terraform to destroy the infrastructure'
task destroy_infra: ['terraform:openstack:plan_destroy_infra', 'terraform:openstack:apply_destroy_infra']
task :plan_destroy_infra do
sh %(
terraform plan \
-destroy \
-target=module.splunk_network_infra \
-out=terraform_state/splunk_destroy_infra.tfplan \
-state=terraform_state/terraform_infra.tfstate
)
end
task :apply_destroy_infra do
sh %(
terraform apply \
-target=module.splunk_network_infra \
-state-out=terraform_state/terraform_infra.tfstate \
terraform_state/splunk_destroy_infra.tfplan
)
end
desc 'Use Terraform to destroy the security groups'
task destroy_secgrps: ['terraform:openstack:plan_destroy_secgrps', 'terraform:openstack:apply_destroy_secgrps']
task :plan_destroy_secgrps do
sh %(
terraform plan \
-destroy \
-target=module.splunk_security_group \
-out=terraform_state/splunk_destroy_secgrps.tfplan \
-state=terraform_state/terraform_secgrps.tfstate
)
end
task :apply_destroy_secgrps do
sh %(
terraform apply \
-target=module.splunk_security_group \
-state-out=terraform_state/terraform_secgrps.tfstate \
terraform_state/splunk_destroy_secgrps.tfplan
)
end
desc 'Use Terraform to destroy the compute instances'
task destroy_compute: ['terraform:openstack:plan_destroy_compute', 'terraform:openstack:apply_destroy_compute']
task :plan_destroy_compute do
sh %(
terraform plan \
-destroy \
-target=module.splunk_instance_01 \
-out=terraform_state/splunk_destroy_compute.tfplan \
-state=terraform_state/terraform_compute.tfstate
)
end
task :apply_destroy_compute do
sh %(
terraform apply \
-target=module.splunk_instance_01 \
-state-out=terraform_state/terraform_compute.tfstate \
terraform_state/splunk_destroy_compute.tfplan
)
end
end
end |
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. |
Hi
I was looking forward to using the
depends_on
module feature [10076].However it is not working as expected I think.
So my setup:
I have two modules,
network
andenvironment
In the
environment
module I have some resources defined(ec2 instances) that needs to depend on thenetwork
module being fully created.For each resource that depends on
network
module have added:Expected:
Network module is created and then my resources that depends on it are created
Actual:
I feel this is an issue but would like to be proven wrong :)
The text was updated successfully, but these errors were encountered: