Skip to content

Commit

Permalink
feat(tf): tf.Element
Browse files Browse the repository at this point in the history
  • Loading branch information
eladb committed Jul 4, 2024
1 parent 37ec403 commit 5bfc45a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,28 @@ class DnsimpleProvider {
Use `DnsimpleProvider.getOrCreate(scope)` to get the provider instance.
## `tf.Element`
Just a blog of JSON that goes into the Terraform output:
```js
bring tf;

new tf.Element({
provider: [
{ aws: { } },
{ aws: { alias: "server_function" } },
{ aws: { alias: "global", region: "us-east-1" } }
]
});
```
The above example will add a `provider` section to the output Terraform with a set of providers.
## Maintainers
* [Elad Ben-Israel](@eladb)
* [Chris Rybicki](@Chriscbr)
## License
Expand Down
11 changes: 11 additions & 0 deletions tf/element.test.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
bring util;
bring "./element.w" as e;

if util.env("WING_TARGET").startsWith("tf") {
new e.Element({
provider: [
{ foo: "bar" },
{ baz: "qux" }
]
});
}
38 changes: 38 additions & 0 deletions tf/element.test.w.tf-aws.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# `element.test.w.tf-aws.snap.md`

## main.tf.json

```json
{
"//": {
"metadata": {
"backend": "local",
"stackName": "root",
"version": "0.20.3"
},
"outputs": {
}
},
"provider": [
{
"foo": "bar"
},
{
"baz": "qux"
}
],
"terraform": {
"backend": {
"local": {
"path": "./terraform.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "5.31.0"
}
}
}
}
```
15 changes: 15 additions & 0 deletions tf/element.w
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

bring "cdktf" as cdktf;

pub class Element extends cdktf.TerraformElement {
config: Json;

new(config: Json) {
super();
this.config = config;
}

pub toTerraform(): Json {
return this.config;
}
}
45 changes: 45 additions & 0 deletions tf/provider.test.w.tf-aws.snap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# `provider.test.w.tf-aws.snap.md`

## main.tf.json

```json
{
"//": {
"metadata": {
"backend": "local",
"stackName": "root",
"version": "0.20.3"
},
"outputs": {
}
},
"provider": {
"aws": [
{
}
],
"dnsimple": [
{
"token": "dnsimple_token"
}
]
},
"terraform": {
"backend": {
"local": {
"path": "./terraform.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "5.31.0"
},
"dnsimple": {
"source": "dnsimple/dnsimple",
"version": "1.6.0"
}
}
}
}
```

0 comments on commit 5bfc45a

Please sign in to comment.