Custom provider debugging and logging

979 views
Skip to first unread message

Joaquin Fernandez Campo

unread,
Jul 6, 2018, 4:58:54 AM7/6/18
to Terraform
Hi all!

I'm currently developing a provider for some internal tools at my company, I'm having issues with two things: 

1. How do i enable logs? Is there a specific terraform helper package that can deal with that?

2. Is it possible to debug terraform providers? 


Thanks!

Dan Stine

unread,
Jul 6, 2018, 7:03:01 AM7/6/18
to terrafo...@googlegroups.com
Hello,

You can enable additional logging by setting TF_LOG.


Dan
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/6e86ae6d-abe7-49d9-9519-7f32ed8ab72f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joaquin Fernandez Campo

unread,
Jul 6, 2018, 12:39:00 PM7/6/18
to terrafo...@googlegroups.com
Yeah, I know about that but I'm asking about logging "best practices" or how to actually connect a debugger to a terraform provider. Sorry if I wasn't very clear.

Joaquín


For more options, visit https://groups.google.com/d/optout.


--
---------------------------------------
Joaquín Fernández Campo
E-Mail: jfc...@gmail.com

Paddy Carver

unread,
Jul 6, 2018, 4:42:46 PM7/6/18
to terrafo...@googlegroups.com
Hi! As far as I know, most experiments with connecting debuggers to providers end in frustration and abandonment, because providers run in their own processes. Last I heard, most Terraform provider developers use Println-based debugging.

As for how to get logs to show up, anything printed to standard error and prefixed with "[DEBUG] " will get included in the debug log. We also have a package that helps log requests and responses: https://godoc.org/github.com/hashicorp/terraform/helper/logging

CHUA Chee Wee

unread,
Jul 7, 2018, 11:55:46 PM7/7/18
to Terraform
It's actually possible to debug any custom Terraform providers, as long as you have the source to the custom provider.

I've recently done this while working on finding out why a provider isn't working as expected.

Let me know if you require further details.

Joaquin Fernandez Campo

unread,
Jul 8, 2018, 3:52:52 AM7/8/18
to terrafo...@googlegroups.com
Yeah! I'd love to see that! Have you written any blog post or anything??

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

CHUA Chee Wee

unread,
Jul 9, 2018, 10:28:03 PM7/9/18
to Terraform
Hi Joaquin,

I've not written a blog post on this yet, but watch https://chuacw.ath.cx/blogs/chuacw/default.aspx for it.

Using Visual Studio Code, I debugged every portion of a Terraform provider by writing test routines, then test the routine independently.
I did this for both resources and data routines.

Are you intending to debug the entire provider or just certain routines?
The key thing to debugging either resources or data routines is to note that you need to provide the input to these routines.


Here's an example of a piece of code I wrote that helped me to debug. I was able to step into the code and figure out the issues.

func Test_resourceTencentCloudAutoScalingGroupRead(t *testing.T) {
    // chuacw tests
    RequiredVars := map[string]string{
        CRegion: CRegionSingapore,
    }
    GetRequiredEnvVars(RequiredVars)
    config := Config{
        SecretId:  RequiredVars[CSecretId],
        SecretKey: RequiredVars[CSecretKey],
        Region:    RequiredVars[CRegion],
    }
    resource := dataSourceTencentCloudAutoScalingGroups()
    d := resource.Data(nil)
    m, _ := config.Client()

    resourceTencentCloudAutoScalingGroupRead(d, m)
Reply all
Reply to author
Forward
0 new messages