-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/apigateway authorization scopes #4533
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,12 @@ func resourceAwsApiGatewayMethod() *schema.Resource { | |
Optional: true, | ||
}, | ||
|
||
"authorization_scopes": &schema.Schema{ | ||
Type: schema.TypeList, | ||
Optional: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
|
||
"api_key_required": &schema.Schema{ | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
|
@@ -126,6 +132,10 @@ func resourceAwsApiGatewayMethodCreate(d *schema.ResourceData, meta interface{}) | |
input.AuthorizerId = aws.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("authorization_scopes"); ok { | ||
input.AuthorizationScopes = expandStringList(v.([]interface{})) | ||
} | ||
|
||
if v, ok := d.GetOk("request_validator_id"); ok { | ||
input.RequestValidatorId = aws.String(v.(string)) | ||
} | ||
|
@@ -165,6 +175,7 @@ func resourceAwsApiGatewayMethodRead(d *schema.ResourceData, meta interface{}) e | |
d.Set("api_key_required", out.ApiKeyRequired) | ||
d.Set("authorization", out.AuthorizationType) | ||
d.Set("authorizer_id", out.AuthorizerId) | ||
d.Set("authorization_scopes", out.AuthorizationScopes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When setting non-scalar attributes, we should perform error checking: if err := d.Set("authorization_scopes", out.AUthorizationScopes); err != nil {
return fmt.Errorf("error setting authorization_scopes: %s", err)
} |
||
d.Set("request_models", aws.StringValueMap(out.RequestModels)) | ||
d.Set("request_validator_id", out.RequestValidatorId) | ||
|
||
|
@@ -229,6 +240,35 @@ func resourceAwsApiGatewayMethodUpdate(d *schema.ResourceData, meta interface{}) | |
}) | ||
} | ||
|
||
if d.HasChange("authorization_scopes") { | ||
o, n := d.GetChange("authorization_scopes") | ||
path := "/authorizationScopes" | ||
|
||
old := o.([]interface{}) | ||
new := n.([]interface{}) | ||
|
||
// Remove every authorization scope. Simpler to remove and add new ones, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note here: If we switch this to It seems like we should try to reduce any downtime associated with updating these if possible. |
||
// since there are no replacings. | ||
for _, v := range old { | ||
operations = append(operations, &apigateway.PatchOperation{ | ||
Op: aws.String("remove"), | ||
Path: aws.String(path), | ||
Value: aws.String(v.(string)), | ||
}) | ||
} | ||
|
||
// Handle additions | ||
if len(new) > 0 { | ||
for _, v := range new { | ||
operations = append(operations, &apigateway.PatchOperation{ | ||
Op: aws.String("add"), | ||
Path: aws.String(path), | ||
Value: aws.String(v.(string)), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
if d.HasChange("api_key_required") { | ||
operations = append(operations, &apigateway.PatchOperation{ | ||
Op: aws.String("replace"), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the ordering matter for this attribute? If not, we can use
schema.TypeSet
which has some nice helpers for doing set differences. See also: https://www.terraform.io/docs/extend/schemas/schema-types.html#typeset