Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit 671d99f

Browse files
authored
Update README.md
1 parent c9894cd commit 671d99f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ See [init.sh](data/init.sh) for details.
6969

7070
## Configuration
7171

72-
### Extra IAM policy
72+
### Set extra IAM policies
7373

7474
You can attach an extra policy to the IAM role of the NAT instance. For example,
7575

@@ -93,25 +93,40 @@ EOF
9393
}
9494
```
9595

96-
### Extra script
96+
### Run a script
9797

98-
You can set an extra script to run in the NAT instance. For example,
98+
You can set an extra script to run in the NAT instance.
99+
The current region is exported as `AWS_DEFAULT_REGION` and you can use awscli without a region option.
100+
101+
For example, you can expose port 8080 of the NAT instance using DNAT:
99102

100103
```tf
101104
module "nat" {
102-
extra_user_data = <<EOF
103-
# ...
104-
EOF
105+
extra_user_data = templatefile("${path.module}/data/nat-port-forward.sh", {
106+
eni_private_ip = module.nat.eni_private_ip
107+
})
105108
}
106109
```
107110

108-
The current region is exported as `AWS_DEFAULT_REGION` and you can use awscli without a region option.
111+
```sh
112+
# Look up the target instance
113+
tag_name="TARGET_TAG"
114+
target_private_ip="$(aws ec2 describe-instances --filters "Name=tag:Name,Values=$tag_name" | jq -r .Reservations[0].Instances[0].PrivateIpAddress)"
115+
116+
# Expose the port of the NAT instance.
117+
iptables -t nat -A PREROUTING -m tcp -p tcp --dst "${eni_private_ip}" --dport 8080 -j DNAT --to-destination "$target_private_ip:8080"
118+
```
119+
109120

110-
### Open SSH port
121+
### Allow SSH access
111122

112-
You can open the SSH port to the NAT instance.
123+
For example,
113124

114125
```tf
126+
module "nat" {
127+
key_name = "YOUR_KEY_PAIR"
128+
}
129+
115130
resource "aws_security_group_rule" "nat_ssh" {
116131
security_group_id = module.nat.sg_id
117132
type = "ingress"

0 commit comments

Comments
 (0)