Skip to content

fix(internal/provider): set all supported envbuilder options #38

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

Merged
merged 2 commits into from
Aug 16, 2024

Conversation

johnstcn
Copy link
Member

Adds support for setting all envbuilder options supported by the provider.
Other options that the provider overrides must be set via extra_env.

@johnstcn johnstcn requested a review from mafredri August 16, 2024 12:06
@johnstcn johnstcn self-assigned this Aug 16, 2024
@johnstcn johnstcn requested a review from dannykopping August 16, 2024 12:07
for key, elem := range data.ExtraEnv.Elements() {
if _, ok := env[key]; ok {
// This is a warning because it's possible that the user wants to override
// a value set by the provider.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh we could go either way here, provider overrides extra, extra overrides provider or error when both are set. I think this is a good approach as any 👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with this approach for now and tweak as required. Erroring here seems a bit extreme and there may be legit use-cases that we just can't think of right now.

func (data *CachedImageResourceModel) setComputedEnv(ctx context.Context) diag.Diagnostics {
env := make(map[string]string)

env["ENVBUILDER_CACHE_REPO"] = tfValueToString(data.CacheRepo)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting edge-case, what if extra env overrides cache repo? We use data.CacheRepo directly elsewhere, but it may be different in computed env.

We should probably always prefer the values from computed env when running the cache probe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably always prefer the values from computed env when running the cache probe?

I don't agree. The provider should use the arguments it is supplied. We add a warning diag if you override existing environment variables set, which should be enough of an indication.

Alternatively, I could add a check for this and make it a diag.Error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to block it with an error, so I'm just going to not allow overriding these but warn if they are set.

diag = append(diag, ds...)
data.Env, ds = basetypes.NewListValueFrom(ctx, types.StringType, sortedKeyValues(env))
diag = append(diag, ds...)
return diag
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for moving all of this into one place! ❤️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was driving me up the wall 🙈

@johnstcn johnstcn merged commit cd1599f into main Aug 16, 2024
14 checks passed
@johnstcn johnstcn deleted the cj/add-envbuilder-opts branch August 16, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants