Hi.
Take the following module code:
resource "random_string" "awscli_output_temp_file_name" {
length = 16
special = false
}
resource "local_file" "awscli_results_file" {
depends_on = [random_string.awscli_output_temp_file_name]
filename = "${path.module}/temp/${random_string.awscli_output_temp_file_name.result}.json"
directory_permission = "0777"
file_permission = "0666"
}
data "external" "awscli_program" {
depends_on = [local_file.awscli_results_file]
program = ["${path.module}/scripts/awsWithAssumeRole.sh"]
query = {
assume_role_arn = var.assume_role_arn
role_session_name = var.role_session_name
aws_cli_commands = join(" ", var.aws_cli_commands)
aws_cli_query = var.aws_cli_query
output_file = local_file.awscli_results_file.filename
debug_log_filename = var.debug_log_filename
}
}
data "local_file" "awscli_results_file" {
depends_on = [data.external.awscli_program]
filename = data.external.awscli_program.query.output_file
ignore_changes = true
}
Has been working just fine. I run the aws cli command (to get data not yet available in Terraform via the AWS Provider) and then present that data to Terraform. For example, identify which DB instance in a cluster is the reader, or how many EC2 instances are currently running in an ASG so we can launch the new ASG with the same number of instances and have no drop in capacity. I can assume a role. Or not. All wonderful. Even I say so myself (https://registry.terraform.io/modules/digitickets/cli/aws/latest).
Since Terraform 0.15.4 (maybe 0.15.3 … not sure … skipped that version), we’ve been getting (correctly so this is not a bug but a new and valid and useful feature) the following output in our plans:
Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the last "terraform apply":
# module.rds_writer.local_file.awscli_results_file has been deleted
- resource "local_file" "awscli_results_file" {
- directory_permission = "0777" -> null
- file_permission = "0666" -> null
- filename = ".terraform/modules/rds_writer/temp/iUc1oABQ4XYczzx3.json" -> null
- id = "da39a3ee5e6b4b0d3255bfef95601890afd80709" -> null
}
Unless you have made equivalent changes to your configuration, or ignored the relevant attributes using ignore_changes, the following plan may include actions to undo or respond to these changes.
So, my question, is how do I get Terraform to not “worry” about this resource? The code is run in a pipeline, so there’s no file at the beginning of the run. I know I could enforce the name of the file in some way but the file would never be in the repo so it would always be missing.