-
Notifications
You must be signed in to change notification settings - Fork 450
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(cli): implement hcl2cdk #796
Conversation
13c6f58
to
8e0b43e
Compare
d1dbf7b
to
b1e1e05
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to try this out on some of our Terraform projects once it is at that point. Just let me know.
const props = item[0]; | ||
|
||
if (props.alias) { | ||
throw new Error( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this be hard to add?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I just wanted to be explicit about what is currently supported :)
ca82f9e
to
d86b877
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty amazing, looks great! Built and tried it locally as well, seems to work as expected in general. For complex examples, there are a few issues though:
resource "aws_acm_certificate" "example" {
domain_name = "example.com"
validation_method = "DNS"
}
data "aws_route53_zone" "example" {
name = "example.com"
private_zone = false
}
resource "aws_route53_record" "example" {
for_each = {
for dvo in aws_acm_certificate.example.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = data.aws_route53_zone.example.zone_id
}
resource "aws_acm_certificate_validation" "example" {
certificate_arn = aws_acm_certificate.example.arn
validation_record_fqdns = [for record in aws_route53_record.example : record.fqdn]
}
resource "aws_lb_listener" "example" {
# ... other configuration ...
certificate_arn = aws_acm_certificate_validation.example.certificate_arn
}
produces
const awsAcmCertificateExample = new aws.AcmCertificate(this, "example", {
domainName: "example.com",
validationMethod: "DNS",
});
const dataAwsRoute53Zone = new aws.Route53Zone(this, "example", {
name: "example.com",
privateZone: false,
});
const awsRoute53RecordExample = new aws.Route53Record(this, "example", {
allowOverwrite: true,
name: "${each.value.name}",
records: ["${each.value.record}"],
ttl: 60,
type: "${each.value.type}",
zoneId: dataAwsRoute53Zone.example.zoneId,
});
awsRoute53RecordAwsRoute53RecordExample.addOverride(
"for_each",
`\${{
for dvo in ${awsAcmCertificateExample.domainValidationOptions} : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}}`
);
const awsAcmCertificateValidationExample = new aws.AcmCertificateValidation(
this,
"example",
{
certificateArn: awsAcmCertificateExample.arn,
validationRecordFqdns: `\${[for record in ${awsRoute53RecordExample.fqn} : record.fqdn]}`,
}
);
new aws.LbListener(this, "example", {
certificateArn: awsAcmCertificateValidationExample.certificateArn,
});
The thing which doesn't fit there:
const awsRoute53RecordExample = new aws.Route53Record(this, "example", {
allowOverwrite: true,
name: "${each.value.name}",
records: ["${each.value.record}"],
ttl: 60,
type: "${each.value.type}",
zoneId: dataAwsRoute53Zone.example.zoneId,
});
awsRoute53RecordAwsRoute53RecordExample.addOverride(
"for_each",
`\${{
for dvo in ${awsAcmCertificateExample.domainValidationOptions} : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}}`
);
Also, the imports
attribute seems to be empty in this case. I'd have expected that the AWS provider would have been returned for this example.
Currently I find the provider from the provider config. The imports fields goal is more in the import complete project part, the code part is for on the spot conversion :) Does this make sense?
Sorry I'm blind to the error, could you push a failing snapshot test for me to fix? :D |
The override combines resource class name with the variable name: |
@skorfmann Ah thank you! Fixed that one :) |
f22c21a
to
5f37289
Compare
99f3302
to
fba12f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not quite make it through yet, but here is a first set of comments already 👍
I really like the new commands you added to the code after our video review 💪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 💱
I didn't actually review the code, just started trying it out on some real Terraform projects. I tried it again this morning and ran into some new issues:
|
Oh great point, I wonder if we should change this behaviour in get in general 🤔 but for now I can add an extra check 👍
Did you try the latest version? I changed the behaviour to use |
I think so, but I was viewing that as a follow up task.
Yep. The code is updated, but it is still present in cdktf.json |
That is really weird, I'm using the same check for both 🤔
|
I'm thinking it's still in |
Oh right, thank you! Forgot the third part, will do a PR :) |
I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
pbpaste | cdktf convert --language=...
should print the CDKTF-ified version of what you have in your clipboard