cloudposse / terraform-provider-awsutils

Terraform provider to help with various AWS automation tasks (mostly all that stuff we cannot accomplish with the official AWS terraform provider)
https://cloudposse.com/accelerate
Mozilla Public License 2.0
41 stars 9 forks source link

Make region optional like in the aws provider #28

Closed nitrocode closed 2 years ago

nitrocode commented 2 years ago

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

Since both aws and awsutils require the region input, the error message from both are the same if the region is omitted. This makes it seem like if the error is raised, the error comes from the former provider when its coming from this provider.

An easy solution might be to add more error context if the region is omitted most likely due to the provider configuration not explicitly configured since awsutils only recently has the region input requirement.

I don't see a custom error message in the aws provider or in this one

https://github.com/hashicorp/terraform-provider-aws/blob/ea38f3fa8f6b3c60ac30a943efa68ca84adba824/internal/provider/provider.go#L309-L314

https://github.com/cloudposse/terraform-provider-awsutils/blob/095b67b8ce12c6e95d4f9bc5856aa4fc4b7c3d42/internal/provider/provider.go#L64-L73

The main difference I see is that this provider's region is required whereas the aws provider's region is optional.

Why can't this one be optional too?

Maybe the error is as simple as updating the description of the region input. It's exactly the same as the aws provider so it's confusing. All of the descriptions should contain a reference to the provider.

https://github.com/cloudposse/terraform-provider-awsutils/blob/095b67b8ce12c6e95d4f9bc5856aa4fc4b7c3d42/internal/provider/provider.go#L228

Error

│Error: Missing required argument
│
│The argument "region" is required, but was not set.
╵}
    apply.go:15: 
            Error Trace:    apply.go:15
                                        examples_complete_test.go:246
            Error:          Received unexpected error:
                            FatalError{Underlying: error while running command: exit status 1; ╷
│Error: Missing required argument
│
│The argument "region" is required, but was not set.
╵}

Perhaps we can set this as optional instead of required and then we can do some custom provider checking if the value is null? Then we can throw a custom error.

references

https://www.terraform.io/plugin/sdkv2/schemas/schema-methods