Difference between revisions of "Terraform: AWS instance example with aws ami lookup and key name"
Jump to navigation
Jump to search
Line 48: | Line 48: | ||
* [[Terraform resource]]: <code>[[Terraform resource: aws_key_pair|aws_key_pair]]</code> | * [[Terraform resource]]: <code>[[Terraform resource: aws_key_pair|aws_key_pair]]</code> | ||
* <code>[[aws ec2 run-instances]]</code> | * <code>[[aws ec2 run-instances]]</code> | ||
+ | * <code>[[~/.ssh/config]] | ||
== Activities == | == Activities == |
Revision as of 05:57, 12 September 2022
main.tf
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" key_name = "YourKeyName" tags = { Name = "MyInstanceName" } } resource "aws_key_pair" "YourKeyName" { key_name = "YourKeyName" public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD3F6tyPEFEzV0LX3X8BsXdMsQz1x2cEikKDEY0aIj41qgxMCP/iteneqXSIFZBp5vizPvaoIR3Um9xK7PGoW8giupGn+EPuxIA4cDM4vzOqOkiMPhz5XK0whEjkVzTo4+S0puvDZuwIsdiW9mxhJc7tgBNL0cYlWSYVkz4G/fslNfRPW5mYAM49f4fhtxPb5ok4Q2Lg9dPKVHO/Bgeu5woMc7RY0p1ej6D4CKFE6lymSDJpW0YHX/wqE9+cfEauh7xZcG0q9t2ta6F6fmX0agvpFyZo8aFbXeUBr7osSCJNgvavWbM/06niWrOvYX2xwWdhXmXSrbX8ZbabVohBK41 [email protected]" }
Errors: Key par does not exist
│ Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'YourKeyName' does not exist │ status code: 400, request id: 717f23c7-f87f-4056-a8f4-a82ad2095534
Related
aws ec2 describe-key-pairs
terraform init
,terraform show
- Terraform resource:
aws_key_pair
aws ec2 run-instances
~/.ssh/config
Activities
- Improve this example by adding a security group with ssh access from anywhere: Terraform resource: aws security group
See also
terraform apply
[ -auto-approve
| -refresh-only, -destroy | --help ]
, Terraform examples, Still creating...
, Terraform apply examples with errors
terraform
[untaint | fmt
| apply
|show
| state
| init | plan | console | output
| validate
| destroy
| debug
| import
| providers
| get
| graph
| workspaces
| resource
| login
| -var-file
| state mv
| state pull
| state push
| state replace-provider
| state rm
| force-unlock
| env
| tfe
| --version
| remote-exec
| delete on termination
| deprecated commands | terraform --help
]
Advertising: