denoland / terraform-provider-deno

Terraform provider for hosted Deno APIs
Mozilla Public License 2.0
15 stars 2 forks source link

feat: support inline asset in `deno_deployment` & rework on `deno_assets` #28

Closed magurotuna closed 1 year ago

magurotuna commented 1 year ago

This commit adds support for inlined assets in the deno_deployment resource. This also involves some rework on the deno_assets data source, which breaks both input and output types.

Now the terraform config that does a deployment using inlined assets looks like as follows:

resource "deno_project" "test" {}

resource "deno_deployment" "test" {
  project_id = deno_project.test.id
  entry_point_url = "main.ts"
  assets = {
    "main.ts" = {
      kind = "file"
      content = <<-EOT
        Deno.serve(async () => {
          try {
            const image = await Deno.readFile('computer_screen_programming.png');
            return new Response(image);
          } catch (error) {
            return new Response(error.message);
          }
        });
      EOT
    }
    "computer_screen_programming.png" = {
      kind = "file"
      content = filebase64("testdata/binary/computer_screen_programming.png")
      encoding = "base64"
    }
  }
  env_vars = {}
}

Also, terraform's builtin function merge can be used to merge normal assets into inlined ones:

resource "deno_project" "test" {}

data "deno_assets" "image" {
  path = "testdata/binary"
  pattern = "*.png"
  target = "image"
}

resource "deno_deployment" "test" {
  project_id = deno_project.test.id
  entry_point_url = "main.ts"
  compiler_options = {}
  assets = merge(
    data.deno_assets.image.output,
    {
      "main.ts" = {
        kind = "file"
        content = <<-EOT
          Deno.serve(async () => {
            try {
              const image = await Deno.readFile('image/computer_screen_programming.png');
              return new Response(image);
            } catch (error) {
              return new Response(error.message);
            }
          });
        EOT
      }
    },
  )
  env_vars = {}
}

Other examples can be found in internal/provider/deployment_resource_test.go.

Resolves #16

piscisaureus commented 1 year ago

@magurotuna I made the following changes:

If you agree with the above changes, feel free to land, otherwise let's talk about it.