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 tfresource - custom terraform resources #35

Closed
wants to merge 14 commits into from

Conversation

eladb
Copy link
Contributor

@eladb eladb commented Dec 13, 2023

Introduce a library that can be used to create custom resources for Terraform.

Introduce a library that can be used to create custom resources for Terraform.
tfresource/lib.w Show resolved Hide resolved
tfresource/lib.w Show resolved Hide resolved
@eladb eladb requested a review from Chriscbr December 13, 2023 21:29
@eladb eladb changed the title tfresource - custom terraform resources feat: tfresource - custom terraform resources Dec 13, 2023
Copy link
Contributor

@skorfmann skorfmann left a comment

Choose a reason for hiding this comment

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

Looks pretty cool! Tested it both for sim and tf-aws. Works both as expected for normal compilation. When using wing test, it works on sim only since tf-aws will try to run it in a Lambda function.

	2023-12-14T09:45:10.616+01:00	INIT_START Runtime Version: nodejs:18.v18 Runtime Version ARN: arn:aws:lambda:eu-central-1::runtime:5b65a6230d1054ba2f3bcff29fe7654ff1a5453cd2cfa1a03367a850c540a9da
	2023-12-14T09:45:10.834+01:00	START RequestId: c30921df-2488-4aeb-ac61-2c83e7b9764c Version: $LATEST
	2023-12-14T09:45:10.875+01:00	/bin/sh: wing: command not found
	2023-12-14T09:45:11.014+01:00	2023-12-14T08:45:11.014Z c30921df-2488-4aeb-ac61-2c83e7b9764c ERROR Invoke Error {"errorType":"Error","errorMessage":"Command failed: wing compile -t tf-aws examples/file.main.w","status":127,"signal":null,"output":[null,{"type":"Buffer","data":[]},null],"pid":23,"stdout":{"type":"Buffer","data":[]},"stderr":null,"stack":["Error: Command failed: wing compile -t tf-aws examples/file.main.w"," at __node_internal_genericNodeError (node:internal/errors:865:15)"," at checkExecSyncError (node:child_process:890:11)"," at execSync (node:child_process:962:15)"," at Object.exports2.shell (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/target/test/lib.test.tfaws/.wing/../../../../util.js:4:18)"," at Function.shell (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/target/test/lib.test.tfaws/.wing/../../../../lib.test.w:10:48)"," at $Closure1.handle (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/target/test/lib.test.tfaws/.wing/../../../../lib.test.w:14:3)"," at Runtime.exports.handler (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/target/test/lib.test.tfaws/.wing/handler_c85b802b.js:20:11)"]}
	2023-12-14T09:45:11.035+01:00	END RequestId: c30921df-2488-4aeb-ac61-2c83e7b9764c
	2023-12-14T09:45:11.035+01:00	REPORT RequestId: c30921df-2488-4aeb-ac61-2c83e7b9764c Duration: 198.69 ms Billed Duration: 199 ms Memory Size: 1024 MB Max Memory Used: 90 MB Init Duration: 215.49 ms 

So this can't be used as part of wing tests for other targets than sim as it is right now. Not sure if there's an easy workaround for this.

also, wondering if there's a way for richer diffs. Applied the example and changed the content of one of the files. That's the diff:

Terraform will perform the following actions:

  # shell_script.hello_tfrTerraformResource_Shell_8D678384 must be replaced
-/+ resource "shell_script" "hello_tfrTerraformResource_Shell_8D678384" {
      ~ dirty             = true -> false # forces replacement
      ~ id                = "cltc4ldg322nb2d9k18g" -> (known after apply)
      ~ output            = {
          - "hash" = "9e189ad1eb128bfd032968943f323dcf788fd6641cdc7ebddb72a3fa49aceb0f"
          - "path" = "hello1.txt"
        } -> (known after apply)
        # (1 unchanged attribute hidden)

        # (1 unchanged block hidden)
    }

tfresource/lib.w Show resolved Hide resolved
@eladb eladb changed the title feat: tfresource - custom terraform resources feat: bring tfresource - custom terraform resources Dec 30, 2023
@skorfmann
Copy link
Contributor

Looks like the global require of this file introduced in winglang/wing#5306 breaks the current approach. When running it I get

2024-01-22T09:42:45.763+0100 [ERROR] vertex "shell_script.hello_tfrTerraformResource_Shell_8D678384" error: Error occured during shell execution.
Error:
exit status 1

Command:
node .wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js

StdOut:


StdErr:
Error: Cannot find module '@winglang/sdk/lib/helpers'Require stack:- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)    at Module._load (node:internal/modules/cjs/loader:985:27)    at Module.require (node:internal/modules/cjs/loader:1235:19)    at require (node:internal/modules/helpers:176:18)    at Object.<anonymous> (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js:2:18)    at Module._compile (node:internal/modules/cjs/loader:1376:14)    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)    at Module.load (node:internal/modules/cjs/loader:1207:32)    at Module._load (node:internal/modules/cjs/loader:1023:12)    at Module.require (node:internal/modules/cjs/loader:1235:19) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js',    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js'  ]}

Env:
[]
2024-01-22T09:42:45.763+0100 [TRACE] vertex "shell_script.hello_tfrTerraformResource_Shell_8D678384": visit complete, with errors
2024-01-22T09:42:45.763+0100 [TRACE] dag/walk: upstream of "provider[\"registry.terraform.io/scottwinkler/shell\"] (close)" errored, so skipping
2024-01-22T09:42:45.764+0100 [TRACE] dag/walk: upstream of "root" errored, so skipping
2024-01-22T09:42:45.764+0100 [TRACE] statemgr.Filesystem: have already backed up original ./terraform.tfstate to ./terraform.tfstate.backup on a previous write
2024-01-22T09:42:45.764+0100 [TRACE] statemgr.Filesystem: no state changes since last snapshot
2024-01-22T09:42:45.764+0100 [TRACE] statemgr.Filesystem: writing snapshot at ./terraform.tfstate
╷
│ Error: Error occured during shell execution.
│ Error:
│ exit status 1
│
│ Command:
│ node .wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js
│
│ StdOut:
│
│
│ StdErr:
│ Error: Cannot find module '@winglang/sdk/lib/helpers'Require stack:- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)    at Module._load (node:internal/modules/cjs/loader:985:27)    at Module.require (node:internal/modules/cjs/loader:1235:19)    at require (node:internal/modules/helpers:176:18)    at Object.<anonymous> (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js:2:18)    at Module._compile (node:internal/modules/cjs/loader:1376:14)    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)    at Module.load (node:internal/modules/cjs/loader:1207:32)    at Module._load (node:internal/modules/cjs/loader:1023:12)    at Module.require (node:internal/modules/cjs/loader:1235:19) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js',    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8ba0c6c34fa1337eafb35423b47c81ce09f0c552d.js'  ]}
│
│ Env:
│ []
│
│
│
│   with shell_script.hello_tfrTerraformResource_Shell_8D678384,
│   on main.tf.json line 35, in resource.shell_script.hello_tfrTerraformResource_Shell_8D678384:
│   35:       },
│
╵
╷
│ Error: Error occured during shell execution.
│ Error:
│ exit status 1
│
│ Command:
│ node .wing/create-c8470d89f9c70ce77caaadfe3afa2b627b629a9dfd.js
│
│ StdOut:
│
│
│ StdErr:
│ Error: Cannot find module '@winglang/sdk/lib/helpers'Require stack:- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js- /Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8470d89f9c70ce77caaadfe3afa2b627b629a9dfd.js    at Module._resolveFilename (node:internal/modules/cjs/loader:1144:15)    at Module._load (node:internal/modules/cjs/loader:985:27)    at Module.require (node:internal/modules/cjs/loader:1235:19)    at require (node:internal/modules/helpers:176:18)    at Object.<anonymous> (/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js:2:18)    at Module._compile (node:internal/modules/cjs/loader:1376:14)    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)    at Module.load (node:internal/modules/cjs/loader:1207:32)    at Module._load (node:internal/modules/cjs/loader:1023:12)    at Module.require (node:internal/modules/cjs/loader:1235:19) {  code: 'MODULE_NOT_FOUND',  requireStack: [    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/inflight.$Closure1-2.js',    '/Users/sebastian/projects/wing-cloud/winglibs/tfresource/examples/target/file.main.tfaws/.wing/create-c8470d89f9c70ce77caaadfe3afa2b627b629a9dfd.js'  ]}
│
│ Env:
│ []
│
│
│
│   with shell_script.world_tfrTerraformResource_Shell_DF68C121,
│   on main.tf.json line 48, in resource.shell_script.world_tfrTerraformResource_Shell_DF68C121:
│   48:       }
│

tried to install @winglang/sdk globally, but it's probably not using the correct node version when executing the script.

Ideas for workarounds?

Copy link

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Feb 12, 2024
@ainvoner ainvoner removed the Stale label Feb 15, 2024
Copy link

github-actions bot commented Mar 7, 2024

Hi,

This PR has not seen activity in 20 days. Therefore, we are marking the PR as stale for now. It will be closed after 7 days.
If you need help with the PR, do not hesitate to reach out in the winglang community slack at winglang.slack.com.
Feel free to re-open this PR when it is still relevant and ready to be worked on again.
Thanks!

@github-actions github-actions bot added the Stale label Mar 7, 2024
@github-actions github-actions bot closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants