This PR prevents the item from being updated after running terraform apply when it has DATE field which was not changed.
To achieve this the itemToData function was changed and now it checks if the field is of DATE type and converts seconds to YYYY-MM-DD string format. The date value in this format will be saved in the tfstate, so then on the next run when it will compare the date value in tfstate and tf files they will be equal, so no changes will be applied.
In addition, the dataToItem function was changed to validate the format of DATE fields to make sure they are in YYYY-MM-DD format. That will prevent users from setting the dates in other formats and thus potential issues.
How to test
Checkout to fix/137/handle-date-field-on-item-read branch
make build
Update/create ~/.terraformrc file with the following content to tell Terraform to use your local provider version. Change PATH_TO_THE_PROJECT with the real path.
provider_installation {
dev_overrides {
"1Password/onepassword" = "PATH_TO_THE_PROJECT/dist"
}
# For all other providers, install them directly from their origin provider
# registries as normal. If you omit this, Terraform will _only_ use
# the dev_overrides block, and so no other providers will be available.
direct {}
}
In different folder create main.tf file with the following content
provide Connect credentials, service account or account
}
data "onepassword_vault" "vault" {
name = "Example" # there should be the name of you existing vault in 1Password
}
resource "onepassword_item" "item" {
vault = data.onepassword_vault.vault.uuid
title = "Item 2"
section {
label = "Section 1"
field {
label = "text"
type = "DATE"
value = "2023-10-10"
}
}
}
5. `terraform init`
6. `terraform apply` and see that item was created
7. `terraform apply` again and see that it prints `No changes. Your infrastructure matches the configuration.`
Resolves: #137
This PR prevents the item from being updated after running
terraform apply
when it hasDATE
field which was not changed.To achieve this the
itemToData
function was changed and now it checks if the field is ofDATE
type and converts seconds to YYYY-MM-DD string format. The date value in this format will be saved in thetfstate
, so then on the next run when it will compare the date value intfstate
andtf
files they will be equal, so no changes will be applied.In addition, the
dataToItem
function was changed to validate the format ofDATE
fields to make sure they are inYYYY-MM-DD
format. That will prevent users from setting the dates in other formats and thus potential issues.How to test
fix/137/handle-date-field-on-item-read
branchmake build
Update/create
~/.terraformrc
file with the following content to tell Terraform to use your local provider version. ChangePATH_TO_THE_PROJECT
with the real path.main.tf
file with the following contentprovider "onepassword" {
provide Connect credentials, service account or account
}
data "onepassword_vault" "vault" { name = "Example" # there should be the name of you existing vault in 1Password }
resource "onepassword_item" "item" { vault = data.onepassword_vault.vault.uuid title = "Item 2" section { label = "Section 1" field { label = "text" type = "DATE" value = "2023-10-10" } } }