# package.yamlrole:policy:version: "2.0"statement:- action:- cloudapp:VerifyLicense- cvm:DescribeInstancesresource: "*"effect: allow
# variable.tf variable "cloudapp_cam_role" {}
cloudapp_cam_role into the environment variables or configuration files when declaring cloud resources. The following are examples of CVM and containers.# deployment.tfresource "tencentcloud_instance" "demo_cvm" {# Note: You need to bind the CAM role to the runtime role of the CVM instance.cam_role_name = var.cloudapp_cam_roleuser_data_raw = <<-EOT#!/bin/bash# Export the role name to the environment variableexport CLOUDAPP_CAM_ROLE=${var.cloudapp_cam_role}# The process starting can read the role name from the environment variable.node main.jsEOT}
# deployment.tfresource "tencentcloud_instance" "demo_cvm" {# Note: You need to bind the CAM role to the runtime role of the CVM instance.cam_role_name = var.cloudapp_cam_roleuser_data_raw = <<-EOT#!/bin/bash# Export the role name to the configuration fileecho "${var.cloudapp_cam_role}" >> /usr/local/.cloudapp_cam_role# The process starting can read the role name from the configuration file /usr/local/.cloudapp_cam_role.node main.jsEOT}
# <deployment.tf>resource "tencentcloud_kubernetes_cluster" "tke-cluster1" {worker_config {# Other worker_config content is omitted here.cam_role_name = var.cloudapp_cam_role}}resource "cloudapp_helm_app" "helm_charts" {chart_values = {CAM_ROLE = var.cloudapp_cam_role # Inject the role name variable here.}}
# <values.yaml># CAM role name, which is used to obtain a temporary key for calling the TencentCloud API, injected from the tf declarationCAM_ROLE: ""# <templates/statefulset.yaml>kind: StatefulSetspec:spec:containers:- name: "my-container"image: {{ quote .Values.SERVER_IMAGE }}env:# Assign CAM_ROLE to the container's environment variable- name: CAM_ROLEvalue: {{ quote .Values.CAM_ROLE }}
# <values.yaml># CAM role name, which is used to obtain a temporary key for calling the TencentCloud API, injected from the tf declarationCAM_ROLE: ""# <configmap.yaml># Declare ConfigMapkind: ConfigMapmetadata:name: cloudapp-configdata:.cloudapp_cam_role: {{ quote .Values.CAM_ROLE }}# <templates/statefulset.yaml>kind: StatefulSetspec:template:spec:containers:- name: "my-container"image: {{ quote .Values.SERVER_IMAGE }}valueMounts:- name: cloudapp-cam-rolemountPath: /usr/local/cloudappsubPath: .cloudapp_cam_rolevolumes:- name: cloudapp-cam-roleconfigMap:name: cloudapp-config
/usr/local/cloudapp/.cloudapp_cam_role.curl http://metadata.tencentyun.com/meta-data/cam/security-credentials/$CLOUDAPP_CAM_ROLE
{"TmpSecretId": "(RESPONSED SECRET ID)","TmpSecretKey": "(RESPONSED SECRET KEY)","ExpiredTime": 1658866289,"Expiration": "2022-07-26T20:11:29Z","Token": "(RESPONSED TOKEN)","Code": "Success"}
Feedback