Skip to content

Commit

Permalink
Add support for injecting required_providers (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Yoriyasu Yano <[email protected]>
  • Loading branch information
yorinasub17 authored Dec 12, 2022
1 parent d05ca80 commit a9dc739
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions _custom/root.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,50 @@ local h = import './helpers.libsonnet';
// attrs (obj): The attributes to apply to the provider block being injected.
// alias (string): The alias to bind to the provider block. When null, the alias attribute is omitted from the
// provider attributes.
// src (string): Where to source the provider. If specified, an entry to required_providers will be added specifying the
// source. If both src and version is null, the required_providers entry is omitted.
// version (string): What version of the provider to use. If specified, an entry to required_providers will be added
// specifying the version. If both src and version is null, the required_providers entry is omitted.
//
// Returns:
// A mixin object that injects the new provider block into the root Terraform configuration.
local withProvider(name, attrs, alias=null) =
local withProvider(name, attrs, alias=null, src=null, version=null) =
local maybeAlias =
if alias != null then
{ alias: alias }
else
{};

local maybeRequiredProviders =
if src != null || version != null then
{
terraform+: {
required_providers+: {
[name]: (
if src != null then
{ source: src }
else
{}
) + (
if version != null then
{ version: version }
else
{}
),
},
},
}
else
{};

{
provider+: {
[name]+: [
maybeAlias + attrs,
],
},
};
}
+ maybeRequiredProviders;


// withResource injects a new Terraform resource block into the root configuration.
Expand Down

0 comments on commit a9dc739

Please sign in to comment.