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

Ability to log from a module into transcript from terraform apply #20049

Open
buchs opened this issue Jan 18, 2019 · 0 comments
Open

Ability to log from a module into transcript from terraform apply #20049

buchs opened this issue Jan 18, 2019 · 0 comments

Comments

@buchs
Copy link

buchs commented Jan 18, 2019

Current Terraform Version

  • latest documented on Hashicorp website

Use-cases

  • just ordinary use of TF. You want to know that your module has run and
    maybe some other info

As an example, I have a module which optionally creates a zip archive. I would
like to know whether a zip file has been created/updated. Here is the transcript
I see from tf apply:

data.external.lambda_archive: Refreshing state...
aws_api_gateway_rest_api.send_to_sensu_api: Refreshing state... (ID: t5agem92zk)
aws_iam_role.lambda_send_to_sensu_role: Refreshing state... (ID: lambda_send_to_sensu_role)
data.aws_vpc.prod: Refreshing state...
aws_lambda_function.lambda_send_to_sensu: Refreshing state... (ID: lambda_send_to_sensu)
aws_iam_role_policy.lambda_send_to_sensu_role_policy: Refreshing state... (ID: lambda_send_to_sensu_role:lambda_send_to_sensu_role_policy)
aws_api_gateway_usage_plan.send_to_sensu_api: Refreshing state... (ID: 4vot2i)
aws_api_gateway_resource.send_to_sensu_api: Refreshing state... (ID: qfb052)
aws_api_gateway_method.send_to_sensu_api: Refreshing state... (ID: agm-t5agem92zk-qfb052-POST)
aws_api_gateway_method_settings.s: Refreshing state... (ID: t5agem92zk-prod-send/POST)
aws_api_gateway_integration.send_to_sensu_api: Refreshing state... (ID: agi-t5agem92zk-qfb052-POST)
aws_api_gateway_deployment.prod_deploy: Refreshing state... (ID: 4jnb11)
data.aws_subnet.prod_b: Refreshing state...
data.aws_subnet.prod_a: Refreshing state...
aws_lambda_function.lambda_send_to_sensu: Modifying... (ID: lambda_send_to_sensu)
  environment.0.variables.sensu_url: "https://sensu-api.ctmsp.com:443" => "https://sensu-api.ctmsp.com"
  last_modified:                     "2019-01-17T22:45:52.640+0000" => "<computed>"
  source_code_hash:                  "9aSnvYrg1EmTHt6AFDg64tdHmZkWpMksOxDa3rAD6Vk=" => "Sc9223KCa4J/8QaF/X0xW4iH69JC5pGTKhQprEloG/0="
aws_lambda_function.lambda_send_to_sensu: Still modifying... (ID: lambda_send_to_sensu, 10s elapsed)
aws_lambda_function.lambda_send_to_sensu: Modifications complete after 13s (ID: lambda_send_to_sensu)

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.```

In the above you will notice the transition from Refreshing state to Modifying. At that 
point, before the modification to aws_lambda_function, the module has been 
executed and the zip file updated. I can verify that by file timestamp. However, I
would like to see that in the transcript. And, I want to see it in sequence, because I
want to know the zip file has been updated before it is uploaded to AWS Lambda. 

I have attached my module code as main.tf.txt 
[main.tf.txt](https://github.com/hashicorp/terraform/files/2773394/main.tf.txt)


### Attempted Solutions
 - none, after reading documentation thoroughly, again

### Proposal

Here are some different ideas I came up with for implementation:

1) For the *output* statement, add a new field, such as *logging*, setting 
this to true would cause the output to be a logging output when the module is 
executed, not at the end of the apply session, but immediately, along with bold 
font and the module path. It would be like any other logging statements. Add an 
option to indicate whether it should be bold font or not.

2) Add a *log* statement, which may be used inside the module configuration 
to indicate what one wants logged. Example: `log "my message with 
${my value}"`. For extra credit, this statement could be embedded in any 
resource, provisioner, data source. When the work of the resource, etc. is 
happening, the log message will be generated. For double extra credit, this log
statement could have a condition clause after the message, so the logging 
happens if the condition is true. 

3) Amend the data source *external* so that output from the external command
can be used to indicate any desired logging. Like a json string: 
  { "log": "my message bla bla" }. 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant