Skip to main content

Use the 1Password Terraform provider

With the 1Password Terraform provider , you can reference, create, or update items in your vaults using a 1Password Connect Server, a 1Password Service Account, or your 1Password account and biometrics.

Requirements

Get started

To use the 1Password Terraform provider with a Connect server:

  1. Specify the Connect server token.

    You can set this value with the OP_CONNECT_TOKEN environment variable or with the token field in the provider configuration.

  2. Specify the Connect server hostname, URL, or IP address.

    You can set this value with the OP_CONNECT_HOST environment variable or with the url field in the provider configuration.

Reference

The following sections contain reference information for the 1Password Terraform provider:

Configuration

The 1Password Terraform provider has fields you must set before you can use it with a Connect server or 1Password CLI. The following table describes each field.

FieldTypeDescriptionRequired
op_cli_pathStringThe path to the 1Password CLI binary. You can also source the value from the OP_CLI_PATH environment variable. The default value is op.No.
service_account_tokenStringA valid token for the 1Password Service Account. You can also source the value from the OP_SERVICE_ACCOUNT_TOKEN environment variable.Required if using a service account.
tokenStringA valid token for the 1Password Connect server. You can also source the value from the OP_CONNECT_TOKEN environment variable.Required if using a Connect server.
urlStringThe HTTP(s) URL of the 1Password Connect server. You can also source the value from the OP_CONNECT_HOST environment variable.Required if using a Connect server.

You can use the following environment variables to specify configuration values.

Environment variableDescriptionConfiguration field
OP_CLI_PATHThe path to the 1Password CLI binary.op_cli_path
OP_SERVICE_ACCOUNT_TOKENA valid token for the 1Password Service Account.service_account_token
OP_CONNECT_TOKENA valid token for the 1Password Connect server.token
OP_CONNECT_HOSTThe hostname, IP address, or URL of the 1Password Connect server.url
OP_ACCOUNTThe 1Password user account.account

Configuration examples

The following code blocks show configuration examples.

tip

The following examples use environment variables. Make sure to set the environment variables beforehand or use plain text.

The following example shows a provider configuration using a Connect server:

connect-example.tf

Resources

The 1Password Terraform provider has the following resources:

Item resource

The onepassword_item resource represents a 1Password item. You can import a onepassword_item with the following syntax:

Schema

The following tables describe the onepassword_item resource schema.

FieldTypeDescriptionRequiredAccess
vaultStringThe UUID of the vault the item is in.YesRead-Write
categoryStringThe category of the item.

Acceptable values: login, password, or database.
NoRead-Write
databaseStringThe name of the database. Only applies to the database category.NoRead-Write
hostnameStringThe address where the database can be found. Only applies to the database category.NoRead-Write
passwordString, SensitiveThe password for the item.NoRead-Write
password_recipeBlock List, Max: 1The password recipe for the item. Only applies to Login and Password items. See password_recipe.NoRead-Write
portStringThe port the database is listening on. Only applies to the database category.NoRead-Write
sectionBlock ListA list of custom sections in the item. See section.NoRead-Write
tagsList of StringAn array of strings representing the tags assigned to the item.NoRead-Write
titleStringThe title of the item.NoRead-Write
typeStringThe type of database. Only applies to the database category.

Acceptable values: db2, filemaker, msaccess, mssql, mysql, oracle, postgresql, sqlite or other.
NoRead-Write
urlStringThe primary URL for the item.NoRead-Write
usernameStringThe username for the item.NoRead-Write
idStringThe Terraform resource identifier for the item in the format vaults/<vault_id>/items/<item_id>.N/ARead-Only
uuidStringThe UUID of the item. Item identifiers are unique within a specific vault.N/ARead-Only
password_recipe
tip

Password recipes can only be added to Login and Password items.

The nested schema for the password_recipe field:

FieldTypeDescriptionRequiredAccess
digitsBooleanUse digits [0-9] when generating the password.NoRead-Write
lengthNumberThe length of the password to be generated.NoRead-Write
letterBooleanUse letters [a-zA-Z] when generating the password.NoRead-Write
symbolsBooleanUse symbols [!@.-_*] when generating the password.NoRead-Write
section

The nested schema for the section field:

FieldTypeDescriptionRequiredAccess
labelStringThe label for the section.YesRead-Write
fieldBlock ListA list of custom fields in the section. See section.field.NoRead-Write
idStringA unique identifier for the section.N/ARead-Only
section.field

The nested schema for the section.field field:

FieldTypeDescriptionRequiredAccess
labelStringThe label for the field.YesRead-Write
idStringA unique identifier for the field.NoRead-Write
password_recipeStringThe password for the item. Only applies to Login and Password items. See section.field.password_recipe.NoRead-Write
purposeStringThe purpose indicates this is a special field: a username, password, or notes field.

Acceptable values: USERNAME, PASSWORD, or NOTES.
NoRead-Write
typeStringThe type of value stored in the field.

Acceptable values: STRING, EMAIL, CONCEALED, URL, OTP, DATE, MONTH_YEAR, or MENU.
NoRead-Write
valueString, SensitiveThe value of the field.NoRead-Write
section.field.password_recipe
tip

Password recipes can only be added to Login and Password items.

The nested schema for the section.field.password_recipe field:

FieldTypeDescriptionRequiredAccess
digitsBooleanUse digits [0-9] when generating the password.NoRead-Write
lengthNumberThe length of the password to be generated.NoRead-Write
letterBooleanUse letters [a-zA-Z] when generating the password.NoRead-Write
symbolsBooleanUse symbols [!@.-_*] when generating the password.NoRead-Write
Example

The following code block shows an example usage of the onepassword_item resource.

resource.tf

Data sources

The 1Password Terraform provider has the following data sources:

Item data source

Use the onepassword_item data source to get details of a 1Password item. You can identify an item by its vault UUID and either the item's title or UUID.

Schema

The following tables describe the onepassword_item resource schema.

FieldTypeDescriptionRequiredAccess
vaultStringThe UUID of the vault the item is in.YesRead-Write
note_valueString, SensitiveThe Secure Note value.NoRead-Write
titleStringThe title of the item to retrieve. This field populates with the title of the item if the item is looked up by its UUID.NoRead-Write
uuidStringThe UUID of the item to retrieve. This field populates with the UUID of the item if the item is looked up by its title.NoRead-Write
categoryStringThe category of the item.

Acceptable values: login, password, or database.
NoRead-Only
databaseStringThe name of the database. Only applies to the database category.NoRead-Only
hostnameStringThe address where the database can be found. Only applies to the database category.NoRead-Only
idStringThe Terraform resource identifier for the item in the format vaults/<vault_id>/items/<item_id>.NoRead-Only
passwordString, SensitiveThe password for the item.NoRead-Only
portStringThe port the database is listening on. Only applies to the database category.NoRead-Only
sectionList of ObjectA list of custom sections in an item.NoRead-Only
tagsList of StringAn array of strings of the tags assigned to the item.NoRead-Only
typeStringThe type of database. Only applies to the database category.

Acceptable values: db2, filemaker, msaccess, mssql, mysql, oracle, postgresql, sqlite, or other.
NoRead-Only
urlStringThe primary URL for the item.NoRead-Only
usernameStringThe username for the item.NoRead-Only
section

The nested schema for the section field:

FieldTypeDescriptionRequiredAccess
fieldList of ObjectA list of custom fields in the section. See section.field.N/ARead-Only
idStringA unique identifier for the section.N/ARead-Only
labelStringThe label for the section.N/ARead-Only
section.field

The nested schema for the section.field field:

FieldTypeDescriptionRequiredAccess
idStringA unique identifier for the field.N/ARead-Only
labelStringThe label for the field.N/ARead-Only
purposeStringThe purpose indicates this is a special field: a username, password, or notes field.

Acceptable values: USERNAME, PASSWORD, or NOTES.
N/ARead-Only
typeStringThe type of value stored in the field.

Acceptable values: STRING, EMAIL, CONCEALED, URL, OTP, DATE, MONTH_YEAR, or MENU.
N/ARead-Only
valueString, SensitiveThe value of the field.N/ARead-Only
Example

The following example shows how to use the onepassword_item data source.

data-source.tf

Vault data source

Use the onepassword_vault data source to get details of a vault. You can identify a vault with the vault name or UUID.

Schema

The following tables describe the onepassword_item resource schema.

FieldTypeDescriptionRequiredAccess
nameStringThe name of the vault to retrieve. This field populates with the name of the vault if the vault is looked up by its UUID.NoRead-Write
uuidStringThe UUID of the vault to retrieve. This field populates with the UUID of the vault if the vault is looked up by its name.NoRead-Write
descriptionStringThe description of the vault.NoRead-Only
idStringThe Terraform resource identifier for this item in the format vaults/<vault_id>.NoRead-Only

Was this page helpful?