🐙

[Pulumi] Pulumi #とは & 開発環境準備 (Python&AWS)

2022/03/06に公開

Pulumi #とは

https://www.pulumi.com/product/
下記公式の引用となります

Key features

Build Infrastructure as Code in familiar languages
Languages you love
Use TypeScript, JavaScript, Python, Go, and .NET to model cloud infrastructure by leveraging the features of each language.

Build on any cloud
Access the full breadth of services in AWS, Azure, GCP, and 60+ providers through a complete and consistent SDK interface.

Create reusable infrastructure
Build and share cloud infrastructure with reusable Pulumi Packages, which encapsulate your cloud architectures and best practices.

基本的にはアプリケーションとインフラストラクチャを管理・デプロイできるツールです
複数のプロバイダーや複数言語に対応していて、再利用可能なインフラストラクチャを作成します

似たようなツールはマルチプロバイダー対応の Terraform がありますが、Pulumi は Terraform みたいな HCL 等の専用言語ではなく、一般的な言語で記述が可能です
Terraform と Pulumi の違いに関しての参考ブログ:https://kari-marttila.medium.com/terraform-vs-pulumi-experiences-c41a8774b637

Pricing

一人で使う分には無料ですね
Team 単位や、企業単位で使う場合は有償プランもあります
※RBAC や SAML/SSO に対応したり 24*7 のサポートがあったりするんですね

https://www.pulumi.com/pricing/

API Document

ぱっと見めちゃくちゃ丁寧で感激
https://www.pulumi.com/registry/

開発環境準備

基本手順
Pulumi : https://www.pulumi.com/docs/get-started/aws/
AWS : https://pulumi.awsworkshop.io/10_prerequisites.html

必要なもの

・Python version 3.6 or later
・AWS configure

事前の設定 (Amazon linux2 をいれただけ)

$ /opt/aws/bin/ec2-metadata | grep ami-id:
ami-id: ami-07b4f72c4c356c19d

$ cat /etc/system-release
Amazon Linux release 2 (Karoo)

$ uname -a
Linux ip-*-*-*-*.ap-northeast-1.compute.internal 5.10.96-90.460.amzn2.x86_64 #1 SMP Fri Feb 4 17:12:04 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

$ python --version
Python 2.7.18

$ python3 --version
Python 3.7.10

$ pip3 --version
pip 20.2.2 from /usr/lib/python3.7/site-packages/pip (python 3.7)

AWS configure の設定

$ aws configure
AWS Access Key ID [None]: ***
AWS Secret Access Key [None]: ***
Default region name [None]: ap-northeast-1
Default output format [None]: json

Pulumi のインストール、ログイン

$ curl -fsSL https://get.pulumi.com | sh
=== Installing Pulumi v3.25.1 ===
+ Downloading https://get.pulumi.com/releases/sdk/pulumi-v3.25.1-linux-x64.tar.gz...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 63.4M  100 63.4M    0     0  92.5M      0 --:--:-- --:--:-- --:--:-- 92.5M
+ Extracting to /home/ec2-user/.pulumi/bin
+ Adding $HOME/.pulumi/bin to $PATH in /home/ec2-user/.bashrc

=== Pulumi is now installed! 🍹 ===
+ Please restart your shell or add /home/ec2-user/.pulumi/bin to your $PATH
+ Get started with Pulumi: https://www.pulumi.com/docs/quickstart
$ source ~/.bashrc
$ pulumi version
v3.25.1
$ pulumi login
Manage your Pulumi stacks by logging in.
Run `pulumi login --help` for alternative login options.
Enter your access token from https://app.pulumi.com/account/tokens
    or hit <ENTER> to log in using your browser : 

ブラウザで URL にアクセスをします

アカウントを新規作成してログインします

Create token からトークンを新規取得し、コンソールに張り付けてログインします

Welcome to Pulumi!

  Pulumi helps you create, deploy, and manage infrastructure on any cloud using
  your favorite language. You can get started today with Pulumi at:

      https://www.pulumi.com/docs/get-started/

  Tip of the day: Resources you create with Pulumi are given unique names (a randomly
  generated suffix) by default. To learn more about auto-naming or customizing resource
  names see https://www.pulumi.com/docs/intro/concepts/resources/#autonaming.


Logged in to pulumi.com as ano (https://app.pulumi.com/ano)

これで準備完了ですね
次回は AWS が提供している下記を試してみたいと思っています
https://pulumi.awsworkshop.io/20_cloud_engineering_python/20_getting_started_with_pulumi.html

Discussion