0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

OCIでteraformを試してみる 作業端末の準備編

Posted at

やりたいこと

1.ローカルPC端末からOCIクラウドへteraformで環境を構築する

前提として、windows10の端末からOCIへteradormで別コンパートメントに環境を構築する。
すでに日本語パック、Administratorを有効にしただけのWindowsサーバがある。
※Bationを利用してプライベートサブネットへ接続している。

すでにあるものをカスタムイメージを作成し、
別コンパートメントにてそのイメージを指定して作成する。

VCNやサブネットはすでに構築済み。
VCNの名前はVPN-TEST-VCN

準備

サーバがすでにあるので、Windows端末にteraformをインストールする。

参考記事

今回入れたのはこのバージョン
terraform_1.9.0_windows_386.zip

ダウンロード先

Cドライブ直下にtoolsというフォルダを作成して、その中に中身を入れる
フォルダ.PNG

フォルダ2.PNG

次は環境変数を設定する

先ほどのフォルダのパスを指定する。

1.PNG

パスはterraform.exeがあるフォルダを指定します。
C:\tools\terraform

2.PNG

Pathに新しい設定を入れます。

3.PNG

パワーシェルで確認

コマンドで確認
terraform -v

4.PNG

OCI CLIのダウンロード

参考記事

ダウンロード先

今回は下記をダウンロードする
oci-cli-3.44.0-Windows-Server-Installer.msi

インストール

CLI3.PNG
CLI1.PNG
CLI2.PNG

PowerShellで確認

コマンドで確認
oci -v

CLI4.PNG

セットアップ

セットアップをする前に、下記情報をOCIクラウドから集めておきます。

■IAMユーザ
■テナンシ
■コンパートメント

現在複製元のあるコンパートメントを選択します。

PowerShellでセットアップ
PS C:\Users\81803> oci setup config  #セットアップコマンドを入力
    This command provides a walkthrough of creating a valid CLI config file.

    The following links explain where to find the information required by this
    script:

    User API Signing Key, OCID and Tenancy OCID:

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other

    Region:

        https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm

    General config documentation:

        https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm

# 何も入力しないでEnterするとC:\Users\81803\.oci\config配下に作成される
Enter a location for your config [C:\Users\81803\.oci\config]: 

#OCIユーザのIDを入れる
Enter a user OCID: ocid1.user.oc1..aaaaaaaal5njakbijurpzebfyxdkg3fdirx4mqfnrkprhjycrq6jqbsbiquq

#テナンシのIDを入力
Enter a tenancy OCID: ocid1.tenancy.oc1..aaaaaaaa5qulwfnxyvi4ciptd4cpz4axmbx4nauiowevy6cbklpf3yig2oeq

#日本リージョンは14: ap-tokyo-1 なので、14を入力します。
Enter a region by index or name(e.g.
1: af-johannesburg-1, 2: ap-chiyoda-1, 3: ap-chuncheon-1, 4: ap-dcc-canberra-1, 5: ap-dcc-gazipur-1,
6: ap-hyderabad-1, 7: ap-ibaraki-1, 8: ap-melbourne-1, 9: ap-mumbai-1, 10: ap-osaka-1,
11: ap-seoul-1, 12: ap-singapore-1, 13: ap-sydney-1, 14: ap-tokyo-1, 15: ca-montreal-1,
16: ca-toronto-1, 17: eu-amsterdam-1, 18: eu-dcc-dublin-1, 19: eu-dcc-dublin-2, 20: eu-dcc-milan-1,
21: eu-dcc-milan-2, 22: eu-dcc-rating-1, 23: eu-dcc-rating-2, 24: eu-dcc-zurich-1, 25: eu-frankfurt-1,
26: eu-frankfurt-2, 27: eu-jovanovac-1, 28: eu-madrid-1, 29: eu-madrid-2, 30: eu-marseille-1,
31: eu-milan-1, 32: eu-paris-1, 33: eu-stockholm-1, 34: eu-zurich-1, 35: il-jerusalem-1,
36: me-abudhabi-1, 37: me-abudhabi-3, 38: me-dcc-doha-1, 39: me-dcc-muscat-1, 40: me-dubai-1,
41: me-jeddah-1, 42: mx-monterrey-1, 43: mx-queretaro-1, 44: sa-bogota-1, 45: sa-santiago-1,
46: sa-saopaulo-1, 47: sa-valparaiso-1, 48: sa-vinhedo-1, 49: uk-cardiff-1, 50: uk-gov-cardiff-1,
51: uk-gov-london-1, 52: uk-london-1, 53: us-ashburn-1, 54: us-chicago-1, 55: us-gov-ashburn-1,
56: us-gov-chicago-1, 57: us-gov-phoenix-1, 58: us-langley-1, 59: us-luke-1, 60: us-phoenix-1,
61: us-saltlake-2, 62: us-sanjose-1): 14
#↑14を入力

#新しい秘密鍵を作るか聞かれているので、Yesを選択
Do you want to generate a new API Signing RSA key pair? (If you decline you will be asked to supply the path to an existing key.) [Y/n]: y

#ディレクトリはC:\Users\81803\.ociでよいかと聞かれているので何も入力せずEnter
Enter a directory for your keys to be created [C:\Users\81803\.oci]:

#何も入力しないでEnter
Enter a name for your key [oci_api_key]:
Public key written to: C:\Users\81803\.oci\oci_api_key_public.pem
#公開カギをC:\Users\81803\.oci\oci_api_key_public.pemに書き出してくれた


#秘密鍵のパスフレーズを聞かれるので好きなものを入力
Enter a passphrase for your private key ("N/A" for no passphrase):

#もう一度入力する
Repeat for confirmation:

#C:\Users\81803\.oci\oci_api_key.pemに書き出しましたとの報告
Private key written to: C:\Users\81803\.oci\oci_api_key.pem

#パスフレーズを構成ファイルに書き込みますか? 
(そうでない場合はoci コマンドを実行するたびにプロンプ​​トが表示されたら入力する必要があります

#Yesにしておく
Fingerprint: 5b:43:ed:00:9b:bb:43:4e:9a:42:35:a0:01:bb:c1:18
Do you want to write your passphrase to the config file? (If not, you will need to enter it when prompted each time you run an oci command) [y/N]: y
Config written to C:\Users\81803\.oci\config


    If you haven't already uploaded your API Signing public key through the
    console, follow the instructions on the page linked below in the section
    'How to upload the public key':

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#How2


PS C:\Users\81803>

APIキーの作成

右上の人のアイコンを押し、アイデンティティ > 自分のプロファイル > 左のエリアからAPIキーを選択

API1.PNG

APIキーの追加を選択

先ほど作られた公開カギを入れる
API2.PNG

API3.PNG

OCI CLIのテスト

日本リージョンにある、今回のコンパートメントのVCNの情報を取得

コマンドで確認
PS C:\Users\81803> oci network vcn list --compartment-id ocid1.compartment.oc1..aaaaaaaaqdylk7exxlqb6d5btecccpm4mujb3v2deljsyqperkkr766lnaoq --region ap-tokyo-1
{
  "data": [
    {
      "byoipv6-cidr-blocks": null,
      "cidr-block": "10.0.0.0/16",
      "cidr-blocks": [
        "10.0.0.0/16"
      ],
      "compartment-id": "ocid1.compartment.oc1..aaaaaaaaqdylk7exxlqb6d5btecccpm4mujb3v2deljsyqperkkr766lnaoq",
      "default-dhcp-options-id": "ocid1.dhcpoptions.oc1.ap-tokyo-1.aaaaaaaa6bte35p3w6cn575jijphbikhdxjjds2ufe6gwpnhccs4wvxp7ylq",
      "default-route-table-id": "ocid1.routetable.oc1.ap-tokyo-1.aaaaaaaak2givbygwbgvgj5dknx7npjf72pgqa3due7esob3eqqosoh7qpgq",
      "default-security-list-id": "ocid1.securitylist.oc1.ap-tokyo-1.aaaaaaaaz6qnc63knwmg5zu6ensjzg6guqrpxoierqpf5bits4dacf4lzftq",
      "defined-tags": {
        "Oracle-Tags": {
          "CreatedBy": "default/akiallworks@gmail.com",
          "CreatedOn": "2024-04-10T07:55:36.432Z"
        }
      },
      "display-name": "VPN-TEST-VCN",
      "dns-label": "vpntestvcn",
      "freeform-tags": {},
      "id": "ocid1.vcn.oc1.ap-tokyo-1.amaaaaaanc7b76ia75d2loxixhkhntvbxgi4wzw2bbed5s25rafxlxu6gjgq",
      "ipv6-cidr-blocks": null,
      "ipv6-private-cidr-blocks": null,
      "lifecycle-state": "AVAILABLE",
      "time-created": "2024-04-10T07:55:36.509000+00:00",
      "vcn-domain-name": "vpntestvcn.oraclevcn.com"
    }
  ]
}
PS C:\Users\81803>

VPN-TEST-VCNが確認できました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?