├── .gitignore ├── LICENSE ├── README.md ├── aws_image_nixos ├── README.md ├── main.tf ├── update-url-map ├── url_map.nix ├── url_map.tf └── versions.tf ├── deploy_nixos ├── README.md ├── main.tf ├── maybe-sudo.sh ├── nixos-deploy.sh ├── nixos-instantiate.sh ├── unpack-keys.sh └── versions.tf ├── examples ├── google │ ├── deploy_nixos.tf │ ├── image_nixos.tf │ ├── image_nixos_custom.nix │ ├── image_nixos_custom.tf │ └── provider.tf └── hermetic_config │ ├── configuration.nix │ └── default.tf ├── fmt ├── google_image_nixos ├── README.md ├── main.tf ├── update-url-map ├── url_map.nix ├── url_map.tf └── versions.tf ├── google_image_nixos_custom ├── README.md ├── main.tf ├── nixos-build.sh └── versions.tf ├── nix └── terraform-docs │ └── default.nix ├── scripts └── terraform-docs-updater └── shell.nix /.gitignore: -------------------------------------------------------------------------------- 1 | # Nix 2 | result 3 | result-* 4 | 5 | # Terraform 6 | *.tfstate 7 | *.tfstate.backup 8 | .terraform 9 | .terraform.* 10 | 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-nixos 2 | 3 | [![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org) 4 | 5 | This repository contains a set of Terraform Modules designed to deploy NixOS 6 | machines. These modules are designed to work together and support different 7 | deployment scenarios. 8 | 9 | ## What is Terraform? 10 | 11 | [Terraform][terraform] is a tool that allows to declare infrastructures as 12 | code. 13 | 14 | ## What is Nix, nixpkgs and NixOS? 15 | 16 | [Nix][nix] is a build system and package manager that allows to manage whole 17 | system configurations as code. nixpkgs is a set of 20k+ packages built with 18 | Nix. NixOS is a Linux distribution built on top of nixpkgs. 19 | 20 | ## What is a Terraform Module? 21 | 22 | A Terraform Module refers to a self-contained package of Terraform 23 | configurations that are managed as a group. This repo contains a collection of 24 | Terraform Modules which can be composed together to create useful 25 | infrastructure patterns. 26 | 27 | ## Terraform + Nix vs NixOps 28 | 29 | NixOps is a great tool for personal deployments. It handles a lot of things 30 | like cloud resource creation, machine NixOS bootstrapping and deployment. 31 | 32 | The difficulty is when the cloud resources are not supported by NixOps. It 33 | takes a lot of work to map all the cloud APIs. Compared to NixOps, Terraform 34 | has become an industry standard and has thousands of people contributing new 35 | cloud API mapping all the time. 36 | 37 | Another issue is when sharing the configuration as code with multiple 38 | developers. Both NixOps and Terraform maintain a state file of "known applied" 39 | configuration. Unlike NixOps, Terraform provides facilities to sync and lock 40 | the state file so it's available by other users. 41 | 42 | The approach here is to use Terraform to create all the cloud resources. By 43 | using the `google_image_nixos_custom` module it's possible to pre-build images in 44 | auto-scaling scenarios. Or use a push model similar to NixOps with the generic 45 | `deploy_nixos` module. 46 | 47 | So overall Terraform + Nix is more flexible and scales better. But it's also 48 | more cumbersome to use as it requires to learn two languages instead of one 49 | and the integration between both is also a bit clunky. 50 | 51 | ## Terraform Modules 52 | 53 | The list of modules provided by this project: 54 | 55 | * [deploy_nixos](deploy_nixos#readme) - deploy NixOS onto running NixOS 56 | machines 57 | * [google_image_nixos](google_image_nixos#readme) - setup an official GCE 58 | image into a Google Cloud Project. 59 | * [google_image_nixos_custom](google_image_nixos_custom#readme) - build and 60 | deploy a custom GCE image into a Google Cloud Project 61 | 62 | ## Using these modules from your terraform configuration 63 | 64 | Terraform supports importing [modules](https://www.terraform.io/docs/configuration/modules.html) directly [from a GitHub repository](https://www.terraform.io/docs/modules/sources.html#github). 65 | 66 | For example, to use the [`deploy_nixos`](deploy_nixos#readme) module: 67 | 68 | ``` 69 | module "deploy_nixos" { 70 | source = "github.com/tweag/terraform-nixos//deploy_nixos?ref=ced68729b6a0382dda02401c8f663c9b29c29368" 71 | 72 | … module-specific fields … 73 | } 74 | ``` 75 | 76 | Beware the double `//`, which separates the github repository url from the 77 | subdirectory that contains the module. `?ref=` specifies a specific git ref 78 | of the repository, in this case the commit `ced687…`. 79 | 80 | ## Examples 81 | 82 | To better understand how these modules can be used together, look into the 83 | [./examples](examples) folder. 84 | 85 | ## Related projects 86 | 87 | * [terraform-provider-nix](https://github.com/andrewchambers/terraform-provider-nix) 88 | 89 | ## Future 90 | 91 | * Support other cloud providers. 92 | * Support nixos-infect bootstrapping method. 93 | 94 | Contributions are welcome! 95 | 96 | ## Thanks 97 | 98 | Thanks to [Digital Asset][digital-asset] for generously sponsoring this work! 99 | 100 | Thanks to [Tweag][tweag] for enabling this work and the continuous support! 101 | 102 | ## License 103 | 104 | This code is released under the Apache 2.0 License. Please see 105 | [LICENSE](LICENSE) for more details. 106 | 107 | Copyright © 2018 Tweag I/O. 108 | 109 | 110 | [digital-asset]: https://www.digitalasset.com/ 111 | [nix]: https://nixos.org/nix/ 112 | [terraform]: https://www.terraform.io 113 | [tweag]: https://www.tweag.io/ 114 | -------------------------------------------------------------------------------- /aws_image_nixos/README.md: -------------------------------------------------------------------------------- 1 | # AWS Collection of NixOS AMIs 2 | 3 | This terraform module provides links to official NixOS AMIs on AWS. The AMIs are 4 | released by the NixOS project. 5 | 6 | Since image names are unique, only one instance per version of the module is 7 | supported. 8 | 9 | ## Example 10 | 11 | provider "aws" { 12 | region = "eu-west-1" 13 | } 14 | 15 | module "nixos_image_1903" { 16 | source = "path/to/aws_image_nixos" 17 | release = "19.03" 18 | } 19 | 20 | resource "aws_instance" "example" { 21 | ami = module.nixos_image_1903.ami 22 | instance_type = "t2.micro" 23 | 24 | ... 25 | } 26 | 27 | ## New NixOS releases 28 | 29 | Run the `./update-url-map` script to fetch new image releases. 30 | 31 | 32 | ## Inputs 33 | 34 | | Name | Description | Type | Default | Required | 35 | |------|-------------|:----:|:-----:|:-----:| 36 | | region | The region to use. If not provided, current provider's region will be used. | string | `` | no | 37 | | release | The NixOS version to use. For example, 18.09 | string | `latest` | no | 38 | | type | The type of the AMI to use -- hvm-ebs, pv-ebs, or pv-s3. | string | `hvm-ebs` | no | 39 | | url\_map | A map of release series to actual releases | map | `` | no | 40 | 41 | ## Outputs 42 | 43 | | Name | Description | 44 | |------|-------------| 45 | | ami | NixOS AMI on AWS | 46 | 47 | -------------------------------------------------------------------------------- /aws_image_nixos/main.tf: -------------------------------------------------------------------------------- 1 | variable "release" { 2 | type = string 3 | default = "latest" 4 | description = "The NixOS version to use. For example, 18.09" 5 | } 6 | 7 | variable "region" { 8 | type = string 9 | default = "" 10 | description = "The region to use. If not provided, current provider's region will be used." 11 | } 12 | 13 | variable "type" { 14 | type = string 15 | default = "hvm-ebs" 16 | description = "The type of the AMI to use -- hvm-ebs, pv-ebs, or pv-s3." 17 | } 18 | 19 | # --- 20 | 21 | data "aws_region" "current" {} 22 | 23 | locals { 24 | key = "${var.release}.${coalesce(var.region, data.aws_region.current.name)}.${var.type}" 25 | ami = var.url_map[local.key] 26 | } 27 | 28 | # --- 29 | 30 | output "ami" { 31 | description = "NixOS AMI on AWS" 32 | value = local.ami 33 | } 34 | 35 | -------------------------------------------------------------------------------- /aws_image_nixos/update-url-map: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-shell 2 | #!nix-shell -p python3 -i python 3 | # vim: ft=python 4 | # 5 | # Run this script to update the list of EC2 images 6 | # 7 | import json 8 | import io 9 | from subprocess import check_output 10 | from textwrap import dedent 11 | from os import putenv 12 | 13 | putenv('NIX_PATH', 'nixpkgs=channel:nixpkgs-unstable') 14 | 15 | def render_tf(): 16 | nix_eval = check_output(['nix-instantiate', '--json', '--strict', '--eval', './url_map.nix']) 17 | url_map = json.loads(nix_eval) 18 | 19 | out = io.StringIO() 20 | out.write(dedent("""\ 21 | # DON'T EDIT, run '%s' instead 22 | variable "url_map" { 23 | type = map(string) 24 | 25 | default = { 26 | """ % __file__)) 27 | 28 | for version, regions in url_map.items(): 29 | for region, kinds in regions.items(): 30 | for kind, ami in kinds.items(): 31 | out.write(' "%s.%s.%s" = "%s"\n' % (version, region, kind, ami)) 32 | 33 | out.write(dedent("""\ 34 | } 35 | 36 | description = "A map of release series to actual releases" 37 | } 38 | """)) 39 | 40 | return out.getvalue() 41 | 42 | url_map_tf = render_tf() 43 | 44 | with open("url_map.tf", "w") as f: 45 | f.write(url_map_tf) 46 | 47 | print(url_map_tf) 48 | 49 | # Local Variables: 50 | # mode: Python 51 | # End: 52 | -------------------------------------------------------------------------------- /aws_image_nixos/url_map.nix: -------------------------------------------------------------------------------- 1 | # Indirect link to where the image map is stored 2 | import 3 | -------------------------------------------------------------------------------- /aws_image_nixos/url_map.tf: -------------------------------------------------------------------------------- 1 | # DON'T EDIT, run './update-url-map' instead 2 | variable "url_map" { 3 | type = map(string) 4 | 5 | default = { 6 | "14.04.ap-northeast-1.hvm-ebs" = "ami-71c6f470" 7 | "14.04.ap-northeast-1.pv-ebs" = "ami-4dcbf84c" 8 | "14.04.ap-northeast-1.pv-s3" = "ami-8fc4f68e" 9 | "14.04.ap-southeast-1.hvm-ebs" = "ami-da280888" 10 | "14.04.ap-southeast-1.pv-ebs" = "ami-7a9dbc28" 11 | "14.04.ap-southeast-1.pv-s3" = "ami-c4290996" 12 | "14.04.ap-southeast-2.hvm-ebs" = "ami-ab523e91" 13 | "14.04.ap-southeast-2.pv-ebs" = "ami-6769055d" 14 | "14.04.ap-southeast-2.pv-s3" = "ami-15533f2f" 15 | "14.04.eu-central-1.hvm-ebs" = "ami-ba0234a7" 16 | "14.04.eu-west-1.hvm-ebs" = "ami-96cb63e1" 17 | "14.04.eu-west-1.pv-ebs" = "ami-b48c25c3" 18 | "14.04.eu-west-1.pv-s3" = "ami-06cd6571" 19 | "14.04.sa-east-1.hvm-ebs" = "ami-01b90e1c" 20 | "14.04.sa-east-1.pv-ebs" = "ami-69e35474" 21 | "14.04.sa-east-1.pv-s3" = "ami-61b90e7c" 22 | "14.04.us-east-1.hvm-ebs" = "ami-58ba3a30" 23 | "14.04.us-east-1.pv-ebs" = "ami-9e0583f6" 24 | "14.04.us-east-1.pv-s3" = "ami-9cbe3ef4" 25 | "14.04.us-west-1.hvm-ebs" = "ami-0bc3d74e" 26 | "14.04.us-west-1.pv-ebs" = "ami-8b1703ce" 27 | "14.04.us-west-1.pv-s3" = "ami-27ccd862" 28 | "14.04.us-west-2.hvm-ebs" = "ami-3bf1bf0b" 29 | "14.04.us-west-2.pv-ebs" = "ami-259bd515" 30 | "14.04.us-west-2.pv-s3" = "ami-07094037" 31 | "14.12.ap-northeast-1.hvm-ebs" = "ami-24435f25" 32 | "14.12.ap-northeast-1.pv-ebs" = "ami-b0425eb1" 33 | "14.12.ap-northeast-1.pv-s3" = "ami-fed3c6ff" 34 | "14.12.ap-southeast-1.hvm-ebs" = "ami-6c765d3e" 35 | "14.12.ap-southeast-1.pv-ebs" = "ami-6a765d38" 36 | "14.12.ap-southeast-1.pv-s3" = "ami-d1bf9183" 37 | "14.12.ap-southeast-2.hvm-ebs" = "ami-af86f395" 38 | "14.12.ap-southeast-2.pv-ebs" = "ami-b386f389" 39 | "14.12.ap-southeast-2.pv-s3" = "ami-69c5ae53" 40 | "14.12.eu-central-1.hvm-ebs" = "ami-4a497a57" 41 | "14.12.eu-central-1.pv-ebs" = "ami-4c497a51" 42 | "14.12.eu-central-1.pv-s3" = "ami-60f2c27d" 43 | "14.12.eu-west-1.hvm-ebs" = "ami-d126a5a6" 44 | "14.12.eu-west-1.pv-ebs" = "ami-0126a576" 45 | "14.12.eu-west-1.pv-s3" = "ami-deda5fa9" 46 | "14.12.sa-east-1.hvm-ebs" = "ami-2d239e30" 47 | "14.12.sa-east-1.pv-ebs" = "ami-35239e28" 48 | "14.12.sa-east-1.pv-s3" = "ami-81e3519c" 49 | "14.12.us-east-1.hvm-ebs" = "ami-0c463a64" 50 | "14.12.us-east-1.pv-ebs" = "ami-ac473bc4" 51 | "14.12.us-east-1.pv-s3" = "ami-00e18a68" 52 | "14.12.us-west-1.hvm-ebs" = "ami-ca534a8f" 53 | "14.12.us-west-1.pv-ebs" = "ami-3e534a7b" 54 | "14.12.us-west-1.pv-s3" = "ami-2905196c" 55 | "14.12.us-west-2.hvm-ebs" = "ami-fb9dc3cb" 56 | "14.12.us-west-2.pv-ebs" = "ami-899dc3b9" 57 | "14.12.us-west-2.pv-s3" = "ami-cb7f2dfb" 58 | "15.09.ap-northeast-1.hvm-ebs" = "ami-58cac236" 59 | "15.09.ap-northeast-1.hvm-s3" = "ami-39c8c057" 60 | "15.09.ap-northeast-1.pv-ebs" = "ami-5ac9c134" 61 | "15.09.ap-northeast-1.pv-s3" = "ami-03cec66d" 62 | "15.09.ap-southeast-1.hvm-ebs" = "ami-2fc2094c" 63 | "15.09.ap-southeast-1.hvm-s3" = "ami-9ec308fd" 64 | "15.09.ap-southeast-1.pv-ebs" = "ami-95c00bf6" 65 | "15.09.ap-southeast-1.pv-s3" = "ami-bfc00bdc" 66 | "15.09.ap-southeast-2.hvm-ebs" = "ami-996c4cfa" 67 | "15.09.ap-southeast-2.hvm-s3" = "ami-3f6e4e5c" 68 | "15.09.ap-southeast-2.pv-ebs" = "ami-066d4d65" 69 | "15.09.ap-southeast-2.pv-s3" = "ami-cc6e4eaf" 70 | "15.09.eu-central-1.hvm-ebs" = "ami-3f8c6b50" 71 | "15.09.eu-central-1.hvm-s3" = "ami-5b836434" 72 | "15.09.eu-central-1.pv-ebs" = "ami-118c6b7e" 73 | "15.09.eu-central-1.pv-s3" = "ami-2c977043" 74 | "15.09.eu-west-1.hvm-ebs" = "ami-9cf04aef" 75 | "15.09.eu-west-1.hvm-s3" = "ami-2bea5058" 76 | "15.09.eu-west-1.pv-ebs" = "ami-c9e852ba" 77 | "15.09.eu-west-1.pv-s3" = "ami-c6f64cb5" 78 | "15.09.sa-east-1.hvm-ebs" = "ami-6e52df02" 79 | "15.09.sa-east-1.hvm-s3" = "ami-1852df74" 80 | "15.09.sa-east-1.pv-ebs" = "ami-4368e52f" 81 | "15.09.sa-east-1.pv-s3" = "ami-f15ad79d" 82 | "15.09.us-east-1.hvm-ebs" = "ami-84a6a0ee" 83 | "15.09.us-east-1.hvm-s3" = "ami-06a7a16c" 84 | "15.09.us-east-1.pv-ebs" = "ami-a4a1a7ce" 85 | "15.09.us-east-1.pv-s3" = "ami-5ba8ae31" 86 | "15.09.us-west-1.hvm-ebs" = "ami-22c8bb42" 87 | "15.09.us-west-1.hvm-s3" = "ami-a2ccbfc2" 88 | "15.09.us-west-1.pv-ebs" = "ami-10cebd70" 89 | "15.09.us-west-1.pv-s3" = "ami-fa30429a" 90 | "15.09.us-west-2.hvm-ebs" = "ami-ce57b9ae" 91 | "15.09.us-west-2.hvm-s3" = "ami-2956b849" 92 | "15.09.us-west-2.pv-ebs" = "ami-005fb160" 93 | "15.09.us-west-2.pv-s3" = "ami-cd55bbad" 94 | "16.03.ap-northeast-1.hvm-ebs" = "ami-40619d21" 95 | "16.03.ap-northeast-1.hvm-s3" = "ami-ce629eaf" 96 | "16.03.ap-northeast-1.pv-ebs" = "ami-ef639f8e" 97 | "16.03.ap-northeast-1.pv-s3" = "ami-a1609cc0" 98 | "16.03.ap-northeast-2.hvm-ebs" = "ami-deca00b0" 99 | "16.03.ap-northeast-2.hvm-s3" = "ami-a3b77dcd" 100 | "16.03.ap-northeast-2.pv-ebs" = "ami-7bcb0115" 101 | "16.03.ap-northeast-2.pv-s3" = "ami-a2b77dcc" 102 | "16.03.ap-south-1.hvm-ebs" = "ami-0dff9562" 103 | "16.03.ap-south-1.hvm-s3" = "ami-13f69c7c" 104 | "16.03.ap-south-1.pv-ebs" = "ami-0ef39961" 105 | "16.03.ap-south-1.pv-s3" = "ami-e0c8a28f" 106 | "16.03.ap-southeast-1.hvm-ebs" = "ami-5e964a3d" 107 | "16.03.ap-southeast-1.hvm-s3" = "ami-4d964a2e" 108 | "16.03.ap-southeast-1.pv-ebs" = "ami-ec9b478f" 109 | "16.03.ap-southeast-1.pv-s3" = "ami-999b47fa" 110 | "16.03.ap-southeast-2.hvm-ebs" = "ami-9f7359fc" 111 | "16.03.ap-southeast-2.hvm-s3" = "ami-987359fb" 112 | "16.03.ap-southeast-2.pv-ebs" = "ami-a2705ac1" 113 | "16.03.ap-southeast-2.pv-s3" = "ami-a3705ac0" 114 | "16.03.eu-central-1.hvm-ebs" = "ami-17a45178" 115 | "16.03.eu-central-1.hvm-s3" = "ami-f9a55096" 116 | "16.03.eu-central-1.pv-ebs" = "ami-c8a550a7" 117 | "16.03.eu-central-1.pv-s3" = "ami-6ea45101" 118 | "16.03.eu-west-1.hvm-ebs" = "ami-b5b3d5c6" 119 | "16.03.eu-west-1.hvm-s3" = "ami-c986e0ba" 120 | "16.03.eu-west-1.pv-ebs" = "ami-b083e5c3" 121 | "16.03.eu-west-1.pv-s3" = "ami-3c83e54f" 122 | "16.03.sa-east-1.hvm-ebs" = "ami-f6eb7f9a" 123 | "16.03.sa-east-1.hvm-s3" = "ami-93e773ff" 124 | "16.03.sa-east-1.pv-ebs" = "ami-cbb82ca7" 125 | "16.03.sa-east-1.pv-s3" = "ami-abb82cc7" 126 | "16.03.us-east-1.hvm-ebs" = "ami-c123a3d6" 127 | "16.03.us-east-1.hvm-s3" = "ami-bc25a5ab" 128 | "16.03.us-east-1.pv-ebs" = "ami-bd25a5aa" 129 | "16.03.us-east-1.pv-s3" = "ami-a325a5b4" 130 | "16.03.us-west-1.hvm-ebs" = "ami-748bcd14" 131 | "16.03.us-west-1.hvm-s3" = "ami-a68dcbc6" 132 | "16.03.us-west-1.pv-ebs" = "ami-048acc64" 133 | "16.03.us-west-1.pv-s3" = "ami-208dcb40" 134 | "16.03.us-west-2.hvm-ebs" = "ami-8263a0e2" 135 | "16.03.us-west-2.hvm-s3" = "ami-925c9ff2" 136 | "16.03.us-west-2.pv-ebs" = "ami-5e61a23e" 137 | "16.03.us-west-2.pv-s3" = "ami-734c8f13" 138 | "16.09.ap-northeast-1.hvm-ebs" = "ami-68453b0f" 139 | "16.09.ap-northeast-1.hvm-s3" = "ami-f9bec09e" 140 | "16.09.ap-northeast-1.pv-ebs" = "ami-254a3442" 141 | "16.09.ap-northeast-1.pv-s3" = "ami-ef473988" 142 | "16.09.ap-northeast-2.hvm-ebs" = "ami-18ae7f76" 143 | "16.09.ap-northeast-2.hvm-s3" = "ami-9eac7df0" 144 | "16.09.ap-northeast-2.pv-ebs" = "ami-57aa7b39" 145 | "16.09.ap-northeast-2.pv-s3" = "ami-5cae7f32" 146 | "16.09.ap-south-1.hvm-ebs" = "ami-b3f98fdc" 147 | "16.09.ap-south-1.hvm-s3" = "ami-98e690f7" 148 | "16.09.ap-south-1.pv-ebs" = "ami-aef98fc1" 149 | "16.09.ap-south-1.pv-s3" = "ami-caf88ea5" 150 | "16.09.ap-southeast-1.hvm-ebs" = "ami-80fb51e3" 151 | "16.09.ap-southeast-1.hvm-s3" = "ami-2df3594e" 152 | "16.09.ap-southeast-1.pv-ebs" = "ami-37f05a54" 153 | "16.09.ap-southeast-1.pv-s3" = "ami-27f35944" 154 | "16.09.ap-southeast-2.hvm-ebs" = "ami-57ece834" 155 | "16.09.ap-southeast-2.hvm-s3" = "ami-87f4f0e4" 156 | "16.09.ap-southeast-2.pv-ebs" = "ami-d8ede9bb" 157 | "16.09.ap-southeast-2.pv-s3" = "ami-a6ebefc5" 158 | "16.09.ca-central-1.hvm-ebs" = "ami-9f863bfb" 159 | "16.09.ca-central-1.hvm-s3" = "ami-ea85388e" 160 | "16.09.ca-central-1.pv-ebs" = "ami-ce8a37aa" 161 | "16.09.ca-central-1.pv-s3" = "ami-448a3720" 162 | "16.09.eu-central-1.hvm-ebs" = "ami-1b884774" 163 | "16.09.eu-central-1.hvm-s3" = "ami-b08c43df" 164 | "16.09.eu-central-1.pv-ebs" = "ami-888946e7" 165 | "16.09.eu-central-1.pv-s3" = "ami-06874869" 166 | "16.09.eu-west-1.hvm-ebs" = "ami-1ed3e76d" 167 | "16.09.eu-west-1.hvm-s3" = "ami-73d1e500" 168 | "16.09.eu-west-1.pv-ebs" = "ami-44c0f437" 169 | "16.09.eu-west-1.pv-s3" = "ami-f3d8ec80" 170 | "16.09.eu-west-2.hvm-ebs" = "ami-2c9c9648" 171 | "16.09.eu-west-2.hvm-s3" = "ami-6b9e940f" 172 | "16.09.eu-west-2.pv-ebs" = "ami-f1999395" 173 | "16.09.eu-west-2.pv-s3" = "ami-bb9f95df" 174 | "16.09.sa-east-1.hvm-ebs" = "ami-a11882cd" 175 | "16.09.sa-east-1.hvm-s3" = "ami-7726bc1b" 176 | "16.09.sa-east-1.pv-ebs" = "ami-9725bffb" 177 | "16.09.sa-east-1.pv-s3" = "ami-b027bddc" 178 | "16.09.us-east-1.hvm-ebs" = "ami-854ca593" 179 | "16.09.us-east-1.hvm-s3" = "ami-2241a834" 180 | "16.09.us-east-1.pv-ebs" = "ami-a441a8b2" 181 | "16.09.us-east-1.pv-s3" = "ami-e841a8fe" 182 | "16.09.us-east-2.hvm-ebs" = "ami-3f41645a" 183 | "16.09.us-east-2.hvm-s3" = "ami-804065e5" 184 | "16.09.us-east-2.pv-ebs" = "ami-f1466394" 185 | "16.09.us-east-2.pv-s3" = "ami-05426760" 186 | "16.09.us-west-1.hvm-ebs" = "ami-c2efbca2" 187 | "16.09.us-west-1.hvm-s3" = "ami-d71042b7" 188 | "16.09.us-west-1.pv-ebs" = "ami-04e8bb64" 189 | "16.09.us-west-1.pv-s3" = "ami-31e9ba51" 190 | "16.09.us-west-2.hvm-ebs" = "ami-6449f504" 191 | "16.09.us-west-2.hvm-s3" = "ami-344af654" 192 | "16.09.us-west-2.pv-ebs" = "ami-6d4af60d" 193 | "16.09.us-west-2.pv-s3" = "ami-de48f4be" 194 | "17.03.ap-northeast-1.hvm-ebs" = "ami-dbd0f7bc" 195 | "17.03.ap-northeast-1.hvm-s3" = "ami-7cdff81b" 196 | "17.03.ap-northeast-2.hvm-ebs" = "ami-c59a48ab" 197 | "17.03.ap-northeast-2.hvm-s3" = "ami-0b944665" 198 | "17.03.ap-south-1.hvm-ebs" = "ami-4f413220" 199 | "17.03.ap-south-1.hvm-s3" = "ami-864033e9" 200 | "17.03.ap-southeast-1.hvm-ebs" = "ami-e08c3383" 201 | "17.03.ap-southeast-1.hvm-s3" = "ami-c28f30a1" 202 | "17.03.ap-southeast-2.hvm-ebs" = "ami-fca9a69f" 203 | "17.03.ap-southeast-2.hvm-s3" = "ami-3daaa55e" 204 | "17.03.ca-central-1.hvm-ebs" = "ami-9b00bdff" 205 | "17.03.ca-central-1.hvm-s3" = "ami-e800bd8c" 206 | "17.03.eu-central-1.hvm-ebs" = "ami-5450803b" 207 | "17.03.eu-central-1.hvm-s3" = "ami-6e2efe01" 208 | "17.03.eu-west-1.hvm-ebs" = "ami-10754c76" 209 | "17.03.eu-west-1.hvm-s3" = "ami-11734a77" 210 | "17.03.eu-west-2.hvm-ebs" = "ami-ff1d099b" 211 | "17.03.eu-west-2.hvm-s3" = "ami-fe1d099a" 212 | "17.03.sa-east-1.hvm-ebs" = "ami-d95d3eb5" 213 | "17.03.sa-east-1.hvm-s3" = "ami-fca2c190" 214 | "17.03.us-east-1.hvm-ebs" = "ami-0940c61f" 215 | "17.03.us-east-1.hvm-s3" = "ami-674fc971" 216 | "17.03.us-east-2.hvm-ebs" = "ami-afc2e6ca" 217 | "17.03.us-east-2.hvm-s3" = "ami-a1cde9c4" 218 | "17.03.us-west-1.hvm-ebs" = "ami-587b2138" 219 | "17.03.us-west-1.hvm-s3" = "ami-70411b10" 220 | "17.03.us-west-2.hvm-ebs" = "ami-a93daac9" 221 | "17.03.us-west-2.hvm-s3" = "ami-5139ae31" 222 | "17.09.ap-northeast-1.hvm-ebs" = "ami-89b921ef" 223 | "17.09.ap-northeast-2.hvm-ebs" = "ami-179b3b79" 224 | "17.09.ap-south-1.hvm-ebs" = "ami-4e376021" 225 | "17.09.ap-southeast-1.hvm-ebs" = "ami-84bccff8" 226 | "17.09.ap-southeast-2.hvm-ebs" = "ami-0dc5386f" 227 | "17.09.ca-central-1.hvm-ebs" = "ami-ca8207ae" 228 | "17.09.eu-central-1.hvm-ebs" = "ami-266cfe49" 229 | "17.09.eu-west-1.hvm-ebs" = "ami-a30192da" 230 | "17.09.eu-west-2.hvm-ebs" = "ami-295a414d" 231 | "17.09.eu-west-3.hvm-ebs" = "ami-8c0eb9f1" 232 | "17.09.sa-east-1.hvm-ebs" = "ami-4762202b" 233 | "17.09.us-east-1.hvm-ebs" = "ami-40bee63a" 234 | "17.09.us-east-2.hvm-ebs" = "ami-9d84aff8" 235 | "17.09.us-west-1.hvm-ebs" = "ami-d14142b1" 236 | "17.09.us-west-2.hvm-ebs" = "ami-3eb40346" 237 | "18.03.ap-northeast-1.hvm-ebs" = "ami-456511a8" 238 | "18.03.ap-northeast-2.hvm-ebs" = "ami-3366d15d" 239 | "18.03.ap-south-1.hvm-ebs" = "ami-6a390b05" 240 | "18.03.ap-southeast-1.hvm-ebs" = "ami-aa0b4d40" 241 | "18.03.ap-southeast-2.hvm-ebs" = "ami-d0f254b2" 242 | "18.03.ca-central-1.hvm-ebs" = "ami-aca72ac8" 243 | "18.03.eu-central-1.hvm-ebs" = "ami-09faf9e2" 244 | "18.03.eu-west-1.hvm-ebs" = "ami-065c46ec" 245 | "18.03.eu-west-2.hvm-ebs" = "ami-64f31903" 246 | "18.03.eu-west-3.hvm-ebs" = "ami-5a8d3d27" 247 | "18.03.sa-east-1.hvm-ebs" = "ami-163e1f7a" 248 | "18.03.us-east-1.hvm-ebs" = "ami-8b3538f4" 249 | "18.03.us-east-2.hvm-ebs" = "ami-150b3170" 250 | "18.03.us-west-1.hvm-ebs" = "ami-ce06ebad" 251 | "18.03.us-west-2.hvm-ebs" = "ami-586c3520" 252 | "18.09.ap-northeast-1.hvm-ebs" = "ami-0cdba8e998f076547" 253 | "18.09.ap-northeast-2.hvm-ebs" = "ami-0400a698e6a9f4a15" 254 | "18.09.ap-south-1.hvm-ebs" = "ami-0880a678d3f555313" 255 | "18.09.ap-southeast-1.hvm-ebs" = "ami-0892c7e24ebf2194f" 256 | "18.09.ap-southeast-2.hvm-ebs" = "ami-010730f36424b0a2c" 257 | "18.09.ca-central-1.hvm-ebs" = "ami-04f66113f76198f6c" 258 | "18.09.eu-central-1.hvm-ebs" = "ami-07c9b884e679df4f8" 259 | "18.09.eu-west-1.hvm-ebs" = "ami-0f412186fb8a0ec97" 260 | "18.09.eu-west-2.hvm-ebs" = "ami-0dada3805ce43c55e" 261 | "18.09.eu-west-3.hvm-ebs" = "ami-074df85565f2e02e2" 262 | "18.09.sa-east-1.hvm-ebs" = "ami-0e4a8a47fd6db6112" 263 | "18.09.us-east-1.hvm-ebs" = "ami-009c9c3f1af480ff3" 264 | "18.09.us-east-2.hvm-ebs" = "ami-08199961085ea8bc6" 265 | "18.09.us-west-1.hvm-ebs" = "ami-07aa7f56d612ddd38" 266 | "18.09.us-west-2.hvm-ebs" = "ami-01c84b7c368ac24d1" 267 | "19.03.ap-northeast-1.hvm-ebs" = "ami-00db62688900456a4" 268 | "19.03.ap-northeast-2.hvm-ebs" = "ami-0485cdd1a5fdd2117" 269 | "19.03.ap-south-1.hvm-ebs" = "ami-0303deb1b5890f878" 270 | "19.03.ap-southeast-1.hvm-ebs" = "ami-0cff66114c652c262" 271 | "19.03.ap-southeast-2.hvm-ebs" = "ami-054c73a7f8d773ea9" 272 | "19.03.ca-central-1.hvm-ebs" = "ami-03f9fd0ef2e035ede" 273 | "19.03.eu-central-1.hvm-ebs" = "ami-0022b8ea9efde5de4" 274 | "19.03.eu-west-1.hvm-ebs" = "ami-0fe40176548ff0940" 275 | "19.03.eu-west-2.hvm-ebs" = "ami-03a40fd3a02fe95ba" 276 | "19.03.eu-west-3.hvm-ebs" = "ami-0436f9da0f20a638e" 277 | "19.03.sa-east-1.hvm-ebs" = "ami-0c6a43c6e0ad1f4e2" 278 | "19.03.us-east-1.hvm-ebs" = "ami-0efc58fb70ae9a217" 279 | "19.03.us-east-2.hvm-ebs" = "ami-0abf711b1b34da1af" 280 | "19.03.us-west-1.hvm-ebs" = "ami-07d126e8838c40ec5" 281 | "19.03.us-west-2.hvm-ebs" = "ami-03f8a737546e47fb0" 282 | "19.09.ap-east-1.hvm-ebs" = "ami-055b2348db2827ff1" 283 | "19.09.ap-northeast-1.hvm-ebs" = "ami-02a62555ca182fb5b" 284 | "19.09.ap-northeast-2.hvm-ebs" = "ami-0219dde0e6b7b7b93" 285 | "19.09.ap-south-1.hvm-ebs" = "ami-066f7f2a895c821a1" 286 | "19.09.ap-southeast-1.hvm-ebs" = "ami-0f71ae5d4b0b78d95" 287 | "19.09.ap-southeast-2.hvm-ebs" = "ami-057bbf2b4bd62d210" 288 | "19.09.ca-central-1.hvm-ebs" = "ami-07df50fc76702a36d" 289 | "19.09.eu-central-1.hvm-ebs" = "ami-015f8efc2be419b79" 290 | "19.09.eu-north-1.hvm-ebs" = "ami-07fc0a32d885e01ed" 291 | "19.09.eu-west-1.hvm-ebs" = "ami-071082f0fa035374f" 292 | "19.09.eu-west-2.hvm-ebs" = "ami-0d9dc33c54d1dc4c3" 293 | "19.09.eu-west-3.hvm-ebs" = "ami-09566799591d1bfed" 294 | "19.09.sa-east-1.hvm-ebs" = "ami-018aab68377227e06" 295 | "19.09.us-east-1.hvm-ebs" = "ami-03330d8b51287412f" 296 | "19.09.us-east-2.hvm-ebs" = "ami-0518b4c84972e967f" 297 | "19.09.us-west-1.hvm-ebs" = "ami-06ad07e61a353b4a6" 298 | "19.09.us-west-2.hvm-ebs" = "ami-0e31e30925cf3ce4e" 299 | "20.03.ap-east-1.hvm-ebs" = "ami-0d18fdd309cdefa86" 300 | "20.03.ap-northeast-1.hvm-ebs" = "ami-093d9cc49c191eb6c" 301 | "20.03.ap-northeast-2.hvm-ebs" = "ami-0087df91a7b6ebd45" 302 | "20.03.ap-south-1.hvm-ebs" = "ami-0a1a6b569af04af9d" 303 | "20.03.ap-southeast-1.hvm-ebs" = "ami-0dbf353e168d155f7" 304 | "20.03.ap-southeast-2.hvm-ebs" = "ami-04c0f3a75f63daddd" 305 | "20.03.ca-central-1.hvm-ebs" = "ami-02365684a173255c7" 306 | "20.03.eu-central-1.hvm-ebs" = "ami-0a1a94722dcbff94c" 307 | "20.03.eu-north-1.hvm-ebs" = "ami-02699abfacbb6464b" 308 | "20.03.eu-west-1.hvm-ebs" = "ami-02c34db5766cc7013" 309 | "20.03.eu-west-2.hvm-ebs" = "ami-0e32bd8c7853883f1" 310 | "20.03.eu-west-3.hvm-ebs" = "ami-061edb1356c1d69fd" 311 | "20.03.sa-east-1.hvm-ebs" = "ami-09859378158ae971d" 312 | "20.03.us-east-1.hvm-ebs" = "ami-0c5e7760748b74e85" 313 | "20.03.us-east-2.hvm-ebs" = "ami-030296bb256764655" 314 | "20.03.us-west-1.hvm-ebs" = "ami-050be818e0266b741" 315 | "20.03.us-west-2.hvm-ebs" = "ami-06562f78dca68eda2" 316 | "20.09.ap-east-1.hvm-ebs" = "ami-071f49713f86ea965" 317 | "20.09.ap-northeast-1.hvm-ebs" = "ami-0beb18d632cf64e5a" 318 | "20.09.ap-northeast-2.hvm-ebs" = "ami-0dd0316af578862db" 319 | "20.09.ap-south-1.hvm-ebs" = "ami-008d15ced81c88aed" 320 | "20.09.ap-southeast-1.hvm-ebs" = "ami-0db0304e23c535b2a" 321 | "20.09.ap-southeast-2.hvm-ebs" = "ami-045983c4db7e36447" 322 | "20.09.ca-central-1.hvm-ebs" = "ami-06d5ee429f153f856" 323 | "20.09.eu-central-1.hvm-ebs" = "ami-01d4a0c2248cbfe38" 324 | "20.09.eu-north-1.hvm-ebs" = "ami-0003f54dd99d68e0f" 325 | "20.09.eu-west-1.hvm-ebs" = "ami-01a79d5ce435f4db3" 326 | "20.09.eu-west-2.hvm-ebs" = "ami-0cbe14f32904e6331" 327 | "20.09.eu-west-3.hvm-ebs" = "ami-07f493412d6213de6" 328 | "20.09.sa-east-1.hvm-ebs" = "ami-05ded1ae35209b5a8" 329 | "20.09.us-east-1.hvm-ebs" = "ami-068a62d478710462d" 330 | "20.09.us-east-2.hvm-ebs" = "ami-01ac677ff61399caa" 331 | "20.09.us-west-1.hvm-ebs" = "ami-04befdb203b4b17f6" 332 | "20.09.us-west-2.hvm-ebs" = "ami-0fb7bd4a43261c6b2" 333 | "latest.ap-east-1.hvm-ebs" = "ami-071f49713f86ea965" 334 | "latest.ap-northeast-1.hvm-ebs" = "ami-0beb18d632cf64e5a" 335 | "latest.ap-northeast-2.hvm-ebs" = "ami-0dd0316af578862db" 336 | "latest.ap-south-1.hvm-ebs" = "ami-008d15ced81c88aed" 337 | "latest.ap-southeast-1.hvm-ebs" = "ami-0db0304e23c535b2a" 338 | "latest.ap-southeast-2.hvm-ebs" = "ami-045983c4db7e36447" 339 | "latest.ca-central-1.hvm-ebs" = "ami-06d5ee429f153f856" 340 | "latest.eu-central-1.hvm-ebs" = "ami-01d4a0c2248cbfe38" 341 | "latest.eu-north-1.hvm-ebs" = "ami-0003f54dd99d68e0f" 342 | "latest.eu-west-1.hvm-ebs" = "ami-01a79d5ce435f4db3" 343 | "latest.eu-west-2.hvm-ebs" = "ami-0cbe14f32904e6331" 344 | "latest.eu-west-3.hvm-ebs" = "ami-07f493412d6213de6" 345 | "latest.sa-east-1.hvm-ebs" = "ami-05ded1ae35209b5a8" 346 | "latest.us-east-1.hvm-ebs" = "ami-068a62d478710462d" 347 | "latest.us-east-2.hvm-ebs" = "ami-01ac677ff61399caa" 348 | "latest.us-west-1.hvm-ebs" = "ami-04befdb203b4b17f6" 349 | "latest.us-west-2.hvm-ebs" = "ami-0fb7bd4a43261c6b2" 350 | } 351 | 352 | description = "A map of release series to actual releases" 353 | } 354 | -------------------------------------------------------------------------------- /aws_image_nixos/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /deploy_nixos/README.md: -------------------------------------------------------------------------------- 1 | # deploy_nixos 2 | 3 | A Terraform module that knows how to deploy NixOS onto a target host. 4 | 5 | This allow to describe an infrastructure as code with Terraform and delegate 6 | the machine configuration with NixOS. All directed by Terraform. 7 | 8 | The advantage of this method is that if any of the Nix code changes, the 9 | difference will be detected on the next "terraform plan". 10 | 11 | ## Usage 12 | 13 | Either pass a "config" which is a dynamic nixos configuration and a 14 | "config_pwd", or a "nixos_config", a path to a nixos configuration.nix file. 15 | If you have defined your NixOs configuration in a Flake, use "nixos_config" 16 | to specify the name of the attribue and set "flake" to true. 17 | 18 | ### Secret handling 19 | 20 | Keys can be passed to the "keys" attribute. Each key will be installed under 21 | `/var/keys/${key}` with the content as the value. 22 | 23 | For services to access one of the keys, add the service user to the "keys" 24 | group. 25 | 26 | The target machine needs `jq` installed prior to the deployment (as part of 27 | the base image). If `jq` is not found it will try to use a version from 28 | ``. 29 | 30 | ### Disabling sandboxing 31 | 32 | Unfortunately some time it's required to disable the nix sandboxing. To do so, 33 | add `["--option", "sandbox", "false"]` to the "extra_build_args" parameter. 34 | 35 | If that doesn't work, make sure that your user is part of the nix 36 | "trusted-users" list. 37 | 38 | ### Non-root `target_user` 39 | 40 | It is possible to connect to the target host using a user that is not `root` 41 | under certain conditions: 42 | 43 | * sudo needs to be installed on the machine 44 | * the user needs password-less sudo access on the machine 45 | 46 | This would typically be provisioned in the base image. 47 | 48 | ### Binary cache configuration 49 | 50 | One thing that might be surprising is that the binary caches (aka 51 | substituters) are taken from the machine configuration. This implies that the 52 | user Nix configuration will be ignored in that regard. 53 | 54 | ## Dependencies 55 | 56 | * `bash` 4.0+ 57 | * `nix` 58 | * `openssh` 59 | * `readlink` with `-f` (coreutils or busybox) 60 | 61 | ## Known limitations 62 | 63 | The deployment machine requires Nix with access to a remote builder with the 64 | same system as the target machine. 65 | 66 | Because Nix code is being evaluated at "terraform plan" time, deploying a lot 67 | of machine in the same target will require a lot of RAM. 68 | 69 | All the secrets share the same "keys" group. 70 | 71 | When deploying as non-root, it assumes that passwordless `sudo` is available. 72 | 73 | The target host must already have NixOS installed. 74 | 75 | ### config including computed values 76 | 77 | The module doesn't work when `` values from other resources are 78 | interpolated with the "config" attribute. Because it happens at evaluation 79 | time, terraform will render an empty drvPath. 80 | 81 | see also: 82 | * https://github.com/hashicorp/terraform/issues/16380 83 | * https://github.com/hashicorp/terraform/issues/16762 84 | * https://github.com/hashicorp/terraform/issues/17034 85 | 86 | 87 | ## Requirements 88 | 89 | | Name | Version | 90 | |------|---------| 91 | | terraform | >= 0.12 | 92 | 93 | ## Providers 94 | 95 | | Name | Version | 96 | |------|---------| 97 | | external | n/a | 98 | | null | n/a | 99 | 100 | ## Inputs 101 | 102 | | Name | Description | Type | Default | Required | 103 | |------|-------------|------|---------|:--------:| 104 | | NIX\_PATH | Allow to pass custom NIX\_PATH | `string` | `""` | no | 105 | | build\_on\_target | Avoid building on the deployer. Must be true or false. Has no effect when deploying from an incompatible system. Unlike remote builders, this does not require the deploying user to be trusted by its host. | `string` | `false` | no | 106 | | config | NixOS configuration to be evaluated. This argument is required unless 'nixos\_config' is given | `string` | `""` | no | 107 | | config\_pwd | Directory to evaluate the configuration in. This argument is required if 'config' is given | `string` | `""` | no | 108 | | extra\_build\_args | List of arguments to pass to the nix builder | `list(string)` | `[]` | no | 109 | | extra\_eval\_args | List of arguments to pass to the nix evaluation | `list(string)` | `[]` | no | 110 | | hermetic | Treat the provided nixos configuration as a hermetic expression and do not evaluate using the ambient system nixpkgs. Useful if you customize eval-modules or use a pinned nixpkgs. | `bool` | false | no | 111 | | flake | Treat the provided nixos_config as the name of the NixOS configuration to use in the flake located in the current directory. Useful if you customize eval-modules or use a pinned nixpkgs. | `bool` | false | no | 112 | | keys | A map of filename to content to upload as secrets in /var/keys | `map(string)` | `{}` | no | 113 | | nixos\_config | Path to a NixOS configuration | `string` | `""` | no | 114 | | ssh\_agent | Whether to use an SSH agent. True if not ssh\_private\_key is passed | `bool` | `null` | no | 115 | | ssh\_private\_key | Content of private key used to connect to the target\_host | `string` | `""` | no | 116 | | ssh\_private\_key\_file | Path to private key used to connect to the target\_host | `string` | `""` | no | 117 | | target\_host | DNS host to deploy to | `string` | n/a | yes | 118 | | target\_port | SSH port used to connect to the target\_host | `number` | `22` | no | 119 | | target\_system | Nix system string | `string` | `"x86_64-linux"` | no | 120 | | target\_user | SSH user used to connect to the target\_host | `string` | `"root"` | no | 121 | | triggers | Triggers for deploy | `map(string)` | `{}` | no | 122 | 123 | ## Outputs 124 | 125 | | Name | Description | 126 | |------|-------------| 127 | | id | random ID that changes on every nixos deployment | 128 | 129 | 130 | -------------------------------------------------------------------------------- /deploy_nixos/main.tf: -------------------------------------------------------------------------------- 1 | variable "target_host" { 2 | type = string 3 | description = "DNS host to deploy to" 4 | } 5 | 6 | variable "target_user" { 7 | type = string 8 | description = "SSH user used to connect to the target_host" 9 | default = "root" 10 | } 11 | 12 | variable "target_port" { 13 | type = number 14 | description = "SSH port used to connect to the target_host" 15 | default = 22 16 | } 17 | 18 | variable "ssh_private_key" { 19 | type = string 20 | description = "Content of private key used to connect to the target_host" 21 | default = "" 22 | } 23 | 24 | variable "ssh_private_key_file" { 25 | type = string 26 | description = "Path to private key used to connect to the target_host" 27 | default = "" 28 | } 29 | 30 | variable "ssh_agent" { 31 | type = bool 32 | description = "Whether to use an SSH agent. True if not ssh_private_key is passed" 33 | default = null 34 | } 35 | 36 | variable "NIX_PATH" { 37 | type = string 38 | description = "Allow to pass custom NIX_PATH" 39 | default = "" 40 | } 41 | 42 | variable "nixos_config" { 43 | type = string 44 | description = "Path to a NixOS configuration" 45 | default = "" 46 | } 47 | 48 | variable "config" { 49 | type = string 50 | description = "NixOS configuration to be evaluated. This argument is required unless 'nixos_config' is given" 51 | default = "" 52 | } 53 | 54 | variable "config_pwd" { 55 | type = string 56 | description = "Directory to evaluate the configuration in. This argument is required if 'config' is given" 57 | default = "" 58 | } 59 | 60 | variable "extra_eval_args" { 61 | type = list(string) 62 | description = "List of arguments to pass to the nix evaluation" 63 | default = [] 64 | } 65 | 66 | variable "extra_build_args" { 67 | type = list(string) 68 | description = "List of arguments to pass to the nix builder" 69 | default = [] 70 | } 71 | 72 | variable "build_on_target" { 73 | type = string 74 | description = "Avoid building on the deployer. Must be true or false. Has no effect when deploying from an incompatible system. Unlike remote builders, this does not require the deploying user to be trusted by its host." 75 | default = false 76 | } 77 | 78 | variable "triggers" { 79 | type = map(string) 80 | description = "Triggers for deploy" 81 | default = {} 82 | } 83 | 84 | variable "keys" { 85 | type = map(string) 86 | description = "A map of filename to content to upload as secrets in /var/keys" 87 | default = {} 88 | } 89 | 90 | variable "target_system" { 91 | type = string 92 | description = "Nix system string" 93 | default = "x86_64-linux" 94 | } 95 | 96 | variable "hermetic" { 97 | type = bool 98 | description = "Treat the provided nixos configuration as a hermetic expression and do not evaluate using the ambient system nixpkgs. Useful if you customize eval-modules or use a pinned nixpkgs." 99 | default = false 100 | } 101 | 102 | variable "flake" { 103 | type = bool 104 | description = "Treat the provided nixos_config as the NixOS configuration to use in the flake located in the current directory" 105 | default = false 106 | } 107 | 108 | variable "delete_older_than" { 109 | type = string 110 | description = "Can be a list of generation numbers, the special value old to delete all non-current generations, a value such as 30d to delete all generations older than the specified number of days (except for the generation that was active at that point in time), or a value such as +5 to keep the last 5 generations ignoring any newer than current, e.g., if 30 is the current generation +5 will delete generation 25 and all older generations." 111 | default = "+1" 112 | } 113 | 114 | # -------------------------------------------------------------------------- 115 | 116 | locals { 117 | triggers = { 118 | deploy_nixos_drv = data.external.nixos-instantiate.result["drv_path"] 119 | deploy_nixos_keys = sha256(jsonencode(var.keys)) 120 | } 121 | 122 | extra_build_args = concat([ 123 | "--option", "substituters", data.external.nixos-instantiate.result["substituters"], 124 | "--option", "trusted-public-keys", data.external.nixos-instantiate.result["trusted-public-keys"], 125 | ], 126 | var.extra_build_args, 127 | ) 128 | ssh_private_key_file = var.ssh_private_key_file == "" ? "-" : var.ssh_private_key_file 129 | ssh_private_key = local.ssh_private_key_file == "-" ? var.ssh_private_key : file(local.ssh_private_key_file) 130 | ssh_agent = var.ssh_agent == null ? (local.ssh_private_key != "") : var.ssh_agent 131 | build_on_target = data.external.nixos-instantiate.result["currentSystem"] != var.target_system ? true : tobool(var.build_on_target) 132 | } 133 | 134 | # used to detect changes in the configuration 135 | data "external" "nixos-instantiate" { 136 | program = concat([ 137 | "${path.module}/nixos-instantiate.sh", 138 | var.NIX_PATH == "" ? "-" : var.NIX_PATH, 139 | var.config != "" ? var.config : var.nixos_config, 140 | var.config_pwd == "" ? "." : var.config_pwd, 141 | var.flake, 142 | # end of positional arguments 143 | # start of pass-through arguments 144 | "--argstr", "system", var.target_system, 145 | "--arg", "hermetic", var.hermetic 146 | ], 147 | var.extra_eval_args, 148 | ) 149 | } 150 | 151 | resource "null_resource" "deploy_nixos" { 152 | triggers = merge(var.triggers, local.triggers) 153 | 154 | connection { 155 | type = "ssh" 156 | host = var.target_host 157 | port = var.target_port 158 | user = var.target_user 159 | agent = local.ssh_agent 160 | timeout = "100s" 161 | private_key = local.ssh_private_key == "-" ? "" : local.ssh_private_key 162 | } 163 | 164 | # copy the secret keys to the host 165 | provisioner "file" { 166 | content = jsonencode(var.keys) 167 | destination = "packed-keys.json" 168 | } 169 | 170 | # FIXME: move this to nixos-deploy.sh 171 | provisioner "file" { 172 | source = "${path.module}/unpack-keys.sh" 173 | destination = "unpack-keys.sh" 174 | } 175 | 176 | # FIXME: move this to nixos-deploy.sh 177 | provisioner "file" { 178 | source = "${path.module}/maybe-sudo.sh" 179 | destination = "maybe-sudo.sh" 180 | } 181 | 182 | provisioner "remote-exec" { 183 | inline = [ 184 | "chmod +x unpack-keys.sh maybe-sudo.sh", 185 | "./maybe-sudo.sh ./unpack-keys.sh ./packed-keys.json", 186 | ] 187 | } 188 | 189 | # do the actual deployment 190 | provisioner "local-exec" { 191 | interpreter = concat([ 192 | "${path.module}/nixos-deploy.sh", 193 | data.external.nixos-instantiate.result["drv_path"], 194 | data.external.nixos-instantiate.result["out_path"], 195 | "${var.target_user}@${var.target_host}", 196 | var.target_port, 197 | local.build_on_target, 198 | local.ssh_private_key == "" ? "-" : local.ssh_private_key, 199 | "switch", 200 | var.delete_older_than, 201 | ], 202 | local.extra_build_args 203 | ) 204 | command = "ignoreme" 205 | } 206 | } 207 | 208 | # -------------------------------------------------------------------------- 209 | 210 | output "id" { 211 | description = "random ID that changes on every nixos deployment" 212 | value = null_resource.deploy_nixos.id 213 | } 214 | 215 | -------------------------------------------------------------------------------- /deploy_nixos/maybe-sudo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Run sudo if required 4 | # 5 | # Usage: ./maybe-sudo.sh [...args] 6 | set -euo pipefail 7 | if [[ "$UID" = 0 ]]; then 8 | exec -- "$@" 9 | else 10 | exec sudo -- "$@" 11 | fi 12 | -------------------------------------------------------------------------------- /deploy_nixos/nixos-deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # nixos-deploy deploys a nixos-instantiate-generated drvPath to a target host 3 | # 4 | # Usage: nixos-deploy.sh [] ignoreme 5 | set -euo pipefail 6 | 7 | ### Defaults ### 8 | 9 | buildArgs=( 10 | --option extra-binary-caches https://cache.nixos.org/ 11 | ) 12 | profile=/nix/var/nix/profiles/system 13 | # will be set later 14 | sshOpts=( 15 | -o "ControlMaster=auto" 16 | -o "ControlPersist=60" 17 | # Avoid issues with IP re-use. This disable TOFU security. 18 | -o "StrictHostKeyChecking=no" 19 | -o "UserKnownHostsFile=/dev/null" 20 | -o "GlobalKnownHostsFile=/dev/null" 21 | # interactive authentication is not possible 22 | -o "BatchMode=yes" 23 | # verbose output for easier debugging 24 | -v 25 | ) 26 | 27 | ### Argument parsing ### 28 | 29 | drvPath="$1" 30 | outPath="$2" 31 | targetHost="$3" 32 | targetPort="$4" 33 | buildOnTarget="$5" 34 | sshPrivateKey="$6" 35 | action="$7" 36 | deleteOlderThan="$8" 37 | shift 8 38 | 39 | # remove the last argument 40 | set -- "${@:1:$(($# - 1))}" 41 | buildArgs+=("$@") 42 | 43 | sshOpts+=( -p "${targetPort}" ) 44 | 45 | workDir=$(mktemp -d) 46 | trap 'rm -rf "$workDir"' EXIT 47 | 48 | if [[ -n "${sshPrivateKey}" && "${sshPrivateKey}" != "-" ]]; then 49 | sshPrivateKeyFile="$workDir/ssh_key" 50 | echo "$sshPrivateKey" > "$sshPrivateKeyFile" 51 | chmod 0700 "$sshPrivateKeyFile" 52 | sshOpts+=( -o "IdentityFile=${sshPrivateKeyFile}" ) 53 | fi 54 | 55 | ### Functions ### 56 | 57 | log() { 58 | echo "--- $*" >&2 59 | } 60 | 61 | copyToTarget() { 62 | NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$targetHost" "$@" 63 | } 64 | 65 | # assumes that passwordless sudo is enabled on the server 66 | targetHostCmd() { 67 | # ${*@Q} escapes the arguments losslessly into space-separted quoted strings. 68 | # `ssh` did not properly maintain the array nature of the command line, 69 | # erroneously splitting arguments with internal spaces, even when using `--`. 70 | # Tested with OpenSSH_7.9p1. 71 | # 72 | # shellcheck disable=SC2029 73 | ssh "${sshOpts[@]}" "$targetHost" "./maybe-sudo.sh ${*@Q}" 74 | } 75 | 76 | # Setup a temporary ControlPath for this session. This speeds-up the 77 | # operations by not re-creating SSH sessions between each command. At the end 78 | # of the run, the session is forcefully terminated. 79 | setupControlPath() { 80 | sshOpts+=( 81 | -o "ControlPath=$workDir/ssh_control" 82 | ) 83 | cleanupControlPath() { 84 | local ret=$? 85 | # Avoid failing during the shutdown 86 | set +e 87 | # Close ssh multiplex-master process gracefully 88 | log "closing persistent ssh-connection" 89 | ssh "${sshOpts[@]}" -O stop "$targetHost" 90 | rm -rf "$workDir" 91 | exit "$ret" 92 | } 93 | trap cleanupControlPath EXIT 94 | } 95 | 96 | ### Main ### 97 | 98 | setupControlPath 99 | 100 | if [[ "${buildOnTarget:-false}" == true ]]; then 101 | 102 | # Upload derivation 103 | log "uploading derivations" 104 | copyToTarget "$drvPath" --gzip --use-substitutes 105 | 106 | # Build remotely 107 | log "building on target" 108 | set -x 109 | targetHostCmd "nix-store" "--realize" "$drvPath" "${buildArgs[@]}" 110 | 111 | else 112 | 113 | # Build derivation 114 | log "building on deployer" 115 | outPath=$(nix-store --realize "$drvPath" "${buildArgs[@]}") 116 | 117 | # Upload build results 118 | log "uploading build results" 119 | copyToTarget "$outPath" --gzip --use-substitutes 120 | 121 | fi 122 | 123 | # Activate 124 | log "activating configuration" 125 | targetHostCmd nix-env --profile "$profile" --set "$outPath" 126 | targetHostCmd "$outPath/bin/switch-to-configuration" "$action" 127 | 128 | # Cleanup previous generations 129 | log "collecting old nix derivations" 130 | # Deliberately not quoting $deleteOlderThan so the user can configure something like "1 2 3" 131 | # to keep generations with those numbers 132 | targetHostCmd "nix-env" "--profile" "$profile" "--delete-generations" $deleteOlderThan 133 | targetHostCmd "nix-store" "--gc" 134 | -------------------------------------------------------------------------------- /deploy_nixos/nixos-instantiate.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env bash 2 | set -euo pipefail 3 | 4 | # Args 5 | nix_path=$1 6 | config=$2 7 | config_pwd=$3 8 | flake=$4 9 | shift 4 10 | 11 | 12 | command=(nix-instantiate --show-trace --expr ' 13 | { system, configuration, hermetic ? false, flake ? false, ... }: 14 | let 15 | importFromFlake = { nixosConfig }: 16 | let 17 | flake = (import ( 18 | fetchTarball { 19 | url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; 20 | sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } 21 | ) { 22 | src = ./.; 23 | }).defaultNix; 24 | in 25 | builtins.getAttr nixosConfig flake.nixosConfigurations; 26 | os = 27 | if flake 28 | then importFromFlake { nixosConfig = configuration; } 29 | else if hermetic 30 | then import configuration 31 | else import { inherit system configuration; }; 32 | in { 33 | inherit (builtins) currentSystem; 34 | 35 | substituters = 36 | builtins.concatStringsSep " " os.config.nix.binaryCaches; 37 | 38 | trusted-public-keys = 39 | builtins.concatStringsSep " " os.config.nix.binaryCachePublicKeys; 40 | 41 | drv_path = os.config.system.build.toplevel.drvPath; 42 | out_path = os.config.system.build.toplevel; 43 | }') 44 | 45 | if readlink --version | grep -q GNU; then 46 | readlink="readlink -f" 47 | else 48 | if command -v greadlink &> /dev/null; then 49 | readlink="greadlink -f" 50 | else 51 | echo "Warning: symlinks not supported because readlink is non GNU" >&2 52 | readlink="realpath" 53 | fi 54 | fi 55 | 56 | if [[ -f "$config" ]]; then 57 | config=$($readlink "$config") 58 | command+=(--argstr configuration "$config") 59 | else 60 | if $flake; then 61 | command+=(--argstr configuration "$config" --arg flake true) 62 | else 63 | command+=(--arg configuration "$config") 64 | fi 65 | fi 66 | 67 | # add all extra CLI args as extra build arguments 68 | command+=("$@") 69 | 70 | # Setting the NIX_PATH 71 | if [[ -n "$nix_path" && "$nix_path" != "-" ]]; then 72 | export NIX_PATH=$nix_path 73 | fi 74 | 75 | # Changing directory 76 | cd "$($readlink "$config_pwd")" 77 | 78 | # Instantiate 79 | echo "running (instantiating): ${NIX_PATH:+NIX_PATH=$NIX_PATH} ${command[*]@Q}" -A out_path >&2 80 | "${command[@]}" -A out_path >/dev/null 81 | 82 | # Evaluate some more details, 83 | # relying on preceding "Instantiate" command to perform the instantiation, 84 | # because `--eval` is required but doesn't instantiate for some reason. 85 | echo "running (evaluating): ${NIX_PATH:+NIX_PATH=$NIX_PATH} ${command[*]@Q}" --eval --strict --json >&2 86 | "${command[@]}" --eval --strict --json 87 | -------------------------------------------------------------------------------- /deploy_nixos/unpack-keys.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Unpacks the packed-keys.json into individual keys 4 | set -euo pipefail 5 | shopt -s nullglob 6 | 7 | keys_file=${1:-packed-keys.json} 8 | keys_dir=/var/keys 9 | 10 | if [[ ! -f "$keys_file" ]]; then 11 | echo "error: $keys_file not found" 12 | exit 1 13 | fi 14 | 15 | # Fallback if jq is not installed 16 | if ! type -p jq &>/dev/null; then 17 | jqOut=$(nix-build '' -A jq) 18 | jq() { 19 | "$jqOut/bin/jq" "$@" 20 | } 21 | fi 22 | 23 | # cleanup 24 | mkdir -m 0750 -p "$keys_dir" 25 | chown -v root:keys "$keys_dir" 26 | chmod -v 0750 "$keys_dir" 27 | for key in "$keys_dir"/* ; do 28 | rm -v "$key" 29 | done 30 | 31 | if [[ $(< "$keys_file") = "{}" ]]; then 32 | echo "no keys to unpack" 33 | exit 34 | fi 35 | 36 | echo "unpacking $keys_file" 37 | 38 | # extract the keys from .packed.json 39 | for keyname in $(jq -S -r 'keys[]' "$keys_file"); do 40 | echo "unpacking: $keyname" 41 | jq -r ".\"$keyname\"" < "$keys_file" > "$keys_dir/$keyname" 42 | chmod 0640 "$keys_dir/$keyname" 43 | chown root:keys "$keys_dir/$keyname" 44 | done 45 | 46 | echo "unpacking done" 47 | -------------------------------------------------------------------------------- /deploy_nixos/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /examples/google/deploy_nixos.tf: -------------------------------------------------------------------------------- 1 | # Here we have an example of how a machine can be provisioned with some config 2 | # after boot. This is useful in case one doesn't want to unecessarily destroy 3 | # and create VMs in a pet scenario. 4 | 5 | data "google_compute_network" "default" { 6 | name = "default" 7 | } 8 | 9 | resource "google_compute_firewall" "deploy-nixos" { 10 | name = "deploy-nixos" 11 | network = data.google_compute_network.default.name 12 | 13 | allow { 14 | protocol = "icmp" 15 | } 16 | 17 | // Allow SSH access 18 | allow { 19 | protocol = "tcp" 20 | ports = ["22"] 21 | } 22 | 23 | // To vm tagged with: nixos 24 | target_tags = ["nixos"] 25 | direction = "INGRESS" 26 | 27 | // From anywhere. 28 | source_ranges = ["0.0.0.0/0"] 29 | } 30 | 31 | resource "google_compute_instance" "deploy-nixos" { 32 | name = "deploy-nixos-example" 33 | machine_type = "n1-standard-1" 34 | zone = "us-central1-a" 35 | 36 | // Bind the firewall rules 37 | tags = ["nixos"] 38 | 39 | boot_disk { 40 | initialize_params { 41 | // Start with an image the deployer can SSH into 42 | image = module.nixos_image_custom.self_link 43 | size = "20" 44 | } 45 | } 46 | 47 | network_interface { 48 | network = "default" 49 | 50 | // Give it a public IP 51 | access_config {} 52 | } 53 | 54 | lifecycle { 55 | // No need to re-deploy the machine if the image changed 56 | // NixOS is already immutable 57 | ignore_changes = [boot_disk] 58 | } 59 | } 60 | 61 | module "deploy_nixos" { 62 | source = "../../deploy_nixos" 63 | 64 | // Deploy the given NixOS configuration. In this case it's the same as the 65 | // original image. So if the configuration is changed later it will be 66 | // deployed here. 67 | nixos_config = "${path.module}/image_nixos_custom.nix" 68 | 69 | target_user = "root" 70 | target_host = google_compute_instance.deploy-nixos.network_interface[0].access_config[0].nat_ip 71 | 72 | triggers = { 73 | // Also re-deploy whenever the VM is re-created 74 | instance_id = google_compute_instance.deploy-nixos.id 75 | } 76 | 77 | // Pass some secrets. See the terraform-provider-secret to handle secrets 78 | // in Terraform 79 | keys = { 80 | foo = "bar" 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /examples/google/image_nixos.tf: -------------------------------------------------------------------------------- 1 | # Here is a simple example that instantiates the google image and spins up an 2 | # instance 3 | 4 | module "nixos_image_1809" { 5 | source = "../../google_image_nixos" 6 | nixos_version = "18.09" 7 | } 8 | 9 | // This instance is not very useful since it doesn't contain any 10 | // configuration. This could be fixed by passing a user metadata script. 11 | resource "google_compute_instance" "image-nixos" { 12 | name = "image-nixos" 13 | machine_type = "n1-standard-1" 14 | zone = "us-central1-a" 15 | 16 | boot_disk { 17 | initialize_params { 18 | image = module.nixos_image_1809.self_link 19 | } 20 | } 21 | 22 | network_interface { 23 | network = "default" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/google/image_nixos_custom.nix: -------------------------------------------------------------------------------- 1 | { modulesPath, ... }: 2 | { 3 | imports = [ 4 | # Make sure to have this in all your configurations 5 | "${toString modulesPath}/virtualisation/google-compute-image.nix" 6 | ]; 7 | 8 | # Bake the deploy's SSH key into the image. This is not 9 | # kosher Nix. 10 | users.users.root.openssh.authorizedKeys.keyFiles = [ 11 | (/. + builtins.getEnv("HOME") + "/.ssh/id_rsa.pub") 12 | ]; 13 | } 14 | -------------------------------------------------------------------------------- /examples/google/image_nixos_custom.tf: -------------------------------------------------------------------------------- 1 | # create a random ID for the bucket 2 | resource "random_id" "bucket" { 3 | byte_length = 8 4 | } 5 | 6 | # create a bucket to upload the image into 7 | resource "google_storage_bucket" "nixos-images" { 8 | name = "nixos-images-${random_id.bucket.hex}" 9 | location = "EU" 10 | } 11 | 12 | # create a custom nixos base image the deployer can SSH into 13 | # 14 | # this could also include much more configuration and be used to feed the 15 | # auto-scaler with system images 16 | module "nixos_image_custom" { 17 | source = "../../google_image_nixos_custom" 18 | bucket_name = google_storage_bucket.nixos-images.name 19 | 20 | nixos_config = "${path.module}/image_nixos_custom.nix" 21 | } 22 | -------------------------------------------------------------------------------- /examples/google/provider.tf: -------------------------------------------------------------------------------- 1 | provider "google" { 2 | project = "tweag-digital-assets" 3 | } 4 | -------------------------------------------------------------------------------- /examples/hermetic_config/configuration.nix: -------------------------------------------------------------------------------- 1 | # A simple, hermetic NixOS configuration for an AWS EC2 instance that 2 | # uses a nixpkgs pinned to a specific Git revision with an integrity 3 | # hash to ensure that we construct a NixOS system as purely as 4 | # possible. 5 | # 6 | # i.e. we explicitly specify which nixpkgs to use instead of relying 7 | # on the nixpkgs supplied on the NIX_PATH. 8 | # 9 | # The primary benefit of this is that it removes deployment surprises 10 | # when other developers supply a different nix-channel in the NIX_PATH 11 | # of their environment (even if you only add the 20.09 channel, 12 | # nix-channel --update can mutate that channel to a 20.09 with 13 | # backported changes). 14 | # 15 | # The secondary benefit is that you guard the `nixpkgs` you use, with 16 | # an integrity hash. 17 | let 18 | nixpkgs = 19 | let 20 | rev = "cd63096d6d887d689543a0b97743d28995bc9bc3"; 21 | sha256 = "1wg61h4gndm3vcprdcg7rc4s1v3jkm5xd7lw8r2f67w502y94gcy"; 22 | in 23 | builtins.fetchTarball { 24 | url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz"; 25 | inherit sha256; 26 | }; 27 | 28 | system = "x86_64-linux"; 29 | 30 | configuration = { config, pkgs, ... }: { 31 | imports = [ 32 | "${nixpkgs}/nixos/modules/virtualisation/amazon-image.nix" 33 | ]; 34 | 35 | ec2.hvm = true; 36 | 37 | networking.firewall.allowedTCPPorts = [ 22 80 ]; 38 | 39 | environment.systemPackages = [ 40 | pkgs.cloud-utils 41 | ]; 42 | 43 | services.nginx = { 44 | enable = true; 45 | virtualHosts = { 46 | "_" = { 47 | root = pkgs.writeTextDir "html/index.html" '' 48 | 49 | 50 |

This is a hermetic NixOS configuration!

51 | 52 | 53 | ''; 54 | }; 55 | }; 56 | }; 57 | }; 58 | 59 | in 60 | import "${nixpkgs}/nixos" { inherit system configuration; } 61 | -------------------------------------------------------------------------------- /examples/hermetic_config/default.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = "us-east-1" 3 | profile = "yourprofile" 4 | } 5 | 6 | resource "aws_instance" "hermetic-nixos-system" { 7 | count = 1 8 | ami = "ami-068a62d478710462d" # NixOS 20.09 AMI 9 | 10 | instance_type = "t2.micro" 11 | 12 | key_name = "yourkeyname" 13 | 14 | tags = { 15 | Name = "hermetic-nixos-system-example" 16 | Description = "An example of a hermetic NixOS system deployed by Terraform" 17 | } 18 | } 19 | 20 | module "deploy_nixos" { 21 | source = "github.com/awakesecurity/terraform-nixos//deploy_nixos?ref=c4b1ee6d24b54e92fa3439a12bce349a6805bcdd" 22 | nixos_config = "${path.module}/configuration.nix" 23 | hermetic = true 24 | target_user = "root" 25 | target_host = aws_instance.hermetic-nixos-system[0].public_ip 26 | ssh_private_key_file = pathexpand("~/.ssh/yourkeyname.pem") 27 | } 28 | -------------------------------------------------------------------------------- /fmt: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | set -euo pipefail 4 | 5 | cd "$(dirname "$0")" 6 | 7 | terraform fmt 8 | 9 | fmt_docs() { 10 | ./scripts/terraform-docs-updater "$1" 11 | } 12 | 13 | fmt_docs deploy_nixos 14 | fmt_docs google_image_nixos 15 | fmt_docs google_image_nixos_custom 16 | 17 | echo "." 18 | -------------------------------------------------------------------------------- /google_image_nixos/README.md: -------------------------------------------------------------------------------- 1 | # `google_image_nixos` 2 | 3 | This terraform module creates a new image in the Google Cloud project using a 4 | public tarballs of a NixOS release. Those tarballs are released by the NixOS 5 | project. 6 | 7 | Since image names are unique, only one instance per version of the module is 8 | supported per Google Cloud project. 9 | 10 | ## Example 11 | 12 | ```hcl 13 | module "nixos_image_1809" { 14 | source = "github.com/tweag/terraform-nixos/google_image_nixos" 15 | nixos_version = "18.09" 16 | } 17 | 18 | resource "google_compute_instance" "example" { 19 | name = "example" 20 | machine_type = "n1-standard-1" 21 | zone = "us-central1-a" 22 | 23 | boot_disk { 24 | initialize_params { 25 | image = module.nixos_image_1809.self_link 26 | } 27 | } 28 | 29 | network_interface { 30 | network = "default" 31 | } 32 | } 33 | ``` 34 | 35 | ### Default configuration.nix 36 | 37 | A new configuration.nix can be passed trough the userdata. Here is the default 38 | configuration to expand upon: 39 | 40 | ```nix 41 | { modulesPath, ... }: 42 | { 43 | imports = [ 44 | "${toString modulesPath}/virtualisation/google-compute-image.nix" 45 | ]; 46 | } 47 | ``` 48 | 49 | ## New NixOS releases 50 | 51 | Run the `./update-url-map` script to fetch new image releases. Please submit a 52 | PR as well! 53 | 54 | 55 | ## Providers 56 | 57 | | Name | Version | 58 | |------|---------| 59 | | google | n/a | 60 | 61 | ## Inputs 62 | 63 | | Name | Description | Type | Default | Required | 64 | |------|-------------|------|---------|:-----:| 65 | | gcp\_project\_id | The ID of the project in which the resource belongs. If it is not provided, the provider project is used. | `string` | `""` | no | 66 | | licenses | A list of license URIs to apply to this image. Changing this forces a new resource to be created. | `list(string)` |
[
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
]
| no | 67 | | nixos\_version | The NixOS version to use. Eg: 18.09 | `string` | `"latest"` | no | 68 | | url\_map | A map of release series to actual releases | `map(string)` |
{
"14.12": "https://nixos-cloud-images.storage.googleapis.com/nixos-14.12.471.1f09b77-x86_64-linux.raw.tar.gz",
"15.09": "https://nixos-cloud-images.storage.googleapis.com/nixos-15.09.425.7870f20-x86_64-linux.raw.tar.gz",
"16.03": "https://nixos-cloud-images.storage.googleapis.com/nixos-image-16.03.847.8688c17-x86_64-linux.raw.tar.gz",
"17.03": "https://nixos-cloud-images.storage.googleapis.com/nixos-image-17.03.1082.4aab5c5798-x86_64-linux.raw.tar.gz",
"18.03": "https://nixos-cloud-images.storage.googleapis.com/nixos-image-18.03.132536.fdb5ba4cdf9-x86_64-linux.raw.tar.gz",
"18.09": "https://nixos-cloud-images.storage.googleapis.com/nixos-image-18.09.1228.a4c4cbb613c-x86_64-linux.raw.tar.gz",
"20.03": "https://nixos-images.storage.googleapis.com/google-cloud-nixos-20.03.1639.73e73c7d6b5.raw.tar.gz",
"latest": "https://nixos-images.storage.googleapis.com/google-cloud-nixos-20.03.1639.73e73c7d6b5.raw.tar.gz"
}
| no | 69 | 70 | ## Outputs 71 | 72 | | Name | Description | 73 | |------|-------------| 74 | | self\_link | Link to the NixOS Compute Image | 75 | 76 | 77 | -------------------------------------------------------------------------------- /google_image_nixos/main.tf: -------------------------------------------------------------------------------- 1 | variable "nixos_version" { 2 | type = string 3 | default = "latest" 4 | description = "The NixOS version to use. Eg: 18.09" 5 | } 6 | 7 | variable "gcp_project_id" { 8 | type = string 9 | default = "" 10 | description = "The ID of the project in which the resource belongs. If it is not provided, the provider project is used." 11 | } 12 | 13 | variable "labels" { 14 | type = map(string) 15 | default = {} 16 | description = "A map of labels applied to this image." 17 | } 18 | 19 | variable "licenses" { 20 | type = list(string) 21 | 22 | default = [ 23 | "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx", 24 | ] 25 | 26 | description = "A list of license URIs to apply to this image. Changing this forces a new resource to be created." 27 | } 28 | 29 | # --- 30 | 31 | locals { 32 | image_url = var.url_map[var.nixos_version] 33 | 34 | # Example: nixos-image-18-09-1228-a4c4cbb613c-x86-64-linux 35 | # 36 | # Remove a few things so that it matches the required regexp for image names 37 | # (?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?) 38 | image_name = replace( 39 | replace(basename(local.image_url), ".raw.tar.gz", ""), 40 | "/[._]+/", 41 | "-", 42 | ) 43 | } 44 | 45 | resource "google_compute_image" "nixos" { 46 | name = local.image_name 47 | description = "NixOS ${var.nixos_version}" 48 | family = "nixos" 49 | project = var.gcp_project_id 50 | labels = var.labels 51 | licenses = var.licenses 52 | 53 | raw_disk { 54 | source = local.image_url 55 | } 56 | } 57 | 58 | # --- 59 | 60 | output "self_link" { 61 | description = "Link to the NixOS Compute Image" 62 | value = google_compute_image.nixos.self_link 63 | } 64 | 65 | -------------------------------------------------------------------------------- /google_image_nixos/update-url-map: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-shell 2 | #!nix-shell -p ruby -i ruby 3 | # vim: ft=ruby 4 | # 5 | # Run this script to update the list of GCE images 6 | # 7 | require "json" 8 | require "uri" 9 | 10 | ENV['NIX_PATH'] = "nixpkgs=channel:nixpkgs-unstable" 11 | 12 | def render_tf 13 | url_map=JSON.load(`nix-instantiate --json --strict --eval ./url_map.nix`) 14 | 15 | out = <<~HEADER 16 | # DON'T EDIT, run $0 instead 17 | variable "url_map" { 18 | type = map(string) 19 | 20 | default = { 21 | HEADER 22 | 23 | url_map.each_pair do |version, gs_url| 24 | u = URI.parse(gs_url) 25 | # convert the gs:// URL to HTTPS URL for Terraform to consume 26 | # 27 | # Eg: "gs://nixos-cloud-images/nixos-image-18.09-x86_64-linux.raw.tar.gz" 28 | https_url = "https://#{u.host}.storage.googleapis.com#{u.path}" 29 | 30 | out += " %- 8s = %s\n" % [ version.inspect, https_url.inspect] 31 | end 32 | 33 | out += <<~FOOTER 34 | } 35 | 36 | description = "A map of release series to actual releases" 37 | } 38 | FOOTER 39 | end 40 | 41 | url_map_tf = render_tf 42 | 43 | open("url_map.tf", "w") do |f| 44 | f.write(url_map_tf) 45 | end 46 | 47 | puts url_map_tf 48 | -------------------------------------------------------------------------------- /google_image_nixos/url_map.nix: -------------------------------------------------------------------------------- 1 | # Indirect link to where the image map is stored 2 | import 3 | -------------------------------------------------------------------------------- /google_image_nixos/url_map.tf: -------------------------------------------------------------------------------- 1 | # DON'T EDIT, run $0 instead 2 | variable "url_map" { 3 | type = map(string) 4 | 5 | default = { 6 | "14.12" = "https://nixos-cloud-images.storage.googleapis.com/nixos-14.12.471.1f09b77-x86_64-linux.raw.tar.gz" 7 | "15.09" = "https://nixos-cloud-images.storage.googleapis.com/nixos-15.09.425.7870f20-x86_64-linux.raw.tar.gz" 8 | "16.03" = "https://nixos-cloud-images.storage.googleapis.com/nixos-image-16.03.847.8688c17-x86_64-linux.raw.tar.gz" 9 | "17.03" = "https://nixos-cloud-images.storage.googleapis.com/nixos-image-17.03.1082.4aab5c5798-x86_64-linux.raw.tar.gz" 10 | "18.03" = "https://nixos-cloud-images.storage.googleapis.com/nixos-image-18.03.132536.fdb5ba4cdf9-x86_64-linux.raw.tar.gz" 11 | "18.09" = "https://nixos-cloud-images.storage.googleapis.com/nixos-image-18.09.1228.a4c4cbb613c-x86_64-linux.raw.tar.gz" 12 | "20.03" = "https://nixos-images.storage.googleapis.com/google-cloud-nixos-20.03.1639.73e73c7d6b5.raw.tar.gz" 13 | "latest" = "https://nixos-images.storage.googleapis.com/google-cloud-nixos-20.03.1639.73e73c7d6b5.raw.tar.gz" 14 | } 15 | 16 | description = "A map of release series to actual releases" 17 | } 18 | -------------------------------------------------------------------------------- /google_image_nixos/versions.tf: -------------------------------------------------------------------------------- 1 | 2 | terraform { 3 | required_version = ">= 0.12" 4 | } 5 | -------------------------------------------------------------------------------- /google_image_nixos_custom/README.md: -------------------------------------------------------------------------------- 1 | # google_cloud_image_nixos 2 | 3 | This terraform module builds and publishes custom NixOS Google Cloud images. 4 | 5 | ## Runtime dependencies 6 | 7 | Because this module uses the "external" provider it needs the following 8 | executables to be in the path to work properly: 9 | 10 | * bash 11 | * nix 12 | * `readlink -f` (busybox or coreutils) 13 | 14 | ## Known limitations 15 | 16 | NixOS images are built at Terraform plan time. This can make the plan quite 17 | slow. 18 | 19 | Building the image doesn't yield any output, unless the build is interrupted or 20 | failed. 21 | 22 | When a new image is published, the old-one gets removed. This potentially 23 | introduces a race-condition where other targets are trying to create new 24 | instances with the old image. To reduce the race window, `create_before_destroy` is being used. See 25 | https://github.com/hashicorp/terraform/issues/15485 for related discussions. 26 | 27 | Only x86_64-linux is currently supported. 28 | 29 | 30 | ## Providers 31 | 32 | | Name | Version | 33 | |------|---------| 34 | | external | n/a | 35 | | google | n/a | 36 | 37 | ## Inputs 38 | 39 | | Name | Description | Type | Default | Required | 40 | |------|-------------|------|---------|:-----:| 41 | | NIX\_PATH | Allow to pass custom NIX\_PATH. Ignored if `-` or empty. | `string` | `"-"` | no | 42 | | bucket\_name | Bucket where to store the image | `any` | n/a | yes | 43 | | gcp\_project\_id | The ID of the project in which the resource belongs. If it is not provided, the provider project is used. | `string` | `""` | no | 44 | | licenses | A list of license URIs to apply to this image. Changing this forces a new resource to be created. | `list(string)` |
[
"https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
]
| no | 45 | | nixos\_config | Path to a nixos configuration.nix file | `any` | n/a | yes | 46 | 47 | ## Outputs 48 | 49 | | Name | Description | 50 | |------|-------------| 51 | | NIX\_PATH | n/a | 52 | | self\_link | n/a | 53 | 54 | 55 | -------------------------------------------------------------------------------- /google_image_nixos_custom/main.tf: -------------------------------------------------------------------------------- 1 | variable "bucket_name" { 2 | description = "Bucket where to store the image" 3 | } 4 | 5 | variable "nixos_config" { 6 | description = "Path to a nixos configuration.nix file" 7 | } 8 | 9 | variable "NIX_PATH" { 10 | type = string 11 | description = "Allow to pass custom NIX_PATH. Ignored if `-` or empty." 12 | default = "-" 13 | } 14 | 15 | variable "gcp_project_id" { 16 | type = string 17 | default = "" 18 | description = "The ID of the project in which the resource belongs. If it is not provided, the provider project is used." 19 | } 20 | 21 | variable "licenses" { 22 | type = list(string) 23 | 24 | default = [ 25 | "https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx", 26 | ] 27 | 28 | description = "A list of license URIs to apply to this image. Changing this forces a new resource to be created." 29 | } 30 | 31 | # ---------------------------------------------------- 32 | 33 | data "external" "nix_build" { 34 | program = ["${path.module}/nixos-build.sh", var.NIX_PATH, var.nixos_config] 35 | } 36 | 37 | locals { 38 | out_path = data.external.nix_build.result.out_path 39 | image_path = data.external.nix_build.result.image_path 40 | 41 | # 3x2d4rdm9kjzk9d9sz87rmhzvcphs23v 42 | out_hash = element(split("-", basename(local.out_path)), 0) 43 | 44 | # Example: 3x2d4rdm9kjzk9d9sz87rmhzvcphs23v-19-03pre-git-x86-64-linux 45 | # 46 | # Remove a few things so that it matches the required regexp for image names 47 | # (?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?) 48 | image_name = "x${substr(local.out_hash, 0, 12)}-${replace( 49 | replace( 50 | basename(local.image_path), 51 | "/\\.raw\\.tar\\.gz|nixos-image-/", 52 | "", 53 | ), 54 | "/[._]+/", 55 | "-", 56 | )}" 57 | 58 | # 3x2d4rdm9kjzk9d9sz87rmhzvcphs23v-nixos-image-19.03pre-git-x86_64-linux.raw.tar.gz 59 | image_filename = "${local.out_hash}-${basename(local.image_path)}" 60 | } 61 | 62 | resource "google_storage_bucket_object" "nixos" { 63 | name = "images/${local.image_filename}" 64 | source = local.image_path 65 | bucket = var.bucket_name 66 | content_type = "application/tar+gzip" 67 | 68 | lifecycle { 69 | create_before_destroy = true 70 | } 71 | } 72 | 73 | resource "google_compute_image" "nixos" { 74 | name = local.image_name 75 | family = "nixos" 76 | project = var.gcp_project_id 77 | licenses = var.licenses 78 | 79 | raw_disk { 80 | source = "https://${var.bucket_name}.storage.googleapis.com/${google_storage_bucket_object.nixos.name}" 81 | } 82 | 83 | lifecycle { 84 | create_before_destroy = true 85 | } 86 | } 87 | 88 | output "self_link" { 89 | value = google_compute_image.nixos.self_link 90 | } 91 | 92 | output "NIX_PATH" { 93 | value = var.NIX_PATH 94 | } 95 | -------------------------------------------------------------------------------- /google_image_nixos_custom/nixos-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Special version of nix-build that integrates with the Terraform external 3 | # provider 4 | set -euo pipefail 5 | 6 | nix_path="${1}" 7 | nixos_config=$(readlink -f "${2:-./configuration.nix}") 8 | 9 | shift 10 | shift 11 | 12 | if [[ -n "$nix_path" && "$nix_path" != "-" ]]; then 13 | export NIX_PATH=$nix_path 14 | fi 15 | 16 | args=( 17 | --arg configuration "$nixos_config" 18 | --argstr system x86_64-linux 19 | --no-out-link 20 | -A config.system.build.googleComputeImage 21 | ) 22 | 23 | out_path=$(nix-build '' "${args[@]}" "$@") 24 | 25 | image_path= 26 | for path in "$out_path"/*.tar.gz; do 27 | image_path=$path 28 | done 29 | 30 | cat </dev/null ; then 18 | if [[ -f "$doc.bak" ]]; then 19 | echo "$doc.bak file detected, aborting" >&2 20 | exit 1 21 | fi 22 | 23 | mv "$doc" "$doc.bak" 24 | { 25 | sed "/$BANNER_START/q" "$doc.bak" 26 | terraform-docs md . 27 | sed -n -e "/$BANNER_END/,\$p" "$doc.bak" 28 | } > "$doc" 29 | 30 | rm "$doc.bak" 31 | else 32 | { 33 | echo "$BANNER_START" 34 | terraform-docs md . 35 | echo "$BANNER_END" 36 | } >> "$doc" 37 | fi 38 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | let 3 | tf = terraform.withPlugins(p: with p; [ 4 | external 5 | google 6 | p.null 7 | random 8 | ]); 9 | # https://github.com/NixOS/nixpkgs/pull/51579 10 | terraform-docs = callPackage ./nix/terraform-docs {}; 11 | in 12 | mkShell { 13 | buildInputs = [ 14 | tf 15 | terraform-docs 16 | ]; 17 | 18 | shellHook = '' 19 | NIX_PATH=nixpkgs=channel:nixos-18.09 20 | ''; 21 | } 22 | --------------------------------------------------------------------------------