PaloAltoNetworks / terraform-provider-scm

The Terraform provider for Strata Cloud Manager
Apache License 2.0
7 stars 2 forks source link

Creating scm_variable fails with error "unknown host: cannot determine URI" #4

Closed kaisero closed 7 months ago

kaisero commented 8 months ago

Describe the bug

When creating a variable with the required defaults terraform apply fails with the following error

scm_variable.tf_variable_1: Creating...
╷
│ Error: Error creating config
│ 
│   with scm_variable.tf_variable_1,
│   on scm.tf line 1, in resource "scm_variable" "tf_variable_1":
│    1: resource "scm_variable" "tf_variable_1" {
│ 
│ unknown host: cannot determine URI

Expected behavior

Variable is being created in the specified folder

Current behavior

Create operation fails

Possible solution

I assume the issue occurs because api.strata.paloaltonetworks.com endpoint specified in scm-go dependency (https://github.com/PaloAltoNetworks/scm-go/blob/main/netsec/services/variables/service.go) is not live yet. If we check die URI we can see that the SAN points to api.stratacloud.paloaltonetworks.com - Maybe it is a certificate issue which is why the API Call fails?

Steps to reproduce

Define a provider (tried api.strata.paloaltonetworks.com and api.sase.paloaltonetworks.com) and resource and apply configuration

terraform {
  required_providers {
    scm = {
      source  = "paloaltonetworks/scm"
      version = "0.1.1"
    }
  }
}

provider "scm" {
  host          = "api.strata.paloaltonetworks.com"
  client_id     = "YOUR-CLIENT-ID"
  client_secret = "YOUR-CLIENT-SECRET"
  scope         = "tsg_id:YOUR-TSG-ID"
}
resource "scm_variable" "tf_variable_1" {
  folder = "Global"
  name = "tf_variable_1"
  description = "Managed by Terraform"
  type = "ip-netmask"
  value = "198.18.1.1/32"
}

Debug Output

➜  TF_LOG=debug terraform apply
(...) Output omited (...)
2024-01-16T16:41:38.133+0100 [INFO]  Starting apply for scm_variable.tf_variable_1
2024-01-16T16:41:38.133+0100 [DEBUG] scm_variable.tf_variable_1: applying the planned Create change
2024-01-16T16:41:38.134+0100 [INFO]  provider.terraform-provider-scm_v0.1.1: performing resource create: snippet="" terraform_provider_function=Create tf_req_id=774dd35d-b9bf-4a50-d933-82bc3adfb030 tf_rpc=ApplyResourceChange @caller=github.com/paloaltonetworks/terraform-provider-scm/internal/provider/variable.go:588 device="" resource_name=scm_variable tf_provider_addr=registry.terraform.io/paloaltonetworks/scm tf_resource_type=scm_variable folder=Branches @module=scm timestamp="2024-01-16T16:41:38.134+0100"
2024-01-16T16:41:38.134+0100 [ERROR] provider.terraform-provider-scm_v0.1.1: Response contains error diagnostic: diagnostic_summary="Error creating config" tf_resource_type=scm_variable @caller=github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/diag/diagnostics.go:58 tf_req_id=774dd35d-b9bf-4a50-d933-82bc3adfb030 @module=sdk.proto diagnostic_severity=ERROR tf_provider_addr=registry.terraform.io/paloaltonetworks/scm tf_rpc=ApplyResourceChange diagnostic_detail="unknown host: cannot determine URI" tf_proto_version=6.4 timestamp="2024-01-16T16:41:38.134+0100"
2024-01-16T16:41:38.139+0100 [DEBUG] State storage *statemgr.Filesystem declined to persist a state snapshot
2024-01-16T16:41:38.140+0100 [ERROR] vertex "scm_variable.tf_variable_1" error: Error creating config
╷
│ Error: Error creating config
│
│   with scm_variable.tf_variable_1,
│   on scm.tf line 1, in resource "scm_variable" "tf_variable_1":
│    1: resource "scm_variable" "tf_variable_1" {
│
│ unknown host: cannot determine URI
╵
2024-01-16T16:41:38.147+0100 [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = error reading from server: EOF"
2024-01-16T16:41:38.148+0100 [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/paloaltonetworks/scm/0.1.1/darwin_arm64/terraform-provider-scm_v0.1.1 pid=66044
2024-01-16T16:41:38.148+0100 [DEBUG] provider: plugin exited

Your Environment

Terraform v1.6.6 MacOS 13.6.3 (darwin_arm64) Provider registry.terraform.io/paloaltonetworks/scm v0.1.1

shinmog commented 7 months ago

The OpenAPI spec file that this is coming from indeed only references api.strata.paloaltonetworks.com. This means that this resource will only work when the host in the provider block is "api.strata.paloaltonetworks.com", not with "api.sase.paloaltonetworks.com". There are other resources referred to in this file that are in the same bucket, such as "scm_label" and "scm_snippet".

I suspect this is a temporary issue of sorts, or growing pains or something, until eng solidifies their end / endpoints, then things should just work.

Anyways, closing as this is working as intended.