मैं टेराफॉर्म के लिए नया हूं और मैं .tf फ़ाइल के साथ पर्यावरण चर का उपयोग करने का प्रयास करते समय कुछ समस्या में भाग गया, मैंने terraform.tfvars
/variables.tf
का उपयोग करने का प्रयास किया।.tf फ़ाइल में पर्यावरण चर के साथ टेराफॉर्म का उपयोग कैसे करें
./terraform apply -var-file="terraform.tfvars"
Failed to load root config module: Error parsing variables.tf: At 54:17: illegal char
मुझे यहां क्या याद आ रही है?
terraform संस्करण: Terraform v0.9.2
main.tf:
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.aws_region}"
allowed_account_ids = ["${var.aws_account_id}"]
}
resource "aws_instance" "db" {
ami = "ami-49c9295"
instance_type = "t2.micro"
tags {
Name = "test"
}
connection {
user = "ubuntu"
}
security_groups = ["sg-ccc943b0"]
availability_zone = "${var.availability_zone}"
subnet_id = "${var.subnet_id}"
}
terraform.tfvars:
aws_profile = "default"
aws_access_key = "xxxxxx"
aws_secret_key = "xxxxxx"
aws_account_id = "xxxxxx"
key_name = "keyname"
key_path = "/home/user/.ssh/user.pem"
aws_region = "us-east-1"
subnet_id = "subnet-51997e7a"
vpc_security_group_ids = "mysql"
instance_type = "t2.xlarge"
availability_zone = "us-east-1a"
variables.tf:
variable "key_name" {
description = "Name of the SSH keypair to use in AWS."
default = "keypairname"
}
variable "key_path" {
description = "Path to the private portion of the SSH key specified."
default = "/home/user/.ssh/mypem.pem"
}
variable "aws_region" {
description = "AWS region to launch servers."
default = "us-east-1"
}
variable "aws_access_key" {
decscription = "AWS Access Key"
default = "xxxxxx"
}
variable "aws_secret_key" {
description = "AWS Secret Key"
default = "xxxxxx"
}
variable "aws_account_id" {
description = "AWS Account ID"
default = "xxxxxx"
}
variable "subnet_id" {
description = "Subnet ID to use in VPC"
default = "subnet-51997e7a"
}
variable "vpc_security_group_ids" {
description = "vpc_security_group_ids"
default = "sec"
}
variable "instance_type" {
description = "Instance type"
default = "t2.xlarge"
}
variable "instance_name" {
description = "Instance Name"
default = "test"
}
variable "availability_zone" {
description = "availability_zone"
default = "us-east-1a"
}
variable "aws_amis" {
default = {
"us-east-1": "ami-49c9295f",
"eu-west-1": "ami-49c9295f",
"us-west-1": "ami-49c9295f",
"us-west-2": "ami-49c9295f"
}
}
अद्यतन
variables.tf
से variable "aws_amis"
अनुभाग हटाने के बाद, मैं एक और मुद्दा में भाग:
Failed to load root config module: Error loading variables.tf: 1 error(s) occurred:
* variable[aws_access_key]: invalid key: decscription
यह जांच कर रहा है कि variables.tf फ़ाइल लाइन 54 'उपलब्धता_ज़ोन' चर के लिए समापन ब्रैकेट है जिसमें 17 वर्ण नहीं हैं - यह केवल एक बंद ब्रैकेट है। क्या आप अपनी फाइल में कुछ खो रहे हैं? – ydaetskcoR
इसके अलावा आपका 'aws_amis' नक्शा मुझे गलत लगता है। यह 'us-east1 = "ami-49c9295f" जैसा दिखता है और' 'us-east-1' ': "ami-49c9295f" के बजाय,' '। हालांकि एचसीएल जेएसओएन का एक सुपरसेट है, इसलिए मैं हमेशा इस बारे में भ्रमित हो जाता हूं कि आप इसमें JSON का उपयोग कहां कर सकते हैं। – ydaetskcoR
@ydaetskcoR धन्यवाद, मेरे पास अब एक और मुद्दा है, कृपया प्रश्न अपडेट पर एक नज़र डालें। – Berlin