Pulumi is an open-source tool that you can use to manage Alibaba Cloud resources in a familiar programming language using Infrastructure as Code (IaC) and declarative methods. Alibaba Cloud is the first cloud vendor to integrate with Pulumi, and our open platform now provides full support for Pulumi. Pulumi-alicloud can be used to provision 41 Alibaba Cloud products. This solution can meet the requirements of many major customers for automated migration to the cloud. We welcome you to try the Alibaba Cloud open platform.
Six Core Advantages of Pulumi
Below is a list of the six core advantages of Pulumi. As you’ll see, Pulumi may just be your tool of choice for deploying and managing resources on Alibaba Cloud.
1. Hybrid cloud support: You can use the same tool to manage and deploy cloud and OpenStack resources as well as Kubernetes clusters.
2. Multi-language support: You can use general-purpose programming languages to author declarative configurations, without having to learn vendor-specific template languages.
3. Declarative programming: Pulumi defines, provisions, and configures resources in a repeatable and predictable manner to reduce deployment and management errors due to human factors. Declarative programming allows you to describe the desired state of your infrastructure, instead of an imperative process to construct the infrastructure. You can use the same configuration to create the same environment.
4. Infrastructure as Code (IaC): You can use code to manage and maintain resources. Pulumi stores its own copy of the current state of your infrastructure so that you can track changes made to different components in the system and share these configurations with other users.
5. Integrated-development environment (IDE) support: Pulumi allows you to use sophisticated programming languages to author infrastructure and application configurations. This gives you access to IDE functions such as syntax highlighting, detection, and testing.
6. Unified tools: You can use the same language tool for both automated resource management and application development. For example, you can use the Pulumi Python SDK to create database instances and perform operations such as creating database tables in the Python language.
To get started in creating a Pulumi project, you’ll need to follow these steps.
We will be creating a Pulumi project, then deploying an Alibaba Cloud Elastic Compute Service (ECS) instance installed with Linux. The instance will be deployed to whichever region and zone you choose to deploy it. The instance will be configured with security group rules, and the network of the instance will be an Alibaba Cloud Virtual Private Cloud (VPC).
To install a Pulumi project, you’ll need to follow the steps below:
1. Run the
Pulumi new --dir command to create a working directory on your local computer. Select an appropriate template as prompted.
2. Go to the next page and select the
3. Enter the project name, description, stack name, and Alibaba Cloud region (
cn-beijing is selected by default) as prompted. Then, a message appears, indicating that the project has been created. You can run the provided command to start the first deployment.
4. Confirm the files generated in the local directory after the project is created. The details are as follows:
__main__.pyfile is used to define the deployment configuration, and the
Pulumi.demo-dev.yamlfile records the public configuration of the stack, such as the region.
Pulumi.yamlfile records the metadata of the project, including the project name, description, and language.
requirements.txtfile defines the Python module required to run the task.
5. Go to the working directory as instructed. For this you can use this command:
6. Activate the independent Python environment with the following command. Skip this step if there is only one Python version on the server.
virtualenv -p python3 venv source venv/bin/activate
7. Install the Pulumi and Pulumi-alicloud modules.
pip3 install -r requirements.txt
Next, to deploy your ECS instance with Linux installed, follow these steps:
1. Define the deployment file.
The content of the
__main__.py file is as follows:
import pulumi_alicloud as alicloudvpc = alicloud.vpc.Network("my-vpc",cidr_block="172.16.0.0/12")
az = "cn-hangzhou-i"
sg = alicloud.ecs.SecurityGroup("pulumi_sg",description="pulumi security_groups",vpc_id=vpc.id)
vswitch = alicloud.vpc.Switch("pulumi_vswitch",availability_zone=az,cidr_block="172.16.0.0/21",vpc_id=vpc.id)
sg_rule= alicloud.ecs.SecurityGroupRule("sg_rule",security_group_id=sg.id,ip_protocol = "tcp", type= "ingress",nic_type = "intranet",port_range="22/22",cidr_ip="0.0.0.0/0")instance=alicloud.ecs.Instance("ecs-instance2",availability_zone=az,instance_type ="ecs.t6-c1m1.large" , security_groups =sg_ids,image_id="ubuntu_18_04_64_20G_alibase_20190624.vhd",instance_name ="ecsCreatedByPulumi2",vswitch_id=vswitch.id,internet_max_bandwidth_out = 10)
The above code imports the
Pulumi_alicloud module and defines the VPC, VSwitch, security group, security group rules, and finally the ECS instance.
2. Use the Pulumi command-line interface (CLI) to apply the configuration. Run the
Pulumi up command.
Before applying the configuration, view the execution plan and select details. After confirming the settings, select
yes to run the configuration. The following figure shows that five resources have been created.
3. You can also click Permalink to view the execution result on the Pulumi official website.
Now, if you have follows the step above, you have created an Alibaba Cloud ECS instance by using Pulumi.
Using Infrastructure as Code (IaC) to manage cloud infrastructure and resources will be a big trend in the future. However, the need to learn additional vendor-specific template languages increases learning costs. Now, Pulumi Alibaba Cloud plug-ins solve this problem, allowing users to manage resources in Alibaba Cloud more conveniently and efficiently.