This topic describes how to create a Container Registry Enterprise Edition instance by using Terraform.
You can run the sample code in this topic with just one click. Run sample code
Prerequisites
An Alibaba Cloud account, also known as the root account, has full permissions on all resources. Using the root account directly poses a security risk if its credentials are leaked. Use a RAM user and create an AccessKey pair for that user instead. For more information, see Create a RAM user and Create an AccessKey pair.
Grant the RAM user the
AliyunContainerRegistryFullAccesspermission to manage Container Registry. For more information about how to grant permissions to a RAM user, see Grant permissions to a RAM user.{ "Version": "1", "Statement": [ { "Action": "cr:*", "Resource": "*", "Effect": "Allow" }, { "Action": "bss:*", "Resource": "*", "Effect": "Allow" } ] }Prepare a Terraform runtime environment. You can use Terraform in one of the following ways:
Use Terraform in Terraform Explorer: Alibaba Cloud provides Terraform Explorer, an online environment where you can run Terraform commands. This method is suitable for quickly debugging and trying out Terraform at no cost.
Quickly create resources with Terraform: Terraform is pre-installed in Alibaba Cloud Shell and identity credentials are automatically configured. You can run Terraform commands directly in Cloud Shell. This method is suitable for accessing and using Terraform quickly and conveniently at a low cost.
Install and configure Terraform on your local machine: This method is suitable for use cases where you have a poor network connection or require a custom development environment.
ImportantMake sure that your Terraform version is v0.12.28 or later. To check your current version, run the
terraform --versioncommand.
Procedure
This example creates a Container Registry Enterprise Edition instance.
In a new working directory, create a configuration file named
main.tf. This file defines the resources to be deployed. The following table describes the parameters.Parameter
Required
Description
Example
payment_type
No
The billing method for the Container Registry Enterprise Edition instance.
Subscription
period
No
The subscription duration, in months. Valid values: 1, 2, 3, 6, 12, 24, 36, 48, and 60. For annual subscriptions, specify a multiple of 12.
NoteIf you set
renewal_statustoAutoRenewal, this value must be greater than 0. Otherwise, auto-renewal fails.1
renew_period
No
The auto-renewal period in months. For annual subscriptions, specify a multiple of 12.
1
renewal_status
No
The renewal status. Valid values:
AutoRenewal: auto-renewal.
ManualRenewal: manual renewal.
The default value is
ManualRenewal.AutoRenewal
instance_type
Yes
The type of the Container Registry Enterprise Edition instance. Valid values:
Basic: Basic Edition.
Advanced: Advanced Edition.
Advanced
instance_name
Yes
The name of the Container Registry Enterprise Edition instance.
This example uses the
var.namevariable.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 }Run the following command to initialize the
Terraformruntime environment.terraform initThe following output indicates that the initialization is successful.
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.Generate an execution plan to preview the changes.
terraform planApply the configuration to create the instance:
terraform applyWhen prompted, enter
yesand press Enter. The following output indicates that the instance is created.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.Verify the results.
Terraform show
Run the following command to view details of the resources managed by Terraform:
terraform show
Container registry console
After the instance is created, log on to the Container Registry console to view the new instance.

Resource cleanup
Terraform cannot release subscription-based instances. Running terraform destroy only removes the resource from the state file. You must manually release the instance on the console.
Complete example
You can run the sample code in this topic with just one click. Run sample code
For more complete examples, go to the product-specific folder in Quickstarts. For parameter details, see Parameter description.
Example code
References
Terraform resource for creating a Container Registry Enterprise Edition instance: alicloud_cr_ee_instance.