This topic describes how to use Terraform to create a Container Registry Enterprise Edition image.
Prerequisites
Terraform is installed and configured.
Permission configuration
You must grant a Resource Access Management (RAM) user permissions required to execute a Terraform template. You must create a RAM user, obtain an AccessKey pair, and then attach a permission policy to the RAM user. To use a Terraform template to create a Container Registry Enterprise Edition instance, you must attach the AliyunContainerRegistryFullAccess
policy to the RAM user. For more information, see Grant system policies to a RAM user.
Create a template
Create a file named main.tf
and copy the following content to the file:
resource "alicloud_cr_ee_instance" "default" {
payment_type = "Subscription" # The billing method of the instance.
period = 1 # The subscription period of the subscription instance.
renew_period = 0 # The auto-renewal period. The value of 0 indicates that the instance is not automatically renewed.
renewal_status = "ManualRenewal" # The renewal policy. The value of ManualRenewal indicates that the instance can only be manually renewed.
instance_type = "Advanced" # The edition of the instance. The value of Advanced indicates an Advanced Edition instance of Container Registry Enterprise Edition.
instance_name = "terraform-example" # The name of the instance.
}
For more information about the parameters of alicloud_cr_ee_instance
, see alicloud_cr_ee_instance.
Execute the template
Run the following command to initialize the environment for Terraform:
terraform init
If the following information is returned, Terraform is initialized:
Initializing provider plugins... The following providers do not have any version constraints in configuration, so the latest version was installed. To prevent automatic upgrades to new major versions that may contain breaking changes, it is recommended to add version = "..." constraints to the corresponding provider blocks in configuration, with the constraint strings suggested below. * provider.alicloud: version = "~> 1.209" Terraform has been successfully initialized! 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.
Run the following command to create an execution plan:
terraform plan
If the following information is returned, the execution plan is created:
Refreshing Terraform state in-memory prior to plan... The refreshed state will be used to calculate this plan, but will not be persisted to local or remote state storage. ... Plan: 1 to add, 0 to change, 0 to destroy. ...
Run the following command to create a Container Registry Enterprise Edition instance:
terraform apply
When the following information is returned, enter
yes
and press the Enter key. The instance is created.... 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: Creation complete after 1m26s [id=************] Apply complete! Resources: 1 added, 0 changed, 1 destroyed.