在甲骨文使用过程中,很多时候会用到oci
1、安装
bash -c "$(curl –L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
一路回车。当出现“===> Modify profile to update your $PATH and enable shell/tab completion now? (Y/n):”这个时候,是在提示你输入y回车,会自动帮你添加环境变量。之后又是一路回车。
注意oci在八月一号之后就不在支持Python2.7,所以要先确认系统的Python版本
2、提前准备好账号ocid以及租户ocid
3、配置cli
oci setup config
具体如下
Enter a location for your config [/root/.oci/config]:
Enter a user OCID: #输入你的用户ocid
Enter a tenancy OCID: #输入你租户的用户id
Enter a region by index or name(e.g.
1: ap-chiyoda-1, 2: ap-chuncheon-1, 3: ap-hyderabad-1, 4: ap-melbourne-1, 5: ap-mumbai-1,
6: ap-osaka-1, 7: ap-seoul-1, 8: ap-sydney-1, 9: ap-tokyo-1, 10: ca-montreal-1,
11: ca-toronto-1, 12: eu-amsterdam-1, 13: eu-frankfurt-1, 14: eu-zurich-1, 15: me-dubai-1,
16: me-jeddah-1, 17: sa-santiago-1, 18: sa-saopaulo-1, 19: uk-cardiff-1, 20: uk-gov-cardiff-1,
21: uk-gov-london-1, 22: uk-london-1, 23: us-ashburn-1, 24: us-gov-ashburn-1, 25: us-gov-chicago-1,
26: us-gov-phoenix-1, 27: us-langley-1, 28: us-luke-1, 29: us-phoenix-1, 30: us-sanjose-1): 9 #这里选择区域
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 #输入y
Enter a directory for your keys to be created [/root/.oci]:
Enter a name for your key [oci_api_key]:
Public key written to: /root/.oci/oci_api_key_public.pem
Enter a passphrase for your private key (empty for no passphrase):
Private key written to: /root/.oci/oci_api_key.pem
Fingerprint:
Config written to /root/.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
4、复制公钥
cat /root/.oci/oci_api_key_public.pem
5、控制台链接
把展示出来的内容复制下来。并且添加到,甲骨文后台=>用户设置>>资源>>API秘钥>>添加API秘钥
6、检查oci配置是否正确
oci iam availability-domain list
如果这样提示表示配置正确,如果不是,检查你前面的配置
{
"data": [
{
"compartment-id": "ocid1.tenancy.oc1..aaaaaaaauoxxxxxxxxxxxxx",
"id": "ocid1.availabilitydomain.oc1..aaaaaaaaaixxxxxxxxxxxxx",
"name": "uffff:AP-TOKYO-1-AD-1"
}
]
}
6、借用terraform执行相关文件,建立新文件夹“terraform”,cd terraform
https://releases.hashicorp.com/terraform-provider-oci/下载最新版terraform provder
建立文件夹.terraform/providers/registry.terraform.io/hashicorp/oci/{版本}
将解压的文件terraform-provider-oci_v4.62.0_x4放在版本号文件夹中
7、下载最新版terraform,https://www.terraform.io/downloads,放在terraform文件夹下
./terraform init
将堆栈main.tf放在terraform文件夹内
./terraform plan
./terraform apply
,之后输入yes,就可以执行了。可以建立脚本自动化
./terraform.sh
#!/bin/bash
path='/root/terraform/' cd $path && while true do
echo 'yes' | ./terraform apply
sleep 60s done
评论已关闭