×
Community Blog Why You May Want to Consider Using Pulumi

Why You May Want to Consider Using Pulumi

This article discusses why you may want to start using Pulumi and goes over how you can get started with it on Alibaba Cloud.

1

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.

Quick Start

To get started in creating a Pulumi project, you'll need to follow these steps.

  • Objectives:

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).

  • Requirements:

For this tutorial, you'll need Python 3 or later. You'll also need virtualenv to be installed. You'll need to install Pulumi. You can reference this document, Install Pulumi, for some help.

  • Procedure:

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 alicloud-python template.

2

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:

  • The __main__.py file is used to define the deployment configuration, and the Pulumi.demo-dev.yaml file records the public configuration of the stack, such as the region.
  • The Pulumi.yaml file records the metadata of the project, including the project name, description, and language.
  • The requirements.txt file defines the Python module required to run the task.

5. Go to the working directory as instructed. For this you can use this command:

cd project-demo

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
import pulumi_alicloud as alicloud

vpc = 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_ids= [sg.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.

3

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.

4

3. You can also click Permalink to view the execution result on the Pulumi official website.

5

Now, if you have follows the step above, you have created an Alibaba Cloud ECS instance by using Pulumi.

Summary

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.

0 0 0
Share on

AliyunOpenAPI

1 posts | 0 followers

You may also like

Comments

AliyunOpenAPI

1 posts | 0 followers

Related Products