Difference between revisions of "AWS instance example with aws ami lookup"

From wikieduonline
Jump to navigation Jump to search
Tags: Mobile web edit, Mobile edit
 
(9 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
 
  provider "aws" {
 
  provider "aws" {
   region  = "us-west-2"
+
   [[region]] = "[[us-west-2]]"
 
   profile = "YourProfile"
 
   profile = "YourProfile"
 
  }
 
  }
 +
 
 +
[[data]] "[[aws_ami]]" "ubuntu" {
 +
  most_recent = true
 +
 +
  filter {
 +
    name  = "name"
 +
    values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"]
 +
  }
 
   
 
   
  [[data]] "aws_ami" "ubuntu" {
+
  filter {
   most_recent = true
+
    name  = "virtualization-type"
<pre>
+
    values = ["hvm"]
 +
  }
 +
   
 +
  owners = ["099720109477"] # Canonical
 +
}
 +
 
 +
resource "[[aws_instance]]" "myUbuntuMicroInstance" {
 +
  ami          = data.aws_ami.ubuntu.id
 +
  instance_type = "t3.micro"
 +
 +
  tags = {
 +
    Name = "MyInstanceName"
 +
   }
 +
}
  
  filter {
+
== [[Ubuntu Focal 20.04]] ==
    name  = "name"
 
    values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"]
 
  }
 
  
  filter {
+
[[provider]] "aws" {
    name  = "virtualization-type"
+
  region  = "us-west-2"
    values = ["hvm"]
+
  profile = "YourProfile"
  }
+
}
  
  owners = ["099720109477"] # Canonical
 
}
 
  
resource "aws_instance" "myUbuntuMicroInstance" {
+
[[data]] "aws_ami" "ubuntu" {
   ami          = data.aws_ami.ubuntu.id
+
  most_recent = true
  instance_type = "t3.micro"
+
 
+
  filter {
   tags = {
+
    name   = "name"
    Name = "MyInstanceName"
+
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }
+
  }
}
+
</pre>
+
  filter {
 
+
    name   = "virtualization-type"
== [[Ubuntu Focal 20.04]] ==
+
    values = ["hvm"]
 +
  }
 +
 +
  owners = ["099720109477"] # Canonical
 +
}
 
<pre>
 
<pre>
provider "aws" {
 
  region  = "us-west-2"
 
  profile = "YourProfile"
 
}
 
 
data "aws_ami" "ubuntu" {
 
  most_recent = true
 
 
  filter {
 
    name  = "name"
 
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
 
  }
 
 
  filter {
 
    name  = "virtualization-type"
 
    values = ["hvm"]
 
  }
 
 
  owners = ["099720109477"] # Canonical
 
}
 
 
 
resource "aws_instance" "myUbuntuMicroInstance" {
 
resource "aws_instance" "myUbuntuMicroInstance" {
 
   ami          = data.aws_ami.ubuntu.id
 
   ami          = data.aws_ami.ubuntu.id

Latest revision as of 05:57, 13 March 2023

Ubuntu Hirsute 21.04[edit]

provider "aws" {
  region  = "us-west-2"
  profile = "YourProfile"
}
 
data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-hirsute-21.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
} 
 
resource "aws_instance" "myUbuntuMicroInstance" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro" 

  tags = {
    Name = "MyInstanceName"
  }
}

Ubuntu Focal 20.04[edit]

provider "aws" {
  region  = "us-west-2"
  profile = "YourProfile"
}


data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}
resource "aws_instance" "myUbuntuMicroInstance" {
  ami           = data.aws_ami.ubuntu.id
  instance_type = "t3.micro"

  tags = {
    Name = "MyInstanceName"
  }
}

Related terms[edit]

See also[edit]

Advertising: