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

Example usage on registry.terraform.io in multiple languages #1298

Closed
mabead opened this issue Nov 13, 2021 · 11 comments
Closed

Example usage on registry.terraform.io in multiple languages #1298

mabead opened this issue Nov 13, 2021 · 11 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request feature/convert priority/important-soon High priority, to be worked on as part of our current release or the following one. size/x-large estimated > 1 month ux/configuration

Comments

@mabead
Copy link

mabead commented Nov 13, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

When we look at the CDK documentation (the AWS CDK, not CDK TF), we always have the code snippets in all supported languages. For example, here is the documentation for an AWS lambda in multiple languages:

Unfortunately, the terraform documentation does not have code snippets for CDK TF supported languages. All the code snippets are only in HCL. Example from https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function:

image

It therefore makes it hard for developers to use the CDK-TF because most of the available examples are not in the same language they are using. It requires a mental mapping. Note that I am aware aware that I could use cdktf convert to manually convert all the HCL snippets that I see. But I don't see myself trying to convince my colleagues that it's a fun workflow.

All that being said, do you have plans to update registry.terraform.io to show code snippets in all languages that are supported by CDK TF? I think it would significantly help in the adoption of cdktf.

@mabead mabead added enhancement New feature or request new Un-triaged issue labels Nov 13, 2021
@skorfmann skorfmann added the documentation Improvements or additions to documentation label Nov 19, 2021
@skorfmann
Copy link
Contributor

That's certainly something which is on our radar. However, there are no immediate plans to do this.

@mabead
Copy link
Author

mabead commented Nov 19, 2021

@skorfmann thanks for the response. Until you have what I would classify like the best solution (i.e. code samples in all languages in registry.terraform.io), if you had an online page like "cdktf-online-converter.com" where people could:

  • paste some HCL code
  • select the output language
  • show the resulting CDKTF code

Then, I think that it could remove some friction around the usage of cdktf.

@skorfmann
Copy link
Contributor

while we don't have a website for this (yet?), that's possible with cdktf convert. Your example above would translate to when copying the code example from the registry: pbpaste | cdktf convert | pbcopy

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";

/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: aws.
For a more precise conversion please use the --provider flag in convert.*/
const awsIamRoleIamForLambda = new aws.iam.IamRole(this, "iam_for_lambda", {
  assumeRolePolicy:
    '{\n  "Version": "2012-10-17",\n  "Statement": [\n    {\n      "Action": "sts:AssumeRole",\n      "Principal": {\n        "Service": "lambda.amazonaws.com"\n      },\n      "Effect": "Allow",\n      "Sid": ""\n    }\n  ]\n}\n',
  name: "iam_for_lambda",
});
new aws.lambdafunction.LambdaFunction(this, "test_lambda", {
  environment: [
    {
      variables: [
        {
          foo: "bar",
        },
      ],
    },
  ],
  filename: "lambda_function_payload.zip",
  functionName: "lambda_function_name",
  handler: "index.test",
  role: awsIamRoleIamForLambda.arn,
  runtime: "nodejs12.x",
  sourceCodeHash: '${filebase64sha256("lambda_function_payload.zip")}',
});

@skorfmann
Copy link
Contributor

Would even work with other language targets: pbpaste | cdktf convert --language python | pbcopy

# Provider bindings are generated by running cdktf get.
# See https://cdk.tf/provider-generation for more details.
import ...gen.providers.aws as aws

# The following providers are missing schema information and might need manual adjustments to synthesize correctly: aws.
# For a more precise conversion please use the --provider flag in convert.
aws_iam_role_iam_for_lambda = aws.iam.IamRole(self, "iam_for_lambda",
    assume_role_policy="""{
      "Version": "2012-10-17",
      "Statement": [
        {
          "Action": "sts:AssumeRole",
          "Principal": {
            "Service": "lambda.amazonaws.com"
          },
          "Effect": "Allow",
          "Sid": ""
        }
      ]
    }
    """,
    name="iam_for_lambda"
)
aws.lambdafunction.LambdaFunction(self, "test_lambda",
    environment=[{
        "variables": [{
            "foo": "bar"
        }
        ]
    }
    ],
    filename="lambda_function_payload.zip",
    function_name="lambda_function_name",
    handler="index.test",
    role=aws_iam_role_iam_for_lambda.arn,
    runtime="nodejs12.x",
    source_code_hash="${filebase64sha256(\"lambda_function_payload.zip\")}"
)

@mabead
Copy link
Author

mabead commented Nov 22, 2021

@skorfmann thanks for the example that shows how to use cdktf convert. But as I said in my initial post, I know it's possible to use cdktf converrt but I don't see myself trying to convince my colleagues that are not cli savy to use such a workflow... even more on windows where pbpaste is not present.

@ansgarm ansgarm added needs-priority Issue has not yet been prioritized; this will prompt team review and removed new Un-triaged issue labels Nov 22, 2021
@schersh
Copy link
Contributor

schersh commented Nov 22, 2021

@mabead Thanks for filing this issue! We do have this on our radar; because of the way the docs are currently generated for the Terraform Registry there are some technical hurdles that we need to work through to enable a language selector. But it's helpful to have issues like this to show the need and the value!

@DanielMSchmidt
Copy link
Contributor

@mabead would a hosted version of convert be a stepping stone to a proper solution or not help at all? Like a text area to past your code to and a button to convert it to CDK

@mabead
Copy link
Author

mabead commented Nov 23, 2021

@DanielMSchmidt We're pretty aligned on that topic (see this comment).

And if it's easy to do, maybe a button like "Convert to cdktf" could be added in registry.terraform.io. This button would post the code snippet to that online version of cdktf.

@DanielMSchmidt DanielMSchmidt added feature/convert priority/important-soon High priority, to be worked on as part of our current release or the following one. ux/configuration and removed needs-priority Issue has not yet been prioritized; this will prompt team review labels Dec 9, 2021
@mabead
Copy link
Author

mabead commented Aug 15, 2022

Hi @skorfmann @schersh . Now that CDK TF is officially released, do you have more precise plans to make code snippets on registry.terraform.io available in multiple languages?

@xiehan
Copy link
Member

xiehan commented Jul 25, 2023

I'm going to close this since we've begun rolling this out; see #3032 for more details. Feel free to add feedback in comments on that post, which has been pinned to allow everyone to find it more easily.

@xiehan xiehan closed this as completed Jul 25, 2023
@github-actions
Copy link
Contributor

I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation enhancement New feature or request feature/convert priority/important-soon High priority, to be worked on as part of our current release or the following one. size/x-large estimated > 1 month ux/configuration
Projects
None yet
Development

No branches or pull requests

6 participants