All Products
Search
Document Center

Container Registry:Create a Container Registry Enterprise Edition instance with Terraform

Last Updated:Jun 02, 2026

Use Terraform to create a Container Registry Enterprise Edition instance.

Note

Run this sample code with a single click. Run sample code

Prerequisites

  • Avoid using the Alibaba Cloud root account directly because it has full resource permissions and poses security risks if credentials leak. Instead, Create a RAM user and Create an AccessKey pair.

  • Grant the RAM user the AliyunContainerRegistryFullAccess permission to manage Container Registry. Grant permissions to a RAM user.

    {
        "Version": "1",
        "Statement": [
            {
                "Action": "cr:*",
                "Resource": "*",
                "Effect": "Allow"
            },
            {
                "Action": "bss:*",
                "Resource": "*",
                "Effect": "Allow"
            }
        ]
    }
  • Set up a Terraform runtime environment using one of the following methods:

    Important

    Terraform v0.12.28 or later is required. Run terraform --version to verify.

Create an instance with Terraform

This example creates a Container Registry Enterprise Edition instance.

  1. Create a working directory with a configuration file named main.tf. The main.tf file defines the resources to deploy. The following table describes the parameters.

    Parameter

    Required

    Description

    Example

    payment_type

    No

    Billing method.

    Subscription

    period

    No

    Subscription period in months. Valid values: 1, 2, 3, 6, 12, 24, 36, 48, and 60. For annual subscriptions, use a multiple of 12.

    Note

    If you set renewal_status to AutoRenewal, this value must be greater than 0. Otherwise, auto-renewal will fail.

    1

    renew_period

    No

    Auto-renewal period in months. For annual subscriptions, use a multiple of 12.

    1

    renewal_status

    No

    Auto-renewal status. Valid values:

    • AutoRenewal: Auto-renews the instance.

    • ManualRenewal: Requires manual renewal.

    Defaults to ManualRenewal.

    AutoRenewal

    instance_type

    Yes

    Instance type. Valid values:

    • Basic: The Basic Edition.

    • Advanced: The Advanced Edition.

    Advanced

    instance_name

    Yes

    Instance name.

    This example uses the var.name variable.

    variable "region" {
      default = "cn-heyuan"
    }
    provider "alicloud" {
      region = var.region
    }
    variable "name" {
      default = "tf-example"
    }
    resource "alicloud_cr_ee_instance" "default" {
      payment_type   = "Subscription"              
      period         = 1                           
      renew_period   = 1                           
      renewal_status = "AutoRenewal"              
      instance_type  = "Advanced"                  
      instance_name  =  var.name                   
    }
  2. Initialize the Terraform runtime environment.

    terraform init

    Expected output on success:

    Initializing the backend...
    Initializing provider plugins...
    - Finding latest version of hashicorp/alicloud...
    - Installing hashicorp/alicloud v1.234.0...
    - Installed hashicorp/alicloud v1.234.0 (signed by HashiCorp)
    Terraform has created a lock file .terraform.lock.hcl to record the provider
    selections it made above. Include this file in your version control repository
    so that Terraform can guarantee to make the same selections by default when
    you run "terraform init" in the future.
    Terraform has been successfully initialized!
    You may now begin working with Terraform. Try running "terraform plan" to see
    any changes that are required for your infrastructure. All Terraform commands
    should now work.
    If you ever set or change modules or backend configuration for Terraform,
    rerun this command to reinitialize your working directory. If you forget, other
    commands will detect it and remind you to do so if necessary.
  3. Preview changes with an execution plan.

    terraform plan
  4. Create the Container Registry Enterprise Edition instance.

    terraform apply

    When prompted, enter yes and press Enter. Expected output on success:

    Plan: 1 to add, 0 to change, 0 to destroy.
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
      Enter a value: yes
    alicloud_cr_ee_instance.default: Creating...
    alicloud_cr_ee_instance.default: Still creating... [10s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [20s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [31s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [41s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [51s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m1s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m11s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m21s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m31s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m41s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [1m51s elapsed]
    alicloud_cr_ee_instance.default: Still creating... [2m1s elapsed]
    alicloud_cr_ee_instance.default: Creation complete after 2m9s [id=cri-4bsyebi*****]
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
  5. Verify the results.

    Terraform show command

    View the managed resources:

    terraform show
    shell@Alicloud:~/ens/rongqi$ terraform show
    # alicloud_cr_ee_instance.default:
    resource "alicloud_cr_ee_instance" "default" {
        created_time   = "2024-11-21T03:16:00Z"
        end_time       = "2024-12-21T16:00:00Z"
        id             = "xxx"
        instance_name  = "tf-example"
        instance_type  = "Advanced"
        payment_type   = "Subscription"
        period         = 1
        renew_period   = 1
        renewal_status = "AutoRenewal"
        status         = "RUNNING"
    }

    Verify in the console

    Log in to the Container Registry console. On the Instance List page, verify that tf-example has a status of Running and a specification of Advanced Edition.

Resource cleanup

Important

Terraform cannot release subscription-based Container Registry instances. The terraform destroy command removes the resource from the state file but does not terminate the subscription. Manually unsubscribe from the instance in the console to avoid further charges.

Complete example

Note

Run this sample code with a single click. Run sample code

Explore product-specific examples in Quickstarts. The Parameter description table lists all supported parameters.

Example code

variable "region" {
  default = "cn-heyuan"
}
provider "alicloud" {
  region = var.region
}
variable "name" {
  default = "tf-example"
}
resource "alicloud_cr_ee_instance" "default" {
  payment_type   = "Subscription"              
  period         = 1                           
  renew_period   = 1                           
  renewal_status = "AutoRenewal"               
  instance_type  = "Advanced"                  
  instance_name  =  var.name                   
}

References