2016-04-14 21:55:11 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2016-09-11 22:58:07 +02:00
|
|
|
"fmt"
|
2016-04-14 21:55:11 +02:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2016-12-05 14:31:05 +01:00
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
2016-04-14 21:55:11 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/cloudfront"
|
2016-10-09 20:51:16 +02:00
|
|
|
"github.com/hashicorp/errwrap"
|
2016-04-14 21:55:11 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func resourceAwsCloudFrontDistribution() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceAwsCloudFrontDistributionCreate,
|
|
|
|
Read: resourceAwsCloudFrontDistributionRead,
|
|
|
|
Update: resourceAwsCloudFrontDistributionUpdate,
|
|
|
|
Delete: resourceAwsCloudFrontDistributionDelete,
|
2016-07-12 23:18:37 +02:00
|
|
|
Importer: &schema.ResourceImporter{
|
|
|
|
State: resourceAwsCloudFrontDistributionImport,
|
|
|
|
},
|
2016-04-14 21:55:11 +02:00
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-09-23 13:46:27 +02:00
|
|
|
"arn": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"aliases": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
Set: aliasesHash,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"cache_behavior": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Set: cacheBehaviorHash,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"allowed_methods": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"cached_methods": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"compress": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"default_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"forwarded_values": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: forwardedValuesHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"cookies": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
2016-05-05 22:44:35 +02:00
|
|
|
Required: true,
|
2016-04-14 21:55:11 +02:00
|
|
|
Set: cookiePreferenceHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"forward": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"whitelisted_names": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"headers": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"query_string": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"query_string_cache_keys": {
|
2016-09-11 05:26:19 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-04-14 21:55:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-12-31 21:37:26 +01:00
|
|
|
"lambda_function_association": {
|
2017-01-06 16:59:03 +01:00
|
|
|
Type: schema.TypeList,
|
2016-12-31 21:37:26 +01:00
|
|
|
Optional: true,
|
|
|
|
MaxItems: 4,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"event_type": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
"lambda_arn": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"max_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"min_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"path_pattern": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"smooth_streaming": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"target_origin_id": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"trusted_signers": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"viewer_protocol_policy": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"comment": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"custom_error_response": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Set: customErrorResponseHash,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"error_caching_min_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"error_code": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"response_code": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"response_page_path": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"default_cache_behavior": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: defaultCacheBehaviorHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"allowed_methods": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"cached_methods": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"compress": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"default_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"forwarded_values": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: forwardedValuesHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"cookies": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Set: cookiePreferenceHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"forward": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"whitelisted_names": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"headers": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"query_string": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"query_string_cache_keys": {
|
2016-09-11 05:26:19 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-04-14 21:55:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-12-31 21:37:26 +01:00
|
|
|
"lambda_function_association": {
|
2017-01-06 16:59:03 +01:00
|
|
|
Type: schema.TypeList,
|
2016-12-31 21:37:26 +01:00
|
|
|
Optional: true,
|
|
|
|
MaxItems: 4,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"event_type": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
"lambda_arn": {
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"max_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"min_ttl": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"smooth_streaming": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"target_origin_id": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"trusted_signers": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"viewer_protocol_policy": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"default_root_object": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"enabled": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"http_version": {
|
2016-09-11 22:58:07 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "http2",
|
|
|
|
ValidateFunc: validateHTTP,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"logging_config": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Set: loggingConfigHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"bucket": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"include_cookies": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"prefix": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: originHash,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"custom_origin_config": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"origin.s3_origin_config"},
|
|
|
|
Set: customOriginConfigHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"http_port": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"https_port": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin_protocol_policy": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin_ssl_protocols": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Required: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"domain_name": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"custom_header": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
Set: originCustomHeaderHash,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"name": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"value": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin_id": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin_path": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"s3_origin_config": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"origin.custom_origin_config"},
|
|
|
|
Set: s3OriginConfigHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"origin_access_identity": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
2016-09-11 05:46:34 +02:00
|
|
|
Required: true,
|
2016-04-14 21:55:11 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"price_class": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "PriceClass_All",
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"restrictions": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: restrictionsHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"geo_restriction": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: geoRestrictionHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"locations": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeList,
|
|
|
|
Optional: true,
|
|
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"restriction_type": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"viewer_certificate": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeSet,
|
|
|
|
Required: true,
|
|
|
|
Set: viewerCertificateHash,
|
|
|
|
MaxItems: 1,
|
|
|
|
Elem: &schema.Resource{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-10-09 20:51:16 +02:00
|
|
|
"acm_certificate_arn": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"viewer_certificate.cloudfront_default_certificate", "viewer_certificate.iam_certificate_id"},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"cloudfront_default_certificate": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"viewer_certificate.acm_certificate_arn", "viewer_certificate.iam_certificate_id"},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"iam_certificate_id": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
ConflictsWith: []string{"viewer_certificate.acm_certificate_arn", "viewer_certificate.cloudfront_default_certificate"},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"minimum_protocol_version": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
Default: "SSLv3",
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"ssl_support_method": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"web_acl_id": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"caller_reference": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"status": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"active_trusted_signers": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeMap,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"domain_name": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"last_modified_time": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"in_progress_validation_batches": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeInt,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"etag": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-10-09 20:51:16 +02:00
|
|
|
"hosted_zone_id": {
|
2016-05-09 01:40:30 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
2016-04-14 21:55:11 +02:00
|
|
|
// retain_on_delete is a non-API attribute that may help facilitate speedy
|
|
|
|
// deletion of a resoruce. It's mainly here for testing purposes, so
|
|
|
|
// enable at your own risk.
|
2016-10-09 20:51:16 +02:00
|
|
|
"retain_on_delete": {
|
2016-04-14 21:55:11 +02:00
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
2016-11-30 13:13:30 +01:00
|
|
|
"is_ipv6_enabled": {
|
|
|
|
Type: schema.TypeBool,
|
|
|
|
Optional: true,
|
|
|
|
Default: false,
|
|
|
|
},
|
2016-09-23 13:46:27 +02:00
|
|
|
|
|
|
|
"tags": tagsSchema(),
|
2016-04-14 21:55:11 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsCloudFrontDistributionCreate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
conn := meta.(*AWSClient).cloudfrontconn
|
2016-09-23 13:46:27 +02:00
|
|
|
|
|
|
|
params := &cloudfront.CreateDistributionWithTagsInput{
|
|
|
|
DistributionConfigWithTags: &cloudfront.DistributionConfigWithTags{
|
|
|
|
DistributionConfig: expandDistributionConfig(d),
|
|
|
|
Tags: tagsFromMapCloudFront(d.Get("tags").(map[string]interface{})),
|
|
|
|
},
|
2016-04-14 21:55:11 +02:00
|
|
|
}
|
|
|
|
|
2016-09-23 13:46:27 +02:00
|
|
|
resp, err := conn.CreateDistributionWithTags(params)
|
2016-04-14 21:55:11 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d.SetId(*resp.Distribution.Id)
|
|
|
|
return resourceAwsCloudFrontDistributionRead(d, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsCloudFrontDistributionRead(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
conn := meta.(*AWSClient).cloudfrontconn
|
|
|
|
params := &cloudfront.GetDistributionInput{
|
|
|
|
Id: aws.String(d.Id()),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.GetDistribution(params)
|
|
|
|
if err != nil {
|
2016-12-05 14:31:05 +01:00
|
|
|
if errcode, ok := err.(awserr.Error); ok && errcode.Code() == "NoSuchDistribution" {
|
|
|
|
log.Printf("[WARN] No Distribution found: %s", d.Id())
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-14 21:55:11 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update attributes from DistributionConfig
|
2016-04-19 23:40:30 +02:00
|
|
|
err = flattenDistributionConfig(d, resp.Distribution.DistributionConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-04-14 21:55:11 +02:00
|
|
|
// Update other attributes outside of DistributionConfig
|
|
|
|
d.SetId(*resp.Distribution.Id)
|
2016-04-19 23:40:30 +02:00
|
|
|
err = d.Set("active_trusted_signers", flattenActiveTrustedSigners(resp.Distribution.ActiveTrustedSigners))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
d.Set("status", resp.Distribution.Status)
|
|
|
|
d.Set("domain_name", resp.Distribution.DomainName)
|
2016-04-14 21:55:11 +02:00
|
|
|
d.Set("last_modified_time", aws.String(resp.Distribution.LastModifiedTime.String()))
|
2016-04-19 23:40:30 +02:00
|
|
|
d.Set("in_progress_validation_batches", resp.Distribution.InProgressInvalidationBatches)
|
|
|
|
d.Set("etag", resp.ETag)
|
2016-09-23 13:46:27 +02:00
|
|
|
d.Set("arn", resp.Distribution.ARN)
|
|
|
|
|
2016-10-09 20:51:16 +02:00
|
|
|
tagResp, err := conn.ListTagsForResource(&cloudfront.ListTagsForResourceInput{
|
|
|
|
Resource: aws.String(d.Get("arn").(string)),
|
2016-09-23 13:46:27 +02:00
|
|
|
})
|
|
|
|
|
2016-10-09 20:51:16 +02:00
|
|
|
if err != nil {
|
|
|
|
return errwrap.Wrapf(fmt.Sprintf(
|
|
|
|
"Error retrieving EC2 tags for CloudFront Distribution %q (ARN: %q): {{err}}",
|
|
|
|
d.Id(), d.Get("arn").(string)), err)
|
2016-09-23 13:46:27 +02:00
|
|
|
}
|
|
|
|
|
2016-10-09 20:51:16 +02:00
|
|
|
if err := d.Set("tags", tagsToMapCloudFront(tagResp.Tags)); err != nil {
|
|
|
|
return err
|
2016-09-23 13:46:27 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 21:55:11 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsCloudFrontDistributionUpdate(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
conn := meta.(*AWSClient).cloudfrontconn
|
|
|
|
params := &cloudfront.UpdateDistributionInput{
|
|
|
|
Id: aws.String(d.Id()),
|
|
|
|
DistributionConfig: expandDistributionConfig(d),
|
|
|
|
IfMatch: aws.String(d.Get("etag").(string)),
|
|
|
|
}
|
|
|
|
_, err := conn.UpdateDistribution(params)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-09-23 13:46:27 +02:00
|
|
|
if err := setTagsCloudFront(conn, d, d.Get("arn").(string)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-04-14 21:55:11 +02:00
|
|
|
return resourceAwsCloudFrontDistributionRead(d, meta)
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceAwsCloudFrontDistributionDelete(d *schema.ResourceData, meta interface{}) error {
|
|
|
|
conn := meta.(*AWSClient).cloudfrontconn
|
|
|
|
|
|
|
|
// manually disable the distribution first
|
|
|
|
d.Set("enabled", false)
|
|
|
|
err := resourceAwsCloudFrontDistributionUpdate(d, meta)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// skip delete if retain_on_delete is enabled
|
|
|
|
if d.Get("retain_on_delete").(bool) {
|
2016-10-09 20:51:16 +02:00
|
|
|
log.Printf("[WARN] Removing CloudFront Distribution ID %q with `retain_on_delete` set. Please delete this distribution manually.", d.Id())
|
2016-04-14 21:55:11 +02:00
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Distribution needs to be in deployed state again before it can be deleted.
|
2016-04-19 23:40:30 +02:00
|
|
|
err = resourceAwsCloudFrontDistributionWaitUntilDeployed(d.Id(), meta)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-04-14 21:55:11 +02:00
|
|
|
|
|
|
|
// now delete
|
|
|
|
params := &cloudfront.DeleteDistributionInput{
|
|
|
|
Id: aws.String(d.Id()),
|
|
|
|
IfMatch: aws.String(d.Get("etag").(string)),
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = conn.DeleteDistribution(params)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Done
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// resourceAwsCloudFrontWebDistributionWaitUntilDeployed blocks until the
|
|
|
|
// distribution is deployed. It currently takes exactly 15 minutes to deploy
|
|
|
|
// but that might change in the future.
|
|
|
|
func resourceAwsCloudFrontDistributionWaitUntilDeployed(id string, meta interface{}) error {
|
|
|
|
stateConf := &resource.StateChangeConf{
|
|
|
|
Pending: []string{"InProgress", "Deployed"},
|
|
|
|
Target: []string{"Deployed"},
|
|
|
|
Refresh: resourceAwsCloudFrontWebDistributionStateRefreshFunc(id, meta),
|
|
|
|
Timeout: 40 * time.Minute,
|
|
|
|
MinTimeout: 15 * time.Second,
|
|
|
|
Delay: 10 * time.Minute,
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := stateConf.WaitForState()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// The refresh function for resourceAwsCloudFrontWebDistributionWaitUntilDeployed.
|
|
|
|
func resourceAwsCloudFrontWebDistributionStateRefreshFunc(id string, meta interface{}) resource.StateRefreshFunc {
|
|
|
|
return func() (interface{}, string, error) {
|
|
|
|
conn := meta.(*AWSClient).cloudfrontconn
|
|
|
|
params := &cloudfront.GetDistributionInput{
|
|
|
|
Id: aws.String(id),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := conn.GetDistribution(params)
|
|
|
|
if err != nil {
|
2016-10-09 20:51:16 +02:00
|
|
|
log.Printf("[WARN] Error retrieving CloudFront Distribution %q details: %s", id, err)
|
2016-04-14 21:55:11 +02:00
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp == nil {
|
|
|
|
return nil, "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Distribution, *resp.Distribution.Status, nil
|
|
|
|
}
|
|
|
|
}
|
2016-09-11 22:58:07 +02:00
|
|
|
|
|
|
|
// validateHTTP ensures that the http_version resource parameter is
|
|
|
|
// correct.
|
|
|
|
func validateHTTP(v interface{}, k string) (ws []string, errors []error) {
|
|
|
|
value := v.(string)
|
2016-10-09 20:51:16 +02:00
|
|
|
|
|
|
|
if value != "http1.1" && value != "http2" {
|
2016-09-11 22:58:07 +02:00
|
|
|
errors = append(errors, fmt.Errorf(
|
2016-10-09 20:51:16 +02:00
|
|
|
"%q contains an invalid HTTP version parameter %q. Valid parameters are either %q or %q.",
|
|
|
|
k, value, "http1.1", "http2"))
|
2016-09-11 22:58:07 +02:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|