Skip to content

Commit 3b672f3

Browse files
committed
test terraform fix
1 parent 7709b3f commit 3b672f3

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

.github/workflows/client-deployment.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,26 @@ jobs:
128128
steps:
129129
- name: Checkout repo
130130
uses: actions/checkout@v4
131+
132+
- name: Install SSH tools
133+
run: sudo apt-get install -y openssh-client
131134

132-
- name: Setup SSH private key
135+
- name: Write private key to file
133136
run: |
134-
mkdir -p ~/.ssh
135-
echo "${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
136-
chmod 600 ~/.ssh/id_rsa
137+
echo "${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}" > private-key.pem
138+
chmod 600 private-key.pem
139+
140+
141+
- name: Generate public key
142+
run: |
143+
ssh-keygen -y -f private-key.pem > public-key.pub
144+
cat public-key.pub # optional, for debug
145+
146+
# - name: Setup SSH private key
147+
# run: |
148+
# mkdir -p ~/.ssh
149+
# echo "${{ secrets.AWS_EC2_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
150+
# chmod 600 ~/.ssh/id_rsa
137151

138152
- name: Setup Terraform
139153
uses: hashicorp/setup-terraform@v2
@@ -154,7 +168,7 @@ jobs:
154168
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
155169
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
156170
AWS_REGION: us-east-1
157-
run: terraform plan -out=tfplan
171+
run: terraform plan -var="public_key=$(cat public-key.pub)" -out=tfplan
158172

159173
- name: Terraform Apply
160174
working-directory: ./terraform

terraform/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ provider "aws" {
33
}
44

55
resource "aws_key_pair" "deployer" {
6-
key_name = "client-app"
7-
public_key = file(var.public_key_path)
6+
key_name = "ec2"
7+
public_key = var.public_key
88
}
99

1010
resource "aws_instance" "react_app" {

terraform/variables.tf

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
variable "public_key_path" {
2-
description = "Path to your public SSH key"
3-
# default = "~/.ssh/id_rsa.pub"
4-
default = "/home/runner/.ssh/id_rsa.pub"
1+
variable "public_key" {
2+
type = string
3+
description = "public SSH key"
54
}
65

76
variable "ami_id" {

0 commit comments

Comments
 (0)