Resource: aws_s3_bucket_website_configuration#
Manages an S3 bucket website configuration. For more information about hosting websites on S3, see user documentation.
Example Usage#
resource "aws_s3_bucket_website_configuration" "example" {
bucket = aws_s3_bucket.example.bucket
index_document {
suffix = "index.html"
}
error_document {
key = "error.html"
}
routing_rule {
condition {
key_prefix_equals = "docs/"
}
redirect {
replace_key_prefix_with = "documents/"
}
}
}
Argument Reference#
The following arguments are supported:
bucket- (Required, Forces new resource) The name of the bucket.error_document- (Optional, Conflicts withredirect_all_requests_to) The name of the error document for the website detailed below.index_document- (Optional) The name of the index document for the website detailed below.- Constraints: Required if
redirect_all_requests_tois not specified
- Constraints: Required if
redirect_all_requests_to- (Optional) The redirect behavior for every request to this bucket's website endpoint detailed below.- Constraints: Required if
index_documentis not specified. Conflicts witherror_document,index_document, androuting_rule.
- Constraints: Required if
routing_rule- (Optional, Conflicts withredirect_all_requests_to) List of rules that define when a redirect is applied and the redirect behavior detailed below.
error_document#
The error_document configuration block supports the following arguments:
key- (Required) The object key name to use when a 4XX class error occurs.
index_document#
The index_document configuration block supports the following arguments:
suffix- (Required) A suffix that is appended to a request that is for a directory on the website endpoint. For example, if the suffix isindex.htmland you make a request tosamplebucket/images/, the data that is returned will be for the object with the key nameimages/index.html. The suffix must not be empty and must not include a slash character.
redirect_all_requests_to#
The redirect_all_requests_to configuration block supports the following arguments:
host_name- (Required) Name of the host where requests are redirected.protocol- (Optional) Protocol to use when redirecting requests. The default is the protocol that is used in the original request.- Valid values:
http,https
- Valid values:
routing_rule#
The routing_rule configuration block supports the following arguments:
condition- (Optional) A configuration block for describing a condition that must be met for the specified redirect to apply detailed below.redirect- (Required) A configuration block for redirect information detailed below.
condition#
The condition configuration block supports the following arguments:
http_error_code_returned_equals- (Optional) The HTTP error code when the redirect is applied. If specified withkey_prefix_equals, then both must be true for the redirect to be applied.- Constraints: Required if
key_prefix_equalsis not specified
- Constraints: Required if
key_prefix_equals- (Optional) The object key name prefix when the redirect is applied. If specified withhttp_error_code_returned_equals, then both must be true for the redirect to be applied.- Constraints: Required if
http_error_code_returned_equalsis not specified
- Constraints: Required if
redirect#
The redirect configuration block supports the following arguments:
host_name- (Optional) The host name to use in the redirect request.protocol- (Optional) Protocol to use when redirecting requests. The default is the protocol that is used in the original request.- Valid values:
http,https
- Valid values:
replace_key_prefix_with- (Optional, Conflicts withreplace_key_with) The object key prefix to use in the redirect request. For example, to redirect requests for all pages with prefixdocs/(objects in thedocs/folder) todocuments/, you can set aconditionblock withkey_prefix_equalsset todocs/and in theredirectsetreplace_key_prefix_withto/documents.replace_key_with- (Optional, Conflicts withreplace_key_prefix_with) The specific object key to use in the redirect request. For example, redirect request toerror.html.
Attribute Reference#
Supported attributes#
In addition to all arguments above, the following attributes are exported:
id- Thebucket.
Unsupported attributes#
~> Note These attributes may be present in the terraform.tfstate file, but they have preset values and cannot be specified in configuration files.
The following attributes are not currently supported:
expected_bucket_owner, redirect.http_redirect_code, website_domain, website_endpoint.
Import#
S3 bucket website configuration can be imported using the bucket e.g.,
$ terraform import aws_s3_bucket_website_configuration.example bucket-name