argoproj-labs / terraform-provider-argocd

Terraform provider for Argo CD
Mozilla Public License 2.0
426 stars 89 forks source link

block managed_namespace_metadata panic #492

Open Nello-Angelo opened 1 week ago

Nello-Angelo commented 1 week ago
    sync_policy {

      managed_namespace_metadata {
        labels      = each.value.managed_namespace_metadata_labels
        annotations = each.value.managed_namespace_metadata_annotations
      }
    }
variable "multiple_sources_app" {
  type = map(object({
    managed_namespace_metadata_labels      = optional(map(string))
    managed_namespace_metadata_annotations = optional(map(string))
  }))
  default = {}
}
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Request cancelled
│ 
│ The plugin6.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
Stack trace from the terraform-provider-argocd_v7.0.3 plugin:
panic: interface conversion: interface {} is nil, not map[string]interface {}
goroutine 122 [running]:
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSyncPolicy({0x2f7e060, 0xc0023a0bd0})
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:407 +0xa65
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSpec(0x0?)
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:43 +0x213
github.com/oboukili/terraform-provider-argocd/argocd.expandApplication(_)
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:16 +0x10d
github.com/oboukili/terraform-provider-argocd/argocd.resourceArgoCDApplicationUpdate({0x3c00[320](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7370002#L320)?, 0xc000038620}, 0xc002377e00, {0x32d5ec0?, 0xc000828a00?})
    github.com/oboukili/terraform-provider-argocd/argocd/resource_argocd_application.go:262 +0x325
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).update(0xc0007b3b20, {0x3c00278, 0xc00159f290}, 0xd?, {0x32d5ec0, 0xc000828a00})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:840 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc0007b3b20, {0x3c00278, 0xc00159f290}, 0xc000faa9c0, 0xc000ef8980, {0x32d5ec0, 0xc000828a00})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:947 +0x83a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000981e60, {0x3c00278?, 0xc00159f0e0?}, 0xc000f44000)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x3c1b840?, 0xc000981e60?}}, {0x3c00278, 0xc00159f0e0}, 0x0?)
    github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5to6server/tf5to6server.go:38 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x3c002b0?, {0x3c00278?, 0xc00159ede0?}, 0xc000c01f90)
    github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc0009261e0, {0x3c00278?, 0xc00159e180?}, 0xc00076fdc0)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/tf6server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x[340](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7370002#L340)da20?, 0xc0009261e0}, {0x3c00278, 0xc00159e180}, 0xc0014dc480, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000042600, {0x3c00278, 0xc00159e0c0}, {0x3c0f940, 0xc0002ba180}, 0xc001c12ea0, 0xc000da2900, 0x5904858, 0x0)
    google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000042600, {0x3c0f940, 0xc0002ba180}, 0xc001c12ea0)
    google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 78
    google.golang.org/grpc@v1.63.2/server.go:1030 +0x135
Error: The terraform-provider-argocd_v7.0.3 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1
Nello-Angelo commented 1 week ago

the same error

    source_plugin_name                                 = optional(string)
    source_kustomize_common_annotations                = optional(map(string))
    source_kustomize_common_labels                     = optional(map(string))
    source_kustomize_images                            = optional(set(string))
    source_kustomize_name_prefix                       = optional(string)
    source_kustomize_name_suffix                       = optional(string)
    source_kustomize_version                           = optional(string)
      kustomize {
        name_prefix        = each.value.source_kustomize_name_prefix
        name_suffix        = each.value.source_kustomize_name_suffix
        version            = each.value.source_kustomize_version
        common_annotations = each.value.source_kustomize_common_annotations
        common_labels      = each.value.source_kustomize_common_labels
        images             = each.value.source_kustomize_images
      }

      plugin {
        name = each.value.source_plugin_name

        dynamic "env" {
          for_each = { for i in each.value.env : format("%s-%s", i.name, i.value) => i }
          content {
            name  = env.value.name
            value = env.value.value
          }
        }
      }
the-technat commented 1 week ago

So what exactly are you trying to acomplish that let's the provider crash? Would you mind adding some steps to reproduce the issue (including a full example resource)?

Nello-Angelo commented 1 week ago

what my resource looks like doesn’t matter; I get this error if the values ​​of the passed variables remain empty and optional

in the plugin block for example if i use dynamic and do apply

env = optional(list(object({
  name  = string
  value = string
})), [])
Nello-Angelo commented 1 week ago

i resolve with example below but now i get this

│ rpc error: code = Unknown desc = error validating and normalizing app:
│ error validating the repo: error verifying source type: multiple
│ application sources defined: Helm,Plugin
resource "argocd_application" "multiple_sources" {
  for_each = { for key, value in var.multiple_sources_app : key => value }
....
}
    env = optional(list(object({
      name  = string
      value = string
    })), [{ "name" = "", "value" = "" }])
Nello-Angelo commented 1 week ago
+ create
Terraform will perform the following actions:
  # module.argocd-resources.argocd_application.multiple_sources["gitlab-runner-infra"] will be created
  + resource "argocd_application" "multiple_sources" {
      + cascade  = true
      + id       = (known after apply)
      + status   = (known after apply)
      + validate = true
      + wait     = false
      + metadata {
          + generation       = (known after apply)
          + name             = "gitlab-runner-infra"
          + namespace        = "argocd"
          + resource_version = (known after apply)
          + uid              = (known after apply)
        }
      + spec {
          + project                = "default"
          + revision_history_limit = 10
          + destination {
                name      = null
              + namespace = "gitlab-runner"
              + server    = "https://kubernetes.default.svc"
            }
          + source {
              + chart           = "gitlab-runner"
              + path            = "."
              + repo_url        = "http://charts.gitlab.io/"
              + target_revision = "0.70.1"
              + helm {
                  + value_files = [
                      + null,
                    ]
                }
            }
          + sync_policy {
              + sync_options = [
                  + "CreateNamespace=true",
                ]
              + automated {
                  + prune     = true
                  + self_heal = true
                }
              + managed_namespace_metadata {
                  + annotations = {
                      + "argocd.argoproj.io/managed-by" = "argocd"
                    }
                  + labels      = {
                      + "argocd.argoproj.io/managed-by" = "argocd"
                    }
                }
              + retry {
                  + limit = "5"
                  + backoff {
                      + duration     = "5s"
                      + factor       = "2"
                      + max_duration = "3m"
                    }
                }
            }
        }
      + timeouts {}
    }
Plan: 1 to add, 0 to change, 0 to destroy.
module.argocd-resources.argocd_application.multiple_sources["gitlab-runner-infra"]: Creating...
╷
│ Warning: Value for undeclared variable
│ 
│ The root module does not declare a variable named "cloudflare_token" but a
│ value was found in file ".secrets.auto.tfvars". If you meant to use this
│ value, add a "variable" block to the configuration.
│ 
│ To silence these warnings, use TF_VAR_... environment variables to provide
│ certain "global" settings to all configurations in your organization. To
│ reduce the verbosity of these warnings, use the -compact-warnings option.
╵
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the
│ plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may
│ contain more details.
╵
Stack trace from the terraform-provider-argocd_v7.0.3 plugin:
panic: interface conversion: interface {} is nil, not string
goroutine 95 [running]:
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSourceHelm({0xc000fe4130, 0xc000fd3380?, 0x3534eed?})
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:250 +0x994
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSource({0xc000fe40d0, 0x1, 0x3537ddd?})
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:88 +0x29d
github.com/oboukili/terraform-provider-argocd/argocd.expandApplicationSpec(0x0?)
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:54 +0x33f
github.com/oboukili/terraform-provider-argocd/argocd.expandApplication(_)
    github.com/oboukili/terraform-provider-argocd/argocd/structure_application.go:16 +0x10d
github.com/oboukili/terraform-provider-argocd/argocd.resourceArgoCDApplicationCreate({0x3c00320?, 0xc0003bb960}, 0x0?, {0x32d5ec0?, 0xc0001b8500})
    github.com/oboukili/terraform-provider-argocd/argocd/resource_argocd_application.go:86 +0xe8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000641b20, {0x3c00278, 0xc000ecccf0}, 0xd?, {0x32d5ec0, 0xc0001b8500})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:806 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000641b20, {0x3c00278, 0xc000ecccf0}, 0xc000d01520, 0xc0002a1e80, {0x32d5ec0, 0xc0001b8500})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc000a01890, {0x3c00278?, 0xc000eccb40?}, 0xc0003340f0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5to6server.v5tov6Server.ApplyResourceChange({{0x3c1b[84](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7376317#L84)0?, 0xc000a01890?}}, {0x3c00278, 0xc000eccb40}, 0x0?)
    github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5to6server/tf5to6server.go:38 +0x54
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ApplyResourceChange(0x3c002b0?, {0x3c00278?, 0xc000ecc840?}, 0xc0003340a0)
    github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf6muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ApplyResourceChange(0xc00099fb80, {0x3c00278?, 0xc000e97e30?}, 0xc0000f27e0)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/tf6server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ApplyResourceChange_Handler({0x340da20?, 0xc00099fb80}, {0x3c00278, 0xc000e97e30}, 0xc0002a1200, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000184600, {0x3c00278, 0xc000e97da0}, {0x3c0f940, 0xc000982000}, 0xc000ec4a20, 0xc000d9c930, 0x5904[85](https://git.sbercloud.tech/dsworks/infrastructure/-/jobs/7376317#L85)8, 0x0)
    google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc000184600, {0x3c0f940, 0xc000982000}, 0xc000ec4a20)
    google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
    google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 40
    google.golang.org/grpc@v1.63.2/server.go:1030 +0x135
Error: The terraform-provider-argocd_v7.0.3 plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: command terminated with exit code 1
Nello-Angelo commented 1 week ago

can we ignore this block if fields are null ?

              + helm {
                  + value_files = [
                      + null,
                    ]
                }
            }
Nello-Angelo commented 1 week ago

@the-technat

Nello-Angelo commented 1 week ago

@the-technat can you watch this panic?

the-technat commented 1 week ago

Will do, but will take some days before I get time for it.

Nello-Angelo commented 1 week ago

does it correct behavior?