Skip to content

Commit 81604ea

Browse files
committed
Update Terraform documentation (1.15.8)
Fixes #2590.
1 parent 8b1d205 commit 81604ea

3 files changed

Lines changed: 101 additions & 78 deletions

File tree

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,62 @@
11
module Docs
22
class Terraform
33
class CleanHtmlFilter < Filter
4+
# Prism doesn't ship every language the docs use; map those onto the
5+
# closest grammar it does know about.
6+
LANGUAGE_ALIASES = {
7+
'console' => 'shellsession',
8+
# HCL isn't currently supported by Prism, Ruby syntax does an acceptable job for now
9+
'hcl' => 'ruby',
10+
'tf' => 'ruby',
11+
'terraform' => 'ruby',
12+
}
13+
14+
# Languages that carry no syntax at all.
15+
PLAIN_LANGUAGES = %w(documentation plaintext text txt none)
16+
417
def call
5-
@doc = at_css('#inner')
18+
@doc = at_css('#main')
19+
20+
# Chrome that isn't part of the documentation itself.
21+
css('[class*="versionSwitcher"]', '[class*="copy-button"]', 'svg', 'hr').remove
22+
css('a[aria-label$=" permalink"]', 'a[href*="web-unified-docs/blob"]').remove
623

7-
css('hr', 'a.anchor').remove
24+
# Lift the page title out of its wrapper divs.
25+
if heading = at_css('[class*="docs-page-heading_root"]')
26+
heading.css('h1').each { |node| node.remove_attribute('class') }
27+
heading.before(heading.css('h1')).remove
28+
end
829

930
css('.alert').each do |node|
1031
node.name = 'blockquote'
1132
end
1233

1334
css('pre').each do |node|
14-
if language = node['class'][/(json|shell|ruby)/, 1]
35+
if language = language_for(node)
1536
node['data-language'] = language
1637
end
17-
# HCL isn't currently supported by Prism, Ruby syntax does an acceptable job for now
18-
if language = node['class'][/(hcl)/, 1]
19-
node['data-language'] = 'ruby'
20-
end
38+
# Drop the syntax highlighting markup so that Prism can redo it.
2139
node.content = node.content
2240
node.remove_attribute('class')
23-
end
24-
25-
css('.highlight').each do |node|
26-
node.before(node.children).remove
41+
node.remove_attribute('id')
42+
node.remove_attribute('style')
2743
end
2844

2945
doc
3046
end
47+
48+
private
49+
50+
# The language is declared on a wrapper around the <pre>, as "language-hcl".
51+
def language_for(node)
52+
while (node = node.parent) && node.element?
53+
next unless language = node['class'].to_s[/(?:\A|\s)language-([\w-]+)/, 1]
54+
language = language.downcase
55+
return nil if PLAIN_LANGUAGES.include?(language)
56+
return LANGUAGE_ALIASES[language] || language
57+
end
58+
nil
59+
end
3160
end
3261
end
3362
end

‎lib/docs/filters/terraform/entries.rb‎

Lines changed: 46 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,61 @@
11
module Docs
22
class Terraform
33
class EntriesFilter < Docs::EntriesFilter
4-
5-
# Some providers have non-trivial mappings between the directory they live in and their name
6-
# Anything *not* in this list will be capitalized instead.
7-
PROVIDER_NAME_MAP = {
8-
'aws' => 'AWS',
9-
'azure' => 'Azure (Legacy)',
10-
'azurerm' => 'Azure',
11-
'centurylinkcloud' => 'CenturyLinkCloud',
12-
'cloudscale' => 'CloudScale.ch',
13-
'cloudstack' => 'CloudStack',
14-
'dme' => 'DNSMadeEasy',
15-
'dns' => 'DNS',
16-
'dnsimple' => 'DNSimple',
17-
'do' => 'DigitalOcean',
18-
'github' => 'GitHub',
19-
'google' => 'Google Cloud',
20-
'http' => 'HTTP',
21-
'mysql' => 'MySQL',
22-
'newrelic' => 'New Relic',
23-
'oneandone' => '1&1',
24-
'opentelekomcloud' => 'OpenTelekomCloud',
25-
'opsgenie' => 'OpsGenie',
26-
'opc' => 'Oracle Public Cloud',
27-
'oraclepaas' => 'Oracle Cloud Platform',
28-
'ovh' => 'OVH',
29-
'pagerduty' => 'PagerDuty',
30-
'panos' => 'Palo Alto Networks',
31-
'postgresql' => 'PostgreSQL',
32-
'powerdns' => 'PowerDNS',
33-
'profitbricks' => 'ProfitBricks',
34-
'rabbitmq' => 'RabbitMQ',
35-
'softlayer' => 'SoftLayer',
36-
'statuscake' => 'StatusCake',
37-
'tls' => 'TLS',
38-
'ultradns' => 'UltraDNS',
39-
'vcd' => 'VMware vCloud Director',
40-
'nsxt' => 'VMware NSX-T',
41-
'vsphere' => 'VMware vSphere',
42-
}
43-
44-
# Some providers have a lot (> 100) entries, which makes browsing them unwieldy.
45-
# Any present in the list below will have an extra set of types added, breaking the pages out into the different
46-
# products they offer.
47-
LARGE_PROVIDERS = {
48-
"aws" => true,
49-
"azurerm" => true,
50-
"google" => true,
4+
# Fallback types for pages whose sidebar navigation cannot be interpreted,
5+
# keyed by the first segment of the slug.
6+
SECTION_NAME_MAP = {
7+
'cdktf' => 'CDK for Terraform',
8+
'cli' => 'Terraform CLI',
9+
'docs' => 'Documentation',
10+
'intro' => 'Intro to Terraform',
11+
'internals' => 'Internals',
12+
'language' => 'Configuration Language',
13+
'mcp-server' => 'MCP Server',
14+
'migrate' => 'Migrate',
15+
'plugin' => 'Plugin Development',
16+
'policy' => 'Policy Enforcement',
17+
'registry' => 'Registry Publishing',
18+
'tutorials' => 'Tutorials',
5119
}
5220

53-
5421
def get_name
55-
name ||= at_css('#inner h1').content
56-
name.remove! "» "
57-
name.remove! "Data Source: "
58-
name
22+
at_css('#main h1').content.strip
5923
end
6024

6125
def get_type
62-
category, subcategory, subfolder, page = *slug.split('/')
63-
provider = page ? subcategory : category
64-
nice_provider = PROVIDER_NAME_MAP[provider] || provider.capitalize
26+
# The sidebar heading names the section the page belongs to, e.g. "Terraform CLI".
27+
section = at_css('#sidebar-label').try(:content).try(:strip)
28+
root = slug.split('/').first
29+
section = SECTION_NAME_MAP[root] if section.blank?
30+
return 'Terraform' if section.blank?
31+
32+
# Tutorials reuse the same section names as the reference docs
33+
# (e.g. "CLI"), so keep the two apart.
34+
return "Tutorials: #{section}" if root == 'tutorials' && section != 'Tutorials'
35+
36+
group = sidebar_group
37+
group.present? ? "#{section}: #{group}" : section
38+
end
39+
40+
private
41+
42+
# Returns the label of the outermost collapsible group containing the
43+
# current page in the sidebar, e.g. "Provisioning Infrastructure".
44+
def sidebar_group
45+
nav = at_css('#sidebar-nav')
46+
return if nav.nil?
47+
48+
node = nav.at_css('a[aria-current="page"]')
49+
label = nil
6550

66-
if LARGE_PROVIDERS[provider]
67-
category_node = at_css('ul > li > ul > li.active')
68-
parent_node = category_node.parent.previous_element if category_node
69-
nice_provider = nice_provider + ": #{parent_node.content}" if category_node
51+
while node && node != nav
52+
node = node.parent
53+
next unless node && node.name == 'li'
54+
button = node.at_css('> button > span')
55+
label = button.content.strip if button
7056
end
7157

72-
nice_provider
58+
label
7359
end
7460
end
7561
end

‎lib/docs/scrapers/terraform.rb‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,34 @@ module Docs
22
class Terraform < UrlScraper
33
self.name = 'Terraform'
44
self.type = 'terraform'
5-
self.release = '0.11.7'
6-
self.base_url = 'https://www.terraform.io/docs/'
7-
self.root_path = 'index.html'
5+
self.release = '1.15.8'
6+
self.base_url = 'https://developer.hashicorp.com/terraform/'
7+
self.root_path = 'docs'
8+
self.initial_paths = %w(internals)
89
self.links = {
910
home: 'https://www.terraform.io/',
1011
code: 'https://github.com/hashicorp/terraform'
1112
}
1213

1314
html_filters.push 'terraform/entries', 'terraform/clean_html'
1415

15-
options[:skip_patterns] = [/enterprise/, /enterprise-legacy/]
16+
options[:trailing_slash] = false
17+
18+
options[:skip_patterns] = [
19+
# HCP Terraform / Terraform Enterprise are separate products
20+
/\Aenterprise/,
21+
/\Acloud-docs/,
22+
# The version switcher links to every past release of the same page
23+
%r{(\A|/)v\d+\.\d+\.x(/|\z)},
24+
]
1625

1726
options[:attribution] = <<-HTML
18-
&copy; 2018 HashiCorp</br>
27+
&copy; 2026 HashiCorp<br>
1928
Licensed under the MPL 2.0 License.
2029
HTML
2130

2231
def get_latest_version(opts)
23-
contents = get_latest_github_release('hashicorp', 'terraform', opts)
24-
contents.sub("v", "")
32+
get_latest_github_release('hashicorp', 'terraform', opts)
2533
end
2634
end
2735
end

0 commit comments

Comments
 (0)