Skip to content
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

null ressource not destroying when used as a module #29161

Closed
FernandoDMeza opened this issue Jul 14, 2021 · 2 comments
Closed

null ressource not destroying when used as a module #29161

FernandoDMeza opened this issue Jul 14, 2021 · 2 comments

Comments

@FernandoDMeza
Copy link

I'm using null resource to create views in AWS Athena by running aws cli commands and they get properly created and destroyed with the apply and destroy commands. But if I remove/comment the resource it doesn't run the command, to put you in context here is the code:

Module

`resource "null_resource" "views" {

triggers = {
md5 = filemd5("queries/${var.sql_file}")
athena_results_bucket = var.athena_results_bucket
athena_database = var.athena_database
sql_file = var.sql_file
}

provisioner "local-exec" {
command = <<EOF
aws athena start-query-execution
--output json
--query-string file://queries/${var.sql_file}
--query-execution-context "Database=${self.triggers.athena_database}"
--result-configuration "OutputLocation=s3://${self.triggers.athena_results_bucket}"
EOF
}

provisioner "local-exec" {
when = destroy
command = <<EOF
aws athena start-query-execution
--output json
--query-string 'DROP VIEW IF EXISTS ${replace(self.triggers.sql_file,".sql","")}'
--query-execution-context "Database=${self.triggers.athena_database}"
--result-configuration "OutputLocation=s3://${self.triggers.athena_results_bucket}"
EOF
working_dir = path.module
}
}`

Main using the module
`module view {
source = "./build"

athena_results_bucket = "bucket.athena-results"
athena_database = "extract"
sql_file = "view.sql"
}

module another_view {
source = "./build"

athena_results_bucket = "bucket.athena-results"
athena_database = "extract"
sql_file = "view_2.sql"
}`

By commenting any of the modules after apply, it should just run the second provider in the resource, but it doesn't.

@jbardin
Copy link
Member

jbardin commented Jul 14, 2021

Duplicate of #13549

@jbardin jbardin marked this as a duplicate of #13549 Jul 14, 2021
@jbardin jbardin closed this as completed Jul 14, 2021
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants