Šta je novo?

Terraform

pTomic

Čuven
VIP član
Učlanjen(a)
31.01.2002
Poruke
1,166
Poena
660
Krenuh da učim Terraform i prvo pa muško.... :(
U prilogu je sc koda i greške.
Ljudi na Internetima kažu da je do područja u kojem ti se nalazi server, da ami-ID mora biti iz tog područja, koji pozivaš. Kod mene sve kako treba, bar mislim da je tako, ali ne radi.
Neka ideja?
 

Prilozi

  • Screenshot 2023-03-07 111310.png
    Screenshot 2023-03-07 111310.png
    115.3 KB · Pregleda: 56
Ne koristim ga aktivno, vise sam pre cackao malo za sebe, ali ovo tvoje kod mene prolazi. Kreiralo je instancu.
Jedino sto mi pada na pamet da nije mozda do permisija koje koristi profil pa ne moze da dohvati AMI?

Kod:
$ cat main.tf
provider "aws" {
  profile    = "default"
  region     = "us-east-1"
}

resource "aws_instance" "example" {
  ami           = "ami-0557a15b87f6559cf"
  instance_type = "t2.micro"
}

$ terraform apply

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_instance.example will be created
  + resource "aws_instance" "example" {
      + ami                                  = "ami-0557a15b87f6559cf"
      + instance_type                        = "t2.micro"

...

aws_instance.example: Creation complete after 44s

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Jedino za AMI-je koliko sam gledao generalo bi koristio lookup ili data sources.

The first line defines the AMI and supplies the image name and the region in which the deployment is taking place:

ami = "${lookup(var.images, var.region)}"

This code block also introduces the lookup command which is a variable that takes the contents of the “images” variable and the “region” variable to select of the correct AMI image for the region that is being deployed too. In our case we are deploying a Centos 7 image in North Virginia.

YAML:
// Create aws_ami filter to pick up the ami available in your region
data "aws_ami" "amazon-linux-2" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm*"]
  }
}

// Configure the EC2 instance in a public subnet
resource "aws_instance" "ec2_public" {
  ami                         = data.aws_ami.amazon-linux-2.id
 
Poslednja izmena:
Nazad
Vrh Dno