Skip to content

NewValue function should also return an Error type #264

@BBBmau

Description

@BBBmau

terraform-plugin-go version

v0.14.2

Relevant provider source code

func NewValue(t Type, val interface{}) Value {
	v, err := newValue(t, val)
	if err != nil {
		panic(err)
	}
	return v
}

Terraform Configuration Files

terraform {
  required_providers {
    kubernetes = {
      source = "hashicorp/kubernetes"
    }
  }
}

provider "kubernetes" {
  # Configuration options
    config_path = "~/.kube/config"
}

locals {
  condition = false
  postStart = {
    exec = {
      command = ["bash", "-c", "echo postStart"]
    }
  }
  preStop = {
    exec = {
      command = ["bash", "-c", "echo preStop"]
    }
  }
}
resource "kubernetes_manifest" "deploy_foo" {
  manifest = {
    apiVersion = "apps/v1"
    kind       = "Deployment"
    metadata = {
      name      = "foo"
      namespace = "foo"
      labels = {
        "app" = "foo"
      }
    }
    spec = {
      selector = {
        matchLabels = {
          "app" = "foo"
        }
      }
      template = {
        metadata = {
          labels = {
            "app" = "foo"
          },
        }
        spec = {
          containers = [
            {
              name  = "foo"
              image = "busybox"
              lifecycle = true ? {
                postStart = local.postStart
              } :{
                preStop = local.preStop
              }
            }
          ]
        }
      }
    }
  }
}

Expected Behavior

Should return an error in order to prevent having to catch the error with the k8s provider

Actual Behavior

no error is returned forcing us to have to catch the error right before the panic within the provider.

References

hashicorp/terraform-provider-kubernetes#2018

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking-changeThis will impact or improve our compatibility postureenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions