CloudFrontをTerraform化!
設定がたくさんありすぎてこれはimportしてからやらないと
ツライ。。
■aws_cloudfront_distribution
https://www.terraform.io/docs/providers/aws/r/cloudfront_distribution.html
相当な設定箇所が・・・・
公式の例ではS3をオリジンにしてコンテンツを置いてるみたいです。
■aws_cloudfront.tf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
resource "aws_cloudfront_distribution" "adachin-web" { enabled = true is_ipv6_enabled = true aliases = ["adachin-web.com"] comment = "adachin-web" origin { domain_name = "adachin-web-xxxxxxx.ap-northeast-1.elb.amazonaws.com" origin_id = "alb-adachin-web" custom_origin_config { http_port = 80 https_port = 5000 origin_keepalive_timeout = 5 origin_protocol_policy = "match-viewer" origin_read_timeout = 60 origin_ssl_protocols = ["TLSv1", "TLSv1.1", "TLSv1.2"] } } restrictions { geo_restriction { restriction_type = "none" } } viewer_certificate { cloudfront_default_certificate = false acm_certificate_arn = "arn:aws:acm:us-east-1:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" minimum_protocol_version = "TLSv1" ssl_support_method = "sni-only" } default_cache_behavior { allowed_methods = ["HEAD", "DELETE", "POST", "GET", "OPTIONS", "PUT", "PATCH"] cached_methods = ["HEAD", "GET", "OPTIONS"] target_origin_id = "alb-adachin-web" forwarded_values { query_string = true cookies { forward = "all" } headers = ["Accept", "Accept-Language", "Authorization", "CloudFront-Forwarded-Proto", "Host", "Origin", "Referer", "User-agent"] } viewer_protocol_policy = "allow-all" min_ttl = 0 max_ttl = 0 default_ttl = 0 } logging_config { bucket = "adachin-web-cf-logs.s3.amazonaws.com" include_cookies = "true" prefix = "[CF] adachin-web.com/" } } |
今回ALBをオリジンに指定してます。
あとは基本デフォルトの設定なのでttl(キャッシュを0)などなど。
ログはS3にぶち込んでます。
■まとめ
メンテナンスモードに切り替えするときに毎回手動で行っていたので
そこらへんterraformで実現可能化今後試す!
リーダーあざす!
0件のコメント