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: bring tf #196

Merged
merged 4 commits into from
Apr 14, 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
33 changes: 33 additions & 0 deletions .github/workflows/canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,39 @@ jobs:
cd simtools
wing test
timeout_minutes: 5
canary-tf:
name: Test tf
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: tf
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang and dependencies
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: npm i -g winglang --loglevel verbose
timeout_minutes: 3
- name: Install dependencies
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: cd tf && npm i --include=dev --loglevel verbose
timeout_minutes: 3
- name: Run tests
uses: nick-fields/retry@v3
with:
max_attempts: 3
command: |-
cd tf
wing test
timeout_minutes: 5
canary-tsoa:
name: Test tsoa
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pull-request-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
redis
sagemaker
simtools
tf
tsoa
vite
websockets
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/tf-pull.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: tf-pull
on:
pull_request:
paths:
- tf/**
jobs:
build-tf:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: tf
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: tf
- name: Test
run: wing test
working-directory: tf
- name: Pack
run: wing pack
working-directory: tf
54 changes: 54 additions & 0 deletions .github/workflows/tf-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: tf-release
on:
push:
branches:
- main
paths:
- tf/**
- "!tf/package-lock.json"
jobs:
build-tf:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
sparse-checkout: tf
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
registry-url: https://registry.npmjs.org
- name: Install winglang
run: npm i -g winglang
- name: Install dependencies
run: npm install --include=dev
working-directory: tf
- name: Test
run: wing test
working-directory: tf
- name: Pack
run: wing pack
working-directory: tf
- name: Get package version
run: echo WINGLIB_VERSION=$(node -p "require('./package.json').version") >>
"$GITHUB_ENV"
working-directory: tf
- name: Publish
run: npm publish --access=public --registry https://registry.npmjs.org --tag
latest *.tgz
working-directory: tf
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Tag commit
uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
tag: tf-v${{ env.WINGLIB_VERSION }}
- name: GitHub release
uses: softprops/action-gh-release@v1
with:
name: tf v${{ env.WINGLIB_VERSION }}
tag_name: tf-v${{ env.WINGLIB_VERSION }}
files: "*.tgz"
token: ${{ secrets.PROJEN_GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ pull_request_rules:
- -check-failure=build-simtools
- -check-pending=build-simtools
- -check-stale=build-simtools
- -check-failure=build-tf
- -check-pending=build-tf
- -check-stale=build-tf
- -check-failure=build-tsoa
- -check-pending=build-tsoa
- -check-stale=build-tsoa
Expand Down Expand Up @@ -171,6 +174,9 @@ pull_request_rules:
- -check-failure=build-simtools
- -check-pending=build-simtools
- -check-stale=build-simtools
- -check-failure=build-tf
- -check-pending=build-tf
- -check-stale=build-tf
- -check-failure=build-tsoa
- -check-pending=build-tsoa
- -check-stale=build-tsoa
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ publishing them for you.
| [redis](./redis) | [@winglibs/redis](https://www.npmjs.com/package/@winglibs/redis) | sim |
| [sagemaker](./sagemaker) | [@winglibs/sagemaker](https://www.npmjs.com/package/@winglibs/sagemaker) | sim, tf-aws |
| [simtools](./simtools) | [@winglibs/simtools](https://www.npmjs.com/package/@winglibs/simtools) | sim |
| [tf](./tf) | [@winglibs/tf](https://www.npmjs.com/package/@winglibs/tf) | sim, tf-aws |
| [tsoa](./tsoa) | [@winglibs/tsoa](https://www.npmjs.com/package/@winglibs/tsoa) | sim |
| [vite](./vite) | [@winglibs/vite](https://www.npmjs.com/package/@winglibs/vite) | sim, tf-aws |
| [websockets](./websockets) | [@winglibs/websockets](https://www.npmjs.com/package/@winglibs/websockets) | awscdk, sim, tf-aws |
Expand Down
2 changes: 2 additions & 0 deletions tf/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/
node_modules/
21 changes: 21 additions & 0 deletions tf/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Wing

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
112 changes: 112 additions & 0 deletions tf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Terraform Utilities

This Wing library includes some useful utilities to work with Terraform.

## Prerequisites

* [winglang](https://winglang.io).

## Installation

```sh
npm i @winglibs/tf
```

## `tf.Resource`

Represents an arbitrary Terraform resource.

> `tf.Resource` can only be used when compiling your Wing program to a `tf-*` target.

It takes a `type` and `attributes` properties:

```js
bring tf;

let role = new tf.Resource({
type: "aws_iam_role",
attributes: {
inline_policy: {
name: "lambda-invoke",
policy: Json.stringify({
Version: "2012-10-17",
Statement: [
{
Effect: "Allow",
Action: [ "lambda:InvokeFunction" ],
Resource: "*"
}
]
})
},
assume_role_policy: Json.stringify({
Version: "2012-10-17",
Statement: [
{
Action: "sts:AssumeRole",
Effect: "Allow",
Principal: { Service: "states.amazonaws.com" }
},
]
})
}
}) as "my_role";

let arn = role.getStringAttribute("arn");

test "print arn" {
log(arn);
}
```

Now, we can compile this to Terraform:

```sh
wing compile -t tf-aws
```

And the output will be:

```json
{
"resource": {
"aws_iam_role": {
"my_role": {
"//": {
"metadata": {
"path": "root/Default/Default/my_role",
"uniqueId": "my_role"
}
},
"assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"states.amazonaws.com\"}}]}",
"inline_policy": {
"name": "lambda-invoke",
"policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"lambda:InvokeFunction\"],\"Resource\":\"*\"}]}"
}
}
}
},
"provider": { "aws": [ { } ] },
"terraform": {
"backend": {
"local": {
"path": "./terraform.tfstate"
}
},
"required_providers": {
"aws": {
"source": "aws",
"version": "5.31.0"
}
}
}
}
```

## Maintainers

* [Elad Ben-Israel](@eladb)

## License

This library is licensed under the [MIT License](./LICENSE).
Loading
Loading