alekc / terraform-provider-kubectl

Mozilla Public License 2.0
141 stars 7 forks source link

Not applying multiple resource in one yaml #146

Open debugger24 opened 2 weeks ago

debugger24 commented 2 weeks ago

I have yaml with multiple resource only first resource is applied.

Here is the state file content.

yaml_body we have 2 resource yaml_body_parsed have only first resource

This happened with multiple YAML files.

{
    "mode": "managed",
    "type": "kubectl_manifest",
    "name": "aws_cloudwatch",
    "provider": "provider[\"registry.terraform.io/alekc/kubectl\"]",
    "instances": [
        {
            "schema_version": 1,
            "attributes": {
                "api_version": "v1",
                "apply_only": false,
                "field_manager": "kubectl",
                "force_conflicts": false,
                "force_new": false,
                "id": "/api/v1/namespaces/amazon-cloudwatch",
                "ignore_fields": null,
                "kind": "Namespace",
                "live_manifest_incluster": "### Removed 1 ###",
                "live_uid": "2a14b7a5-6fc5-42ea-b152-e759435d99a5",
                "name": "amazon-cloudwatch",
                "namespace": null,
                "override_namespace": null,
                "sensitive_fields": null,
                "server_side_apply": false,
                "timeouts": null,
                "uid": "2a14b7a5-6fc5-42ea-b152-e759435d99a5",
                "validate_schema": true,
                "wait": null,
                "wait_for": [],
                "wait_for_rollout": true,
                "yaml_body": "apiVersion: v1\r\nkind: Namespace\r\nmetadata:\r\n  name: amazon-cloudwatch\r\n---\r\napiVersion: v1\r\ndata:\r\n  cluster.name: kubernetes-dev\r\n  http.port: \"2020\"\r\n  http.server: \"On\"\r\n  logs.region: us-east-1\r\n  read.head: \"Off\"\r\n  read.tail: \"On\"\r\nkind: ConfigMap\r\nmetadata:\r\n  name: fluent-bit-cluster-info\r\n  namespace: amazon-cloudwatch",
                "yaml_body_parsed": "apiVersion: v1\nkind: Namespace\nmetadata:\n  name: amazon-cloudwatch\n",
                "yaml_incluster": "### Removed 1 ###",
            },
            "sensitive_attributes": [],
            "private": "### Removed 2 ###",
            "dependencies": [
                "data.aws_eks_cluster.cluster"
            ]
        }
    ]
},
alekc commented 2 weeks ago

It doesn't support multiple yamls. Use this pattern

data "kubectl_file_documents" "docs" {
    content = file("multi-doc-manifest.yaml")
}

resource "kubectl_manifest" "test" {
    for_each  = data.kubectl_file_documents.docs.manifests
    yaml_body = each.value
}
debugger24 commented 2 weeks ago

Thanks @alekc let me try this..