1Password / terraform-provider-onepassword

Use the 1Password Terraform Provider to reference, create, or update items in your 1Password Vaults.
https://1password.com/secrets
MIT License
314 stars 41 forks source link

Section property not showing on version 2.x #183

Open alekscp opened 1 week ago

alekscp commented 1 week ago

Your environment

Terraform Provider Version: 2.1.0

Connect Server Version:

CLI Version: 2.29.0

OS: linux_amd64 (Terraform Cloud runner)

Terraform Version: 1.8.3

What happened?

The section field on a given item does not get pulled by the provider:

Logs using 2.1.0

...
Terraform will perform the following actions:

  # data.onepassword_item.cloudflare_zone_id will be read during apply
 <= data "onepassword_item" "cloudflare_zone_id" {
      + category   = (known after apply)
      + database   = (known after apply)
      + hostname   = (known after apply)
      + id         = (known after apply)
      + note_value = (sensitive value)
      + password   = (sensitive value)
      + port       = (known after apply)
      + tags       = (known after apply)
      + title      = "cloudflare_zone_id"
      + type       = (known after apply)
      + url        = (known after apply)
      + username   = (known after apply)
      + uuid       = (known after apply)
      + vault      = (known after apply)
    }
...

Logs using 1.4.3

...
Terraform will perform the following actions:

  # data.onepassword_item.cloudflare_zone_id will be read during apply
 <= data "onepassword_item" "cloudflare_zone_id" {
      + category   = (known after apply)
      + database   = (known after apply)
      + hostname   = (known after apply)
      + id         = (known after apply)
      + note_value = (sensitive value)
      + password   = (sensitive value)
      + port       = (known after apply)
      + section    = (known after apply)
      + tags       = (known after apply)
      + title      = "cloudflare_zone_id"
      + type       = (known after apply)
      + url        = (known after apply)
      + username   = (known after apply)
      + uuid       = (known after apply)
      + vault      = (known after apply)
    }
...
Changes to Outputs:
  ~ test = [
      - {
          - field = [
              - {
                  - id      = "hjbfafsv3cvq4m2kzqh3q3uq4q"
                  - label   = "text"
                  - purpose = ""
                  - type    = "STRING"
                  - value   = "some test"
                },
            ]
          - id    = "txgzmv35ep62s2jcz5gtbgcm6a"
          - label = "test"
        },

See the section property available when using version 1.4.3.

What did you expect to happen?

To have the section property available whilst using the latest version of the provider so that I can use its data.

Steps to reproduce

With a onepassword.tf file like so:

###
# NOTE: This is a workaround to have the `op` cli work in Terraform Cloud
# https://github.com/1Password/terraform-provider-onepassword/issues/141
###
resource "terraform_data" "install_op_cli" {
  input = timestamp()

  triggers_replace = [
    timestamp()
  ]

  provisioner "local-exec" {
    command = <<EOH
    ARCH="amd64"; \
    OP_VERSION="v$(curl https://app-updates.agilebits.com/check/1/0/CLI2/en/2.0.0/N -s | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')"; \
    curl -sSfo op.zip \
    https://cache.agilebits.com/dist/1P/op2/pkg/"$OP_VERSION"/op_linux_"$ARCH"_"$OP_VERSION".zip \
    && mkdir tools \
    && unzip -od tools op.zip \
    && rm op.zip \
    && chmod 0755 tools/op \
    && export PATH="$PATH:$(pwd)/tools" \
    && echo $PATH \
    && op --version
EOH
  }
}

data "onepassword_vault" "infra_global" {
  name = "${var.tags.purpose}-infra-global"

  depends_on = [
    terraform_data.install_op_cli
  ]
}

data "onepassword_item" "cloudflare_zone_id" {
  vault = data.onepassword_vault.infra_global.uuid
  title = "cloudflare_zone_id"

  depends_on = [
    terraform_data.install_op_cli
  ]
}

output "test" {
  value = data.onepassword_item.cloudflare_zone_id.section
}

Notes & Logs

I have mainly tried to fetch the sections from Password and Server items until I realized that the version of the provider I was using was simply not providing me with those fields.

I've tried to aim for something similar to this