Skip to content
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

feat(tf): tf.Provider #258

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add built-in support for singletonity?

return this.attributes;
}
}
Loading