Skip to content

Commit

Permalink
feat(tf): tf.Provider (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Jun 11, 2024
1 parent 2af27ad commit c6c8901
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"email": "[email protected]",
"name": "Elad Ben-Israel"
},
"version": "0.0.1",
"version": "0.0.2",
"repository": {
"type": "git",
"url": "https://github.com/winglang/winglibs.git",
Expand Down
18 changes: 18 additions & 0 deletions tf/provider.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
bring expect;
bring util;
bring "./provider.w" as tf;

if util.env("WING_TARGET").startsWith("tf") {
let provider = new tf.Provider(
name: "dnsimple",
source: "dnsimple/dnsimple",
version: "1.6.0",
attributes: {
token: "dnsimple_token",
}
) as "DnsimpleProvider";

let tfconfig: Json = provider.toTerraform();
expect.equal(tfconfig["terraform"]["required_providers"], { "dnsimple": { "source": "dnsimple/dnsimple", "version": "1.6.0" } });
expect.equal(tfconfig["provider"], { "dnsimple": [{ "token": "dnsimple_token" }] });
}
37 changes: 37 additions & 0 deletions tf/provider.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
bring "cdktf" as cdktf;

pub struct ProviderProps {
/// The name of the provider in Terraform - this is the prefix used for all resources in the provider.
/// @example "aws"
name: str;
/// The source of the provider on the Terraform Registry.
/// @example "hashicorp/aws"
source: str;
/// The version of the provider to use.
/// @example "2.0"
version: str;
/// The provider-specific configuration options.
/// @default {}
attributes: Json?;
}

pub class Provider extends cdktf.TerraformProvider {
attributes: Json;

new(props: ProviderProps) {
super(
terraformResourceType: props.name,
terraformGeneratorMetadata: {
providerName: props.name,
providerVersion: props.version,
},
terraformProviderSource: props.source,
);

this.attributes = props.attributes ?? {};
}

protected synthesizeAttributes(): Json {
return this.attributes;
}
}

0 comments on commit c6c8901

Please sign in to comment.