Home > OS >  How do I associate various key names to an ec2 instance in terraform?
How do I associate various key names to an ec2 instance in terraform?

Time:10-10

In the aws_instance resource in Terraform, there is the possibility to associate a Key Pair to the ec2 instance through:

key_name = "deployment-key"

That's fine and it works well. But I need to associate more than one key to an instance.

When I try to use key_name several times it fails with:

The argument "key_name" was already set at instance-main.tf:13,3-11. Each argument may be set only once.

How can I set several key pairs to an instance?

CodePudding user response:

From you question what I understood is you want to associate multiple keys for a single instance. If yes, then it's not possible, the key you mention in terraform config file is for login purpose, so one key should be assigned for login. If you need to add more key, then either you can use user-data or add by logging into the instance manually.

Better to do such of things using 'shell' module in Packer, so that it will be hardened in OS image and don't have to do this things repeatedly.

  • Related