Skip to content

Commit 9a6afae

Browse files
authored
Merge pull request #77525 from bmcelvee/OSDOCS-10865
OSDOCS-10865: Update command to create VPC in Hosted Control Planes guide tutorial
2 parents 6b20bd2 + 7a4e4b1 commit 9a6afae

File tree

1 file changed

+107
-3
lines changed

1 file changed

+107
-3
lines changed

cloud_experts_tutorials/cloud-experts-getting-started/cloud-experts-getting-started-deploying/cloud-experts-getting-started-hcp.adoc

Lines changed: 107 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,115 @@ In this tutorial, we will create these resources first. We will also set up some
3131
rosa list regions --hosted-cp
3232
----
3333

34-
. Create the VPC. For this tutorial, the following script will create the VPC and its required components for you. It will use the region configured for the `aws` CLI.
34+
. Create the VPC. For this tutorial, the following link:https://github.com/openshift-cs/rosaworkshop/blob/master/rosa-workshop/rosa/resources/setup-vpc.sh[script] creates the VPC and its required components for you. It uses the region configured for the `aws` CLI.
3535
+
36-
[source,terminal]
36+
[source,bash]
3737
----
38-
curl https://raw.githubusercontent.com/openshift-cs/rosaworkshop/master/rosa-workshop/rosa/resources/setup-vpc.sh | bash
38+
#!/bin/bash
39+
40+
set -e
41+
##########
42+
# This script will create the network requirements for a ROSA cluster. This will be
43+
# a public cluster. This creates:
44+
# - VPC
45+
# - Public and private subnets
46+
# - Internet Gateway
47+
# - Relevant route tables
48+
# - NAT Gateway
49+
#
50+
# This will automatically use the region configured for the aws cli
51+
#
52+
##########
53+
54+
VPC_CIDR=10.0.0.0/16
55+
PUBLIC_CIDR_SUBNET=10.0.1.0/24
56+
PRIVATE_CIDR_SUBNET=10.0.0.0/24
57+
58+
# Create VPC
59+
echo -n "Creating VPC..."
60+
VPC_ID=$(aws ec2 create-vpc --cidr-block $VPC_CIDR --query Vpc.VpcId --output text)
61+
62+
# Create tag name
63+
aws ec2 create-tags --resources $VPC_ID --tags Key=Name,Value=$CLUSTER_NAME
64+
65+
# Enable dns hostname
66+
aws ec2 modify-vpc-attribute --vpc-id $VPC_ID --enable-dns-hostnames
67+
echo "done."
68+
69+
# Create Public Subnet
70+
echo -n "Creating public subnet..."
71+
PUBLIC_SUBNET_ID=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $PUBLIC_CIDR_SUBNET --query Subnet.SubnetId --output text)
72+
73+
aws ec2 create-tags --resources $PUBLIC_SUBNET_ID --tags Key=Name,Value=$CLUSTER_NAME-public
74+
echo "done."
75+
76+
# Create private subnet
77+
echo -n "Creating private subnet..."
78+
PRIVATE_SUBNET_ID=$(aws ec2 create-subnet --vpc-id $VPC_ID --cidr-block $PRIVATE_CIDR_SUBNET --query Subnet.SubnetId --output text)
79+
80+
aws ec2 create-tags --resources $PRIVATE_SUBNET_ID --tags Key=Name,Value=$CLUSTER_NAME-private
81+
echo "done."
82+
83+
# Create an internet gateway for outbound traffic and attach it to the VPC.
84+
echo -n "Creating internet gateway..."
85+
IGW_ID=$(aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId --output text)
86+
echo "done."
87+
88+
aws ec2 create-tags --resources $IGW_ID --tags Key=Name,Value=$CLUSTER_NAME
89+
90+
aws ec2 attach-internet-gateway --vpc-id $VPC_ID --internet-gateway-id $IGW_ID > /dev/null 2>&1
91+
echo "Attached IGW to VPC."
92+
93+
# Create a route table for outbound traffic and associate it to the public subnet.
94+
echo -n "Creating route table for public subnet..."
95+
PUBLIC_ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID --query RouteTable.RouteTableId --output text)
96+
97+
aws ec2 create-tags --resources $PUBLIC_ROUTE_TABLE_ID --tags Key=Name,Value=$CLUSTER_NAME
98+
echo "done."
99+
100+
aws ec2 create-route --route-table-id $PUBLIC_ROUTE_TABLE_ID --destination-cidr-block 0.0.0.0/0 --gateway-id $IGW_ID > /dev/null 2>&1
101+
echo "Created default public route."
102+
103+
aws ec2 associate-route-table --subnet-id $PUBLIC_SUBNET_ID --route-table-id $PUBLIC_ROUTE_TABLE_ID > /dev/null 2>&1
104+
echo "Public route table associated"
105+
106+
# Create a NAT gateway in the public subnet for outgoing traffic from the private network.
107+
echo -n "Creating NAT Gateway..."
108+
NAT_IP_ADDRESS=$(aws ec2 allocate-address --domain vpc --query AllocationId --output text)
109+
110+
NAT_GATEWAY_ID=$(aws ec2 create-nat-gateway --subnet-id $PUBLIC_SUBNET_ID --allocation-id $NAT_IP_ADDRESS --query NatGateway.NatGatewayId --output text)
111+
112+
aws ec2 create-tags --resources $NAT_IP_ADDRESS --resources $NAT_GATEWAY_ID --tags Key=Name,Value=$CLUSTER_NAME
113+
sleep 10
114+
echo "done."
115+
116+
# Create a route table for the private subnet to the NAT gateway.
117+
echo -n "Creating a route table for the private subnet to the NAT gateway..."
118+
PRIVATE_ROUTE_TABLE_ID=$(aws ec2 create-route-table --vpc-id $VPC_ID --query RouteTable.RouteTableId --output text)
119+
120+
aws ec2 create-tags --resources $PRIVATE_ROUTE_TABLE_ID $NAT_IP_ADDRESS --tags Key=Name,Value=$CLUSTER_NAME-private
121+
122+
aws ec2 create-route --route-table-id $PRIVATE_ROUTE_TABLE_ID --destination-cidr-block 0.0.0.0/0 --gateway-id $NAT_GATEWAY_ID > /dev/null 2>&1
123+
124+
aws ec2 associate-route-table --subnet-id $PRIVATE_SUBNET_ID --route-table-id $PRIVATE_ROUTE_TABLE_ID > /dev/null 2>&1
125+
126+
echo "done."
127+
128+
# echo "***********VARIABLE VALUES*********"
129+
# echo "VPC_ID="$VPC_ID
130+
# echo "PUBLIC_SUBNET_ID="$PUBLIC_SUBNET_ID
131+
# echo "PRIVATE_SUBNET_ID="$PRIVATE_SUBNET_ID
132+
# echo "PUBLIC_ROUTE_TABLE_ID="$PUBLIC_ROUTE_TABLE_ID
133+
# echo "PRIVATE_ROUTE_TABLE_ID="$PRIVATE_ROUTE_TABLE_ID
134+
# echo "NAT_GATEWAY_ID="$NAT_GATEWAY_ID
135+
# echo "IGW_ID="$IGW_ID
136+
# echo "NAT_IP_ADDRESS="$NAT_IP_ADDRESS
137+
138+
echo "Setup complete."
139+
echo ""
140+
echo "To make the cluster create commands easier, please run the following commands to set the environment variables:"
141+
echo "export PUBLIC_SUBNET_ID=$PUBLIC_SUBNET_ID"
142+
echo "export PRIVATE_SUBNET_ID=$PRIVATE_SUBNET_ID"
39143
----
40144
+
41145
For more about VPC requirements, see the xref:../../../rosa_planning/rosa-sts-aws-prereqs.adoc#rosa-vpc_rosa-sts-aws-prereqs[VPC documentation].

0 commit comments

Comments
 (0)