@@ -84,6 +84,24 @@ func resourceAwsApiGatewayV2DomainName() *schema.Resource {
84
84
},
85
85
},
86
86
},
87
+ "mutual_tls_authentication" : {
88
+ Type : schema .TypeList ,
89
+ Optional : true ,
90
+ MaxItems : 1 ,
91
+ Elem : & schema.Resource {
92
+ Schema : map [string ]* schema.Schema {
93
+ "truststore_uri" : {
94
+ Type : schema .TypeString ,
95
+ Required : true ,
96
+ ForceNew : true ,
97
+ },
98
+ "truststore_version" : {
99
+ Type : schema .TypeString ,
100
+ Optional : true ,
101
+ },
102
+ },
103
+ },
104
+ },
87
105
"tags" : tagsSchema (),
88
106
},
89
107
}
@@ -95,6 +113,7 @@ func resourceAwsApiGatewayV2DomainNameCreate(d *schema.ResourceData, meta interf
95
113
req := & apigatewayv2.CreateDomainNameInput {
96
114
DomainName : aws .String (d .Get ("domain_name" ).(string )),
97
115
DomainNameConfigurations : expandApiGatewayV2DomainNameConfiguration (d .Get ("domain_name_configuration" ).([]interface {})),
116
+ MutualTlsAuthentication : expandApiGatewayV2MutualTlsAuthentication (d .Get ("mutual_tls_authentication" ).([]interface {})),
98
117
Tags : keyvaluetags .New (d .Get ("tags" ).(map [string ]interface {})).IgnoreAws ().Apigatewayv2Tags (),
99
118
}
100
119
@@ -138,6 +157,10 @@ func resourceAwsApiGatewayV2DomainNameRead(d *schema.ResourceData, meta interfac
138
157
if err != nil {
139
158
return fmt .Errorf ("error setting domain_name_configuration: %s" , err )
140
159
}
160
+ err = d .Set ("mutual_tls_authentication" , flattenApiGatewayV2MutualTlsAuthentication (resp .MutualTlsAuthentication ))
161
+ if err != nil {
162
+ return fmt .Errorf ("error setting mutual_tls_authentication: %s" , err )
163
+ }
141
164
if err := d .Set ("tags" , keyvaluetags .Apigatewayv2KeyValueTags (resp .Tags ).IgnoreAws ().IgnoreConfig (ignoreTagsConfig ).Map ()); err != nil {
142
165
return fmt .Errorf ("error setting tags: %s" , err )
143
166
}
@@ -148,10 +171,27 @@ func resourceAwsApiGatewayV2DomainNameRead(d *schema.ResourceData, meta interfac
148
171
func resourceAwsApiGatewayV2DomainNameUpdate (d * schema.ResourceData , meta interface {}) error {
149
172
conn := meta .(* AWSClient ).apigatewayv2conn
150
173
151
- if d .HasChange ("domain_name_configuration" ) {
174
+ if d .HasChanges ("domain_name_configuration" , "mutual_tls_authentication " ) {
152
175
req := & apigatewayv2.UpdateDomainNameInput {
153
- DomainName : aws .String (d .Id ()),
154
- DomainNameConfigurations : expandApiGatewayV2DomainNameConfiguration (d .Get ("domain_name_configuration" ).([]interface {})),
176
+ DomainName : aws .String (d .Id ()),
177
+ }
178
+
179
+ if d .HasChange ("domain_name_configuration" ) {
180
+ req .DomainNameConfigurations = expandApiGatewayV2DomainNameConfiguration (d .Get ("domain_name_configuration" ).([]interface {}))
181
+ }
182
+ if d .HasChange ("mutual_tls_authentication" ) {
183
+ vMutualTlsAuthentication := d .Get ("mutual_tls_authentication" ).([]interface {})
184
+
185
+ if len (vMutualTlsAuthentication ) == 0 || vMutualTlsAuthentication [0 ] == nil {
186
+ // To disable mutual TLS for a custom domain name, remove the truststore from your custom domain name.
187
+ req .MutualTlsAuthentication = & apigatewayv2.MutualTlsAuthenticationInput {
188
+ TruststoreUri : aws .String ("" ),
189
+ }
190
+ } else {
191
+ req .MutualTlsAuthentication = & apigatewayv2.MutualTlsAuthenticationInput {
192
+ TruststoreVersion : aws .String (vMutualTlsAuthentication [0 ].(map [string ]interface {})["truststore_version" ].(string )),
193
+ }
194
+ }
155
195
}
156
196
157
197
log .Printf ("[DEBUG] Updating API Gateway v2 domain name: %s" , req )
@@ -258,3 +298,31 @@ func flattenApiGatewayV2DomainNameConfiguration(domainNameConfiguration *apigate
258
298
"target_domain_name" : aws .StringValue (domainNameConfiguration .ApiGatewayDomainName ),
259
299
}}
260
300
}
301
+
302
+ func expandApiGatewayV2MutualTlsAuthentication (vMutualTlsAuthentication []interface {}) * apigatewayv2.MutualTlsAuthenticationInput {
303
+ if len (vMutualTlsAuthentication ) == 0 || vMutualTlsAuthentication [0 ] == nil {
304
+ return nil
305
+ }
306
+ mMutualTlsAuthentication := vMutualTlsAuthentication [0 ].(map [string ]interface {})
307
+
308
+ mutualTlsAuthentication := & apigatewayv2.MutualTlsAuthenticationInput {
309
+ TruststoreUri : aws .String (mMutualTlsAuthentication ["truststore_uri" ].(string )),
310
+ }
311
+
312
+ if vTruststoreVersion , ok := mMutualTlsAuthentication ["truststore_version" ].(string ); ok && vTruststoreVersion != "" {
313
+ mutualTlsAuthentication .TruststoreVersion = aws .String (vTruststoreVersion )
314
+ }
315
+
316
+ return mutualTlsAuthentication
317
+ }
318
+
319
+ func flattenApiGatewayV2MutualTlsAuthentication (mutualTlsAuthentication * apigatewayv2.MutualTlsAuthentication ) []interface {} {
320
+ if mutualTlsAuthentication == nil {
321
+ return []interface {}{}
322
+ }
323
+
324
+ return []interface {}{map [string ]interface {}{
325
+ "truststore_uri" : aws .StringValue (mutualTlsAuthentication .TruststoreUri ),
326
+ "truststore_version" : aws .StringValue (mutualTlsAuthentication .TruststoreVersion ),
327
+ }}
328
+ }
0 commit comments