1

I am currently working on implementing my own terraform provider. In my use case I have some static properties that I have to set for all of my resources, like the region the resource is living in.

To avoid working with variables and having to copy and paste all those region_name = var.default_region_name statements to all of my resources I am looking for a way to encapsulate those values somewhere else.

My idea was to do that in the provider configuration like this:

provider "example_provider" {
  default_region_name = "ww"
}

resource "example_resource" "example" {
  name = "example"
  //region_name = "ww"
}

While reading through the documentation I could not find an example that is accessing the provider config within a resource. Does anyone know how to do that or has a better idea on how I can handle my static configuration without the need of copy and pasting it to all resources?

Thank you in advance! :)

NanoBug
  • 11
  • 1
  • Does this help: https://github.com/hashicorp/terraform-provider-aws/blob/main/internal/provider/provider.go? – Marko E Mar 13 '23 at 13:49
  • f you want to configure those static properties in the provider configuration instead of the resources, then they would need to also probably be incorporated into the client implementation configured in the provider to be shared among the resources. – Matthew Schuchard Mar 13 '23 at 14:20
  • 1
    @MattSchuchard: Thank you very much. That was a great idea that I did not think about. I already tried it out and it is working like expected. :) – NanoBug Mar 14 '23 at 13:42
  • 1
    @MarkoE: Thank you for the hint. I checked out the provider source code for Azure with no luck but it seems like the AWS source code is a little easier to understand (at least imo). Together with the suggestion of Matt that solved my problem. – NanoBug Mar 14 '23 at 13:43

0 Answers0