terradart_hcl 0.34.0 copy "terradart_hcl: ^0.34.0" to clipboard
terradart_hcl: ^0.34.0 copied to clipboard

Pure Dart HCL (Terraform native syntax) parser and tf.json front-end producing a shared Terraform module model — the input side of terradart-migrate.

example/main.dart

import 'package:terradart_hcl/terradart_hcl.dart';

const _mainTf = r'''
variable "project_id" {
  type = string
}

resource "google_pubsub_topic" "orders" {
  project = var.project_id
  name    = "orders"

  labels = {
    team = "checkout"
  }
}

resource "google_pubsub_subscription" "orders_worker" {
  project = var.project_id
  name    = "orders-worker"
  topic   = google_pubsub_topic.orders.id
}
''';

/// Minimal example: parse a Terraform file, walk its resources, and write
/// one block back out as HCL.
void main() {
  final module = TfModule.fromHcl(_mainTf, fileName: 'main.tf');

  for (final variable in module.variables) {
    // ignore: avoid_print
    print('variable ${variable.name}');
  }
  for (final resource in module.resources) {
    final args = resource.body.attributes.map((a) => a.name).join(', ');
    // ignore: avoid_print
    print('resource ${resource.address}: $args');
  }

  final worker = module.resource(
    'google_pubsub_subscription',
    'orders_worker',
  )!;
  final ref = worker.argument('topic')! as TraversalExpr;
  // ignore: avoid_print
  print('orders_worker.topic references ${ref.dottedPath}');

  // ignore: avoid_print
  print(const HclWriter().writeEntry(worker.block));
}
1
likes
160
points
271
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pure Dart HCL (Terraform native syntax) parser and tf.json front-end producing a shared Terraform module model — the input side of terradart-migrate.

Repository (GitHub)
View/report issues
Contributing

License

Apache-2.0 (license)

Dependencies

meta

More

Packages that depend on terradart_hcl