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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support filling out missing references with plausible examples #1845

Open
t0yv0 opened this issue Apr 5, 2024 · 2 comments 路 May be fixed by #1844
Open

Support filling out missing references with plausible examples #1845

t0yv0 opened this issue Apr 5, 2024 · 2 comments 路 May be fixed by #1844
Assignees
Labels
kind/enhancement Improvements or new features

Comments

@t0yv0
Copy link
Member

t0yv0 commented Apr 5, 2024

Hello!

  • Vote on this issue by adding a 馃憤 reaction
  • If you want to implement this feature, comment to let us know (we'll work with you on design, scheduling, etc.)

Issue details

A very common problem in providers like AWS are incomplete HCL examples that assume some missing context and as a result do not compile or preview, specifically often the examples assume a resource that is not listed in the example. It turns out that in TF/HCL representation the types of the missing resources are fairly obvious. It would help out out a lot if we could supply a folder with "canonical" definitions of resources indexed by type, and teach the converter to automatically augment the examples.

One prominent AWS concrete example I'm looking at:

 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         = aws_route53_zone.example.zone_id
}

### Inject this example after we find a missing reference to aws_acm_certificate
resource "aws_acm_certificate" "example" {
  domain_name       = "example.com"
  validation_method = "DNS"
}

### Inject this example after we find a missing reference to aws_route53_zone
resource "aws_route53_zone" "example" {
  name = "example.com"
}

I almost got it to preview. There is some other bug where I had to inject <any> to make the type checker happy type: (<any>aws.route53.RecordType)[range.value.type],.

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const exampleCertificate = new aws.acm.Certificate("example", {
    domainName: "example.com",
    validationMethod: "DNS",
});
const exampleZone = new aws.route53.Zone("example", {name: "example.com"});
const example: aws.route53.Record[] = [];
exampleCertificate.domainValidationOptions.apply(domainValidationOptions => {
    for (const range of Object.entries(domainValidationOptions.reduce((__obj, dvo) => ({ ...__obj, [dvo.domainName]: {
        name: dvo.resourceRecordName,
        record: dvo.resourceRecordValue,
        type: dvo.resourceRecordType,
    } }))).map(([k, v]) => ({key: k, value: v}))) {
        example.push(new aws.route53.Record(`example-${range.key}`, {
            allowOverwrite: true,
            name: range.value.name,
            records: [range.value.record],
            ttl: 60,
            type: (<any>aws.route53.RecordType)[range.value.type],
            zoneId: exampleZone.zoneId,
        }));
    }
});

Affected area/feature

@t0yv0 t0yv0 added kind/enhancement Improvements or new features needs-triage Needs attention from the triage team labels Apr 5, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Apr 5, 2024

We could do this in the bridge if it doesn't belong in the converter.

The advantage of this codebase it might have a better HCL parser available.

Fixing in the bridge:

  • could do some regex-based analysis for dangling variables
  • could iterate through the converter by recognizing error messages and performing the splicing

@t0yv0 t0yv0 self-assigned this Apr 5, 2024
@t0yv0
Copy link
Member Author

t0yv0 commented Apr 5, 2024

Yes actually found it makes more sense in the bridge! Moving.

@t0yv0 t0yv0 transferred this issue from pulumi/pulumi-converter-terraform Apr 5, 2024
@t0yv0 t0yv0 linked a pull request Apr 5, 2024 that will close this issue
@iwahbe iwahbe removed the needs-triage Needs attention from the triage team label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvements or new features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants