This repository was archived by the owner on Jul 20, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-9
lines changed Expand file tree Collapse file tree 1 file changed +24
-9
lines changed Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ See [init.sh](data/init.sh) for details.
69
69
70
70
## Configuration
71
71
72
- ### Extra IAM policy
72
+ ### Set extra IAM policies
73
73
74
74
You can attach an extra policy to the IAM role of the NAT instance. For example,
75
75
93
93
}
94
94
```
95
95
96
- ### Extra script
96
+ ### Run a script
97
97
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:
99
102
100
103
``` tf
101
104
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
+ })
105
108
}
106
109
```
107
110
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
+
109
120
110
- ### Open SSH port
121
+ ### Allow SSH access
111
122
112
- You can open the SSH port to the NAT instance.
123
+ For example,
113
124
114
125
``` tf
126
+ module "nat" {
127
+ key_name = "YOUR_KEY_PAIR"
128
+ }
129
+
115
130
resource "aws_security_group_rule" "nat_ssh" {
116
131
security_group_id = module.nat.sg_id
117
132
type = "ingress"
You can’t perform that action at this time.
0 commit comments