File tree 2 files changed +15
-11
lines changed
2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ func (awsAction *AwsAction) createPrivateEndpoint(pe status.ProjectPrivateEndpoi
23
23
if err != nil {
24
24
return v1.PrivateEndpoint {}, err
25
25
}
26
- subnetID , err := session .GetSubnetID ( )
26
+ subnetID , err := session .GetOrCreateSubnetIDForVpc ( vpcID )
27
27
if err != nil {
28
28
return v1.PrivateEndpoint {}, err
29
29
}
Original file line number Diff line number Diff line change @@ -98,24 +98,28 @@ func (s sessionAWS) DeleteVPC(vpcID string) error {
98
98
return nil
99
99
}
100
100
101
- func (s sessionAWS ) GetSubnetID ( ) (string , error ) {
101
+ func (s sessionAWS ) GetOrCreateSubnetIDForVpc ( vpcID string ) (string , error ) {
102
102
input := & ec2.DescribeSubnetsInput {
103
- Filters : []* ec2.Filter {{
104
- Name : aws .String ("tag:Name" ),
105
- Values : []* string {
106
- aws .String (config .TagName ),
103
+ Filters : []* ec2.Filter {
104
+ {
105
+ Name : aws .String ("vpc-id" ),
106
+ Values : []* string {
107
+ aws .String (vpcID ),
108
+ },
107
109
},
108
- }} ,
110
+ },
109
111
}
112
+
110
113
result , err := s .ec2 .DescribeSubnets (input )
111
114
if err != nil {
112
115
return "" , getError (err )
113
116
}
114
- if len (result .Subnets ) < 1 {
115
- return "" , errors .New ("can not find Subnet" )
117
+
118
+ if len (result .Subnets ) > 0 {
119
+ return * result .Subnets [0 ].SubnetId , nil
116
120
}
117
- fmt . Println ( result )
118
- return * result . Subnets [ 0 ]. SubnetId , nil
121
+
122
+ return s . CreateSubnet ( vpcID , "10.0.0.0/24" , "pe-aws-test" )
119
123
}
120
124
121
125
func (s sessionAWS ) CreateSubnet (vpcID , cidr , testID string ) (string , error ) {
You can’t perform that action at this time.
0 commit comments