dfinity / terraform-provider-ic

A Terraform provider for provisioning Internet Computer canisters
Apache License 2.0
3 stars 0 forks source link

Doc request: How to generate args #25

Open bitdivine opened 5 months ago

bitdivine commented 5 months ago

Thank you for the provider. It worked when I provided args as a hex string but I am struggling to generate the args dynamically with local-exec and didc (see my futile attempt).

If you have an example of how to do this, that would be very helpful.

nmattia commented 4 months ago

I've just added better support for args in https://github.com/dfinity/terraform-provider-ic/pull/26.

The arg parameter now supports strings and records (of records and strings) instead of just strings:

resource "ic_canister" "my-app" {
  arg = { greeter = "hello" } # interpreted as (record { greeter = "hello" } )
}

I've added some functions (needs Terraform 1.8.0+) for encoding Terraform values to candid. So very similar to the above:

resource "ic_canister" "my-app" {
  arg_hex = provider::ic::did_encode({ greeter = "hello" })
}

(note the use of arg_hex instead of arg here; arg effectively applies did_encode to its TF parameter)

@q-uint (more or less) suggested we could also have a function that encodes a didc string, like this:

resource "ic_canister" "my-app" {
  arg_hex = provider::ic::did_didc("(record { greeter = "hello" })")
}

That might give practitioners more flexibility without having to rely on local-exec. Thoughts @bitdivine ?