Search code examples
terraformpactpulumi

Pulumi Terraform Provider reports required field missing that is definetely passed on


I'm trying to use the Pact Terraform Provider with Pulumi using the Terraform Provider for Pulumi. Setup worked fine, but as soon as I'm configuring anything else than the Provider, I'm getting an error that the 'host' field is missing:

Previewing update (broker):
@ previewing update.......
    pulumi:providers:pact default_0_10_0  error: rpc error: code = Unknown desc = "host": required field is not set: 
    pulumi:pulumi:Stack pact-broker-broker  
    pulumi:providers:pact default_0_10_0  1 error
Diagnostics:
  pulumi:providers:pact (default_0_10_0):
    error: rpc error: code = Unknown desc = "host": required field is not set: 

I've enabled maximum verbosity in logging, but the closest I get to what is actually passed to the provider is

eventsink.go:59] RegisterResource RPC finished: resource:Pact Broker[pulumi:providers:pact]; err: null, resp: urn:pulumi:broker::pact-broker::pulumi:providers:pact::Pact Broker,04da6b54-80e4-46f7-96ec-b56ff0331ba9,host,,,https://the-broker-url.com,version,,,0.10.0,,

which looks fine to me.

Somewhere else in the logs I've found that rpc logging is hidden by default and haven't found any way to enable that. TF_LOG=DEBUG hasn't helped anything either.

My Pulumi Script looks like this.

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

const host = process.env["PACT_BROKER_BASE_URL"]!!
if (!host) {
  throw new Error("Host needs to be set")
}

new pact.Provider("Pact Broker", {
  host: host,
  basicAuthUsername: process.env["PACT_BROKER_USERNAME"],
  basicAuthPassword: process.env["PACT_BROKER_PASSWORD"]
})

new pact.Environment("Test Environment", {
  displayName: "Test Environment"
})

Solution

  • Duh. Looked to close at the terraform example that was provided. Pulumi creates a default provider automatically, which I can configure using the command line, like pulumi config set pact:host "http://the-broker.url". However there doesn't seem to be a good way of reading configuration values from environment variables. Alternatively the programmatically created provider can be passed to the ressource, if the default provider shouldn't be used.

    const provider = new pact.Provider("Pact Broker", { // <-- store the provider in a constant
      host: host,
      basicAuthUsername: process.env["PACT_BROKER_USERNAME"],
      basicAuthPassword: process.env["PACT_BROKER_PASSWORD"]
    })
    
    new pact.Environment("Test Environment", {
      displayName: "Test Environment"
    }, { provider })      // <-- added the provider as a pulumi argument here
    

    To enforce that this provider is used, the default provider can be disabled by adding the provider id to the pulumi:disable-default-providers to the config section in the stacks configuration file.