簡體   English   中英

terraform:創建安全組時出錯:UnauthorizedOperation:您無權執行此操作

[英]terraform : Error creating Security Group: UnauthorizedOperation: You are not authorized to perform this operation

我有一個下面的 terraform 腳本,在終端上使用它時可以正常工作。

provider "aws" {
  region = "${var.aws_region}"
}

resource "aws_instance" "jenkins-poc" {
  count = "2"
  ami           = "${var.aws_ami}"
  instance_type = "${var.instance_type}"
  key_name      = "${var.key_name}"
  availability_zone = "${var.aws_region}${element(split(",",var.zones),count.index)}"
  vpc_security_group_ids = ["${aws_security_group.jenkins-poc.id}"]
  subnet_id = "${element(split(",",var.subnet_id),count.index)}"
  user_data = "${file("userdata.sh")}"
  tags {
    Name = "jenkins-poc${count.index + 1}"
    Owner = "Shailesh"
  }
}

resource "aws_security_group" "jenkins-poc" {
  vpc_id = "${var.vpc_id}"
  name = "${var.security_group_name}"
  description = "Allow http,httpd and SSH"

  ingress {
      from_port = 443
      to_port = 443
      protocol = "tcp"
      cidr_blocks = ["10.0.0.0/8"]
  }
  ingress {
      from_port = 22
      to_port = 22
      protocol = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
  }
 ingress {
      from_port = 80
      to_port = 80
      protocol = "tcp"
      cidr_blocks = ["10.0.0.0/8"]
 }
  egress {
      from_port = "0"
      to_port = "0"
      protocol = "-1"
      cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_elb" "jenkins-poc-elb" {
    name = "jenkins-poc-elb"
    subnets = ["subnet-","subnet-"]
listener {
    instance_port = 80
    instance_protocol = "http"
    lb_port = "80"
    lb_protocol = "http"
}

  health_check {
    healthy_threshold = "2"
    unhealthy_threshold = "3"
    timeout = "3"
    target = "tcp:80"
    interval = 30
  }
    instances = ["${aws_instance.jenkins-poc.*.id}"]
}

和變量文件如下所示。

variable "aws_ami" {
  default = "ami-"
}

variable "zones"{
  default = "a,b"
}

variable "aws_region" {
    default = "us-east-1"
}

variable "key_name" {
    default = "test-key"
}

variable "instance_type" {
    default = "t2.micro"
}

variable "count" {
    default = "2"
}
variable "security_group_name" {
    default = "jenkins-poc"
}
variable "vpc_id" {
    default = "vpc-"
}
variable "subnet_id" {
    default = "subnet-,subnet"
}

當我使用 terraform apply 通過終端運行時,一切正常。 但是當我通過 jenkins 運行它時,相同的代碼給了我以下錯誤。

aws_security_group.jenkins-poc: Error creating Security Group: UnauthorizedOperation: You are not authorized to perform this operation

注意 :: 這是我在其中執行此操作的非默認 vpc。

我將不勝感激任何評論。 我沒有提到敏感值。

只需確保您在正確的 aws 配置文件中,並且default aws 配置文件可能會限制您創建實例

provider "aws" {
  region = "${var.aws_region}"
  shared_credentials_file = "~/.aws/credentials"
  profile = "xxxxxxx"
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM