Skip to content

Instantly share code, notes, and snippets.

@cwebberOps
Last active August 29, 2015 14:18
Show Gist options
  • Save cwebberOps/fe9850f4958945116e01 to your computer and use it in GitHub Desktop.
Save cwebberOps/fe9850f4958945116e01 to your computer and use it in GitHub Desktop.
fastly resource
fastly_service 'chef-web-www_prod' do
action :create
domain 'blog.chef.io'
domain 'www.chef.io'
domain 'summit.chef.io'
# Request Conditions
all_www_lb = request_condition 'all_www-lb' do
statement "req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/account\"|| req.url ~ \"^/blog\" || req.url ~ \"^/chef/install.msi\""
end
omnitruck_and_http = request_condition 'omnitruck_and_http' do
statement "(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/chef/install.msi\") && !req.http.Fastly-SSL"
end
not_omitruck = request_condition 'not_omnitruck' do
statement "!(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/chef/install.msi\")"
end
not_www_lb = request_condition 'not_www-lb' do
statement "!(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/account\"|| req.url ~ \"^/blog\" || req.url ~ \"^/chef/install.msi\")"
end
# Backends
backend 'chef-web-www-master.s3-website-us-east-1.amazonaws.com'
backend 'www-lb.chef.io' do
port 443
use_ssl true
request_condition all_www-lb
end
backend 'www-lb.chef.io_http' do
hostname 'www-lb.chef.io'
request_condition omnitruck_and_http
end
# Request Settings
request_setting 'proto_in_hash_key' do
hash_keys 'req.url, req.http.host, req.http.Fastly-SSL'
end
request_setting 'force_ssl' do
force_ssl true
request_condition not_omnitruck
end
request_setting 's3_host_header' do
default_host 'chef-web-www-master.s3-website-us-east-1.amazonaws.com'
request_condition not_www_lb
end
# Cache Conditions
account_mgmt = cache_condition 'account_mgmt' do
statement 'req.url ~ "^/account"'
end
# Cache Settings
cache_setting 'account_mgmt' do
stale_ttl 0
ttl 0
action :pass
cache_condition account_mgmt
end
# Response Conditions
blog_and_301 = response_condition 'blog_and_301' do
statement "req.http.host ~ \"^summit\" && resp.status == 301"
end
# Response Headers
response_header 'blog.domain' do
action :set
destination 'http.location'
source "\"https://www.chef.io/blog\" req.url"
response_conditon blog_and_301
end
end
chef_web_www_prod = fastly_service 'chef-web-www_prod' do
action :create
domain = [
'blog.chef.io',
'www.chef.io',
'summit.chef.io'
]
end
# Request Conditions
all_www_lb = request_condition 'all_www-lb' do
statement "req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/account\"|| req.url ~ \"^/blog\" || req.url ~ \"^/chef/install.msi\""
service chef_web_www_prod
end
omnitruck_and_http = request_condition 'omnitruck_and_http' do
statement "(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/chef/install.msi\") && !req.http.Fastly-SSL"
service chef_web_www_prod
end
not_omitruck = request_condition 'not_omnitruck' do
statement "!(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/chef/install.msi\")"
service chef_web_www_prod
end
not_www_lb = request_condition 'not_www-lb' do
statement "!(req.url ~ \"^/chef/metadata\" || req.url ~ \"^/chef/metadata-server\" || req.url ~ \"^/chef/install.sh\" || req.url ~ \"^/chef/full_list\" || req.url ~ \"^/chef/full_client_list\" || req.url ~ \"^/chef/full_server_list\" || req.url ~ \"^/chef/chef_platform_names\" || req.url ~ \"^/chef/chef_server_platform_names\" || req.url ~ \"^/chef/download\" || req.url ~ \"^/account\"|| req.url ~ \"^/blog\" || req.url ~ \"^/chef/install.msi\")"
service chef_web_www_prod
end
# Backends
backend 'chef-web-www-master.s3-website-us-east-1.amazonaws.com' do
service chef_web_www_prod
end
backend 'www-lb.chef.io' do
port 443
use_ssl true
request_condition all_www-lb
service chef_web_www_prod
end
backend 'www-lb.chef.io_http' do
hostname 'www-lb.chef.io'
request_condition omnitruck_and_http
service chef_web_www_prod
end
# Request Settings
request_setting 'proto_in_hash_key' do
hash_keys 'req.url, req.http.host, req.http.Fastly-SSL'
service chef_web_www_prod
end
request_setting 'force_ssl' do
force_ssl true
request_condition not_omnitruck
service chef_web_www_prod
end
request_setting 's3_host_header' do
default_host 'chef-web-www-master.s3-website-us-east-1.amazonaws.com'
request_condition not_www_lb
service chef_web_www_prod
end
# Cache Conditions
account_mgmt = cache_condition 'account_mgmt' do
statement 'req.url ~ "^/account"'
service chef_web_www_prod
end
# Cache Settings
cache_setting 'account_mgmt' do
action :pass
stale_ttl 0
ttl 0
cache_condition account_mgmt
service chef_web_www_prod
end
# Response Conditions
blog_and_301 = response_condition 'blog_and_301' do
statement "req.http.host ~ \"^summit\" && resp.status == 301"
service chef_web_www_prod
end
# Response Headers
response_header 'blog.domain' do
action :set
destination 'http.location'
source "\"https://www.chef.io/blog\" req.url"
response_conditon blog_and_301
service chef_web_www_prod
end
@paulmooring
Copy link

I'm not familiar with how fastly works/is structured, so take this with a grain of salt.

This resource looks really overloaded from my pov. I'm not conceptually sure what a fastly_service is so maybe it all belongs in single resource but something along the lines of:

fastly_service 'my_service' do
   ...
end

fastly_backend 'backend01' do
  service 'my_service'
  ....
end

fastly_backend 'backend02' do
  service 'my_service'
  conditions [some, array]
  ...
end

fastly_request_setting 'req_set01' do
  conditions [some, array]
  ...
end

Again not knowing fastly that might or might not make sense, but I think the overall idea of smaller chunks leading to more grokable and composable resources stands even if that's a bad example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment