-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
providers/aws: Add support for S3 website redirect #1909
Changes from all 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 |
---|---|---|
|
@@ -38,13 +38,22 @@ func resourceAwsS3Bucket() *schema.Resource { | |
Schema: map[string]*schema.Schema{ | ||
"index_document": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
Optional: true, | ||
}, | ||
|
||
"error_document": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
|
||
"redirect_all_requests_to": &schema.Schema{ | ||
Type: schema.TypeString, | ||
ConflictsWith: []string{ | ||
"website.0.index_document", | ||
"website.0.error_document", | ||
}, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -143,12 +152,18 @@ func resourceAwsS3BucketRead(d *schema.ResourceData, meta interface{}) error { | |
if err == nil { | ||
w := make(map[string]interface{}) | ||
|
||
w["index_document"] = *ws.IndexDocument.Suffix | ||
if v := ws.IndexDocument; v != nil { | ||
w["index_document"] = *v.Suffix | ||
} | ||
|
||
if v := ws.ErrorDocument; v != nil { | ||
w["error_document"] = *v.Key | ||
} | ||
|
||
if v := ws.RedirectAllRequestsTo; v != nil { | ||
w["redirect_all_requests_to"] = *v.HostName | ||
} | ||
|
||
websites = append(websites, w) | ||
} | ||
if err := d.Set("website", websites); err != nil { | ||
|
@@ -235,15 +250,26 @@ func resourceAwsS3BucketWebsitePut(s3conn *s3.S3, d *schema.ResourceData, websit | |
|
||
indexDocument := website["index_document"].(string) | ||
errorDocument := website["error_document"].(string) | ||
redirectAllRequestsTo := website["redirect_all_requests_to"].(string) | ||
|
||
if indexDocument == "" && redirectAllRequestsTo == "" { | ||
return fmt.Errorf("Must specify either index_document or redirect_all_requests_to.") | ||
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. Is there a way to enforce this in the schema? 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. Not at the moment |
||
} | ||
|
||
websiteConfiguration := &s3.WebsiteConfiguration{} | ||
|
||
websiteConfiguration.IndexDocument = &s3.IndexDocument{Suffix: aws.String(indexDocument)} | ||
if indexDocument != "" { | ||
websiteConfiguration.IndexDocument = &s3.IndexDocument{Suffix: aws.String(indexDocument)} | ||
} | ||
|
||
if errorDocument != "" { | ||
websiteConfiguration.ErrorDocument = &s3.ErrorDocument{Key: aws.String(errorDocument)} | ||
} | ||
|
||
if redirectAllRequestsTo != "" { | ||
websiteConfiguration.RedirectAllRequestsTo = &s3.RedirectAllRequestsTo{HostName: aws.String(redirectAllRequestsTo)} | ||
} | ||
|
||
putInput := &s3.PutBucketWebsiteInput{ | ||
Bucket: aws.String(bucket), | ||
WebsiteConfiguration: websiteConfiguration, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,9 @@ The following arguments are supported: | |
|
||
The website object supports the following: | ||
|
||
* `index_document` - (Required) Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders. | ||
* `index_document` - (Required, unless using `redirect_all_requests_to`) Amazon S3 returns this index document when requests are made to the root domain or any of the subfolders. | ||
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. I wasn't sure of the best way to word this. We could just say this is optional, and put a note at the end of the line saying it's required if not specifying 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. Seems fine |
||
* `error_document` - (Optional) An absolute path to the document to return in case of a 4XX error. | ||
* `redirect_all_requests_to` - (Optional) A hostname to redirect all website requests for this bucket to. | ||
|
||
## Attributes Reference | ||
|
||
|
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.
The build is failing because
InternalValidate
inhelper/schema/schema.go
doesn't support this nested notation forConflictsWith
, even though in usage it seems to work correctly.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.
Being the original author of
ConflictsWith
, I know about this limitation, but I was finding it hard to create any nested schema (can't remember what was the problem exactly though), putting asideConflictsWith
.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.
Shouldn't the
website
actually beTypeSet
?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.
@radeksimko we settled on list vs set for this, but I forget why
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.
Fixed with #1926!