Developer tools
Terraform provider
Cloudsmith is a verified provider on the Terraform Registry.
With the Cloudsmith Terraform provider, you can manage your Cloudsmith workspace as code.
-
Create and configure repositories, including upstream proxies, connected repositories (early access), retention rules, and geo/IP access restrictions.
Early Access: Connected repositories
Connected repositories are in early access. For more information, see Connected repositories.
-
Control who has access through teams, service accounts, repository privileges, entitlement tokens, OIDC, and SAML single sign-on.
-
Manage standard license, vulnerability, and package deny policies, alongside custom policies as code.
-
Set up webhooks and usage limits.
-
Use data sources to look up organizations, members, repositories, packages, and policies.
To learn more about using the Cloudsmith Terraform provider, see Cloudsmith Provider in the Terraform Registry documentation.
Installation
To install the Cloudsmith Terraform provider:
-
Add the following configuration to the
required_providersblock in your Terraform module, settingversionto your preferred provider version:required_providers { cloudsmith = { source = "cloudsmith-io/cloudsmith" version = "0.0.85" } }See Terraform Registry: cloudsmith for the latest version of the provider.
-
Add your Cloudsmith API key to the
providerblock:provider "cloudsmith" { api_key = "API-KEY" }
Warning
A plaintext API key in theproviderblock makes your Terraform configuration unsafe to commit to version control. For an authentication method that is safe to commit, see Authenticate Terraform with the Cloudsmith credential helper.
- Run
terraform initand Terraform will automatically install the provider.
For more information about using the required_providers and providers blocks, see Provider Requirements and provider block reference in the Terraform documentation.
Authenticate Terraform with the Cloudsmith credential helper
The Cloudsmith credential helper lets Terraform use credentials configured in the Cloudsmith CLI, meaning no token is stored in your Terraform configuration. For hosts other than Cloudsmith, Terraform falls back to its own credential sources.
To install the credential helper, run:
cloudsmith credential-helper install terraform --workspace my-workspace --repo my-repoThis command installs the terraform-credentials-cloudsmith helper in the Terraform plugins directory and registers it in .terraformrc or terraform.rc by adding the block:
credentials_helper "cloudsmith" {
args = [ "--org", "my-workspace", "-r", "my-repo" ]
}As the resolved workspace and repository are baked into the args list, terraform init needs no environment variables. After that, terraform init authenticates to your Cloudsmith repository with the CLI's existing credentials. To rely on the CLOUDSMITH_WORKSPACE and CLOUDSMITH_REPO environment variables instead, omit the --workspace and/or --repo flags from the install command:
cloudsmith credential-helper install terraformTo remove the helper, run:
cloudsmith credential-helper uninstall terraformExample module
The following example Terraform module uses the Cloudsmith provider to create a repository and entitlement token, with some basic token restrictions:
terraform {
required_providers {
cloudsmith = {
source = "cloudsmith-io/cloudsmith"
version = "0.0.85"
}
}
}
provider "cloudsmith" {
api_key = "abcdefghijlkl1234567890"
}
data "cloudsmith_namespace" "demo" {
slug = "demo-org"
}
resource "cloudsmith_repository" "terraform-demo" {
description = "Example repo provisioned by Terraform"
name = "Terraform Demo"
namespace = "${data.cloudsmith_namespace.demo.slug_perm}"
slug = "terraform-demo"
repository_type = "Private"
}
resource "cloudsmith_entitlement" "demo-entitlement" {
name = "Token 1"
namespace = "${cloudsmith_repository.terraform-demo.namespace}"
repository = "${cloudsmith_repository.terraform-demo.slug_perm}"
limit_num_downloads = "15"
limit_num_clients ="1"
limit_package_query = "name:my-package"
}For more examples, see our terraform-provider GitHub repository.