地形基礎架構代碼(IaC)文件參數詳細信息和示例 - AWS Proton

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

地形基礎架構代碼(IaC)文件參數詳細信息和示例

您可以在模板包中的variable.tf文件中包含 Terraform 輸入變量。您也可以建立結構描述來建立 AWS Proton 受管理的變數。 AWS Proton .tf files從您的架構檔案建立變數。如需詳細資訊,請參閱 地形 IAC 文件

若要在基礎結構中參考結構描述定義的 AWS Proton 變數.tf files,請使用 Terraform IaC 資料 AWS Proton 表的參數和命名空間中顯示的命名空間。例如,您可以使用 var.environment.inputs.vpc_cidr. 在引號內,用單括號括住這些變數,並在第一個大括號前加上貨幣符號 (例如,“${var.environment.inputs.vpc_cidr}”)。

下列範例會示範如何使用命名空間在環境.tf file中包含 AWS Proton 參數。

terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 3.0" } } // This tells terraform to store the state file in s3 at the location // s3://terraform-state-bucket/tf-os-sample/terraform.tfstate backend "s3" { bucket = "terraform-state-bucket" key = "tf-os-sample/terraform.tfstate" region = "us-east-1" } } // Configure the AWS Provider provider "aws" { region = "us-east-1" default_tags { tags = var.proton_tags } } resource "aws_ssm_parameter" "my_ssm_parameter" { name = "my_ssm_parameter" type = "String" // Use the Proton environment.inputs. namespace value = var.environment.inputs.ssm_parameter_value }