├── .gitignore ├── LICENSE ├── README.md ├── examples ├── .terraform.lock.hcl ├── README.md ├── main.tf ├── main.tf-public └── provider.tf ├── instance-pool ├── README.md ├── data.tf ├── files │ └── oci-ubuntu-install.sh ├── instancepool.tf ├── local.tf ├── output.tf ├── template.tf ├── terraform.tf └── vars.tf ├── k3s-cluster └── README.md ├── load-balancer ├── README.md ├── data.tf ├── lb.tf ├── local.tf ├── nsg.tf ├── output.tf ├── terraform.tf └── vars.tf ├── nat-instance ├── README.md ├── data.tf ├── files │ ├── setup_bastion.sh │ └── setup_nat.sh ├── local.tf ├── nat_instance.tf ├── output.tf ├── route_table.tf ├── terraform.tf └── vars.tf ├── network-load-balancer ├── README.md ├── data.tf ├── lb.tf ├── local.tf ├── output.tf ├── terraform.tf └── vars.tf ├── private-vcn ├── README.md ├── local.tf ├── network.tf ├── output.tf ├── security.tf ├── terraform.tf └── vars.tf ├── simple-instance ├── README.md ├── compute.tf ├── data.tf ├── files │ └── oci-ubuntu-install.sh ├── local.tf ├── output.tf ├── terraform.tf └── vars.tf └── simple-vcn ├── README.md ├── local.tf ├── network.tf ├── output.tf ├── security.tf ├── terraform.tf └── vars.tf /.gitignore: -------------------------------------------------------------------------------- 1 | vars-ori.tf_ 2 | main.tf-ori 3 | 4 | # Local .terraform directories 5 | **/.terraform/* 6 | 7 | # .tfstate files 8 | *.tfstate 9 | *.tfstate.* 10 | 11 | # Crash log files 12 | crash.log 13 | 14 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as 15 | # password, private keys, and other secrets. These should not be part of version 16 | # control as they are data points which are potentially sensitive and subject 17 | # to change depending on the environment. 18 | # 19 | *.tfvars 20 | 21 | # Ignore override files as they are usually used to override resources locally and so 22 | # are not checked in 23 | override.tf 24 | override.tf.json 25 | *_override.tf 26 | *_override.tf.json 27 | 28 | # Include override files you do wish to add to version control using negated pattern 29 | # 30 | # !example_override.tf 31 | 32 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 33 | # example: *tfplan* 34 | 35 | # Ignore CLI configuration files 36 | .terraformrc 37 | terraform.rc 38 | 39 | *.json 40 | 41 | *Pipfile 42 | *Pipfile.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![GitHub issues](https://img.shields.io/github/issues/garutilorenzo/oracle-cloud-terraform-examples)](https://github.com/garutilorenzo/oracle-cloud-terraform-examples/issues) 2 | ![GitHub](https://img.shields.io/github/license/garutilorenzo/oracle-cloud-terraform-examples) 3 | [![GitHub forks](https://img.shields.io/github/forks/garutilorenzo/oracle-cloud-terraform-examples)](https://github.com/garutilorenzo/oracle-cloud-terraform-examples/network) 4 | [![GitHub stars](https://img.shields.io/github/stars/garutilorenzo/oracle-cloud-terraform-examples)](https://github.com/garutilorenzo/oracle-cloud-terraform-examples/stargazers) 5 | 6 | # Oracle Cloud terraform examples 7 | 8 | Deploy Oracle Cloud services using Oracle [always free](https://docs.oracle.com/en-us/iaas/Content/FreeTier/freetier_topic-Always_Free_Resources.htm) resources 9 | 10 | **Note** choose a region with enough ARM capacity 11 | 12 | ### Important notes 13 | 14 | * This is repo shows only how to use terraform with the Oracle Cloud infrastructure and use only the **always free** resources. This examples are **not** for a production environment. 15 | * At the end of your trial period (30 days). All the paid resources deployed will be stopped/terminated 16 | * At the end of your trial period (30 days), if you have a running compute instance it will be stopped/hibernated 17 | 18 | ### Table of Contents 19 | 20 | * [Repository structure](#repository-structure) 21 | * [Requirements](#requirements) 22 | * [Setup RSA Key](#example-rsa-key-generation) 23 | * [Oracle provider setup](#oracle-provider-setup) 24 | * [Project setup](#project-setup) 25 | * [Firewall](#firewall) 26 | * [OS](#os) 27 | * [Shape](#shape) 28 | * [Useful documentation](#useful-documentation) 29 | 30 | ### Repository structure 31 | 32 | In this repositroy there are 7 terrafrom modules, in order of dependency: 33 | 34 | * [simple-vcn](simple-vcn/) - Setup a VCN with two PUBLIC subnets 35 | * [private-vcn](private-vcn/) - Setup a VCN with one PUBLIC subnet and one PRIVATE subnet 36 | * [nat-instance](nat-instance/) - Setup a NAT instance (with the Oracle always free account you can't deploy a NAT gateway) 37 | * [simple-instance](simple-instance/) - Deploy a simple instance in a private or public subnet 38 | * [instance-pool](instance-pool/) - Deploy multiple instances using a Oracle instance pool and instance configurations 39 | * [load-balancer](load-balancer/) - Deploy a public load balancer (Layer 7 HTTP) 40 | * [network-load-balancer](network-load-balancer/) - Deploy a private load balancer (Layer 4 TCP) 41 | 42 | For more information on how to use this modules follow the examples in the *examples* directory. To use this repository, clone this repository and use the *example* directory as base dir. 43 | 44 | ### Requirements 45 | 46 | To use this repo you will need: 47 | 48 | * an Oracle Cloud account. You can register [here](https://cloud.oracle.com) 49 | 50 | Once you get the account, follow the *Before you begin* and *1. Prepare* step in [this](https://docs.oracle.com/en-us/iaas/developer-tutorials/tutorials/tf-provider/01-summary.htm) document. 51 | 52 | You need also: 53 | 54 | * [Terraform](https://www.terraform.io/) - Terraform is an open-source infrastructure as code software tool that provides a consistent CLI workflow to manage hundreds of cloud services. Terraform codifies cloud APIs into declarative configuration files. 55 | * [kubectl](https://kubernetes.io/docs/tasks/tools/) - The Kubernetes command-line tool (optional) 56 | * [oci cli](https://docs.oracle.com/en-us/iaas/Content/API/Concepts/cliconcepts.htm) - Oracle command line interface (optional) 57 | 58 | #### Example RSA key generation 59 | 60 | To use terraform with the Oracle Cloud infrastructure you need to generate an RSA key. Generate the rsa key with: 61 | 62 | ``` 63 | openssl genrsa -out ~/.oci/-oracle-cloud.pem 4096 64 | chmod 600 ~/.oci/-oracle-cloud.pem 65 | openssl rsa -pubout -in ~/.oci/-oracle-cloud.pem -out ~/.oci/-oracle-cloud_public.pem 66 | ``` 67 | 68 | replace ** with your name or a string you prefer. 69 | 70 | **NOTE** ~/.oci/-oracle-cloud_public.pem this string will be used on the *terraform.tfvars* used by the Oracle provider plugin, so please take note of this string. 71 | 72 | ### Project setup 73 | 74 | Once you have cloned this repo, change directory to [examples](examples/) dir and choose the example you prefer: *private subnet* or main.tf or *public subnet* main.tf-public file. Edit the example file and set the needed variables (*change-me* variables). Crate a *terraform.tfvars* file, for more detail see [Oracle provider setup](#oracle-provider-setup) and read all the modules requirements in each module directory. 75 | 76 | Or if you prefer you can create a new empty directory in your workspace and start a new project from scratch. To setup the project follow the README.md in the [examples](examples/) directory. 77 | 78 | ### Oracle provider setup 79 | 80 | This is an example of the *terraform.tfvars* file: 81 | 82 | ``` 83 | fingerprint = "" 84 | private_key_path = "~/.oci/-oracle-cloud_public.pem" 85 | user_ocid = "" 86 | tenancy_ocid = "" 87 | compartment_ocid = "" 88 | ``` 89 | 90 | To find your tenency_ocid in the Ocacle Cloud console go to: Governance and Administration > Tenency details, then copy the OCID. 91 | 92 | To find you user_ocid in the Ocacle Cloud console go to User setting (click on the icon in the top right corner, then click on User settings), click your username and then copy the OCID 93 | 94 | The compartment_ocid is the same as tenency_ocid. 95 | 96 | The fingerprint is the fingerprint of your RSA key, you can find this vale under User setting > API Keys 97 | 98 | #### How to find the availability doamin name 99 | 100 | To find the list of the availability domains run this command on che Cloud Shell: 101 | 102 | ``` 103 | oci iam availability-domain list 104 | { 105 | "data": [ 106 | { 107 | "compartment-id": "", 108 | "id": "ocid1.availabilitydomain.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 109 | "name": "iAdc:EU-ZURICH-1-AD-1" 110 | } 111 | ] 112 | } 113 | ``` 114 | 115 | #### How to list all the OS images 116 | 117 | To filter the OS images by shape and OS run this command on che Cloud Shell: 118 | 119 | ``` 120 | oci compute image list --compartment-id --operating-system "Canonical Ubuntu" --shape "VM.Standard.A1.Flex" 121 | { 122 | "data": [ 123 | { 124 | "agent-features": null, 125 | "base-image-id": null, 126 | "billable-size-in-gbs": 2, 127 | "compartment-id": null, 128 | "create-image-allowed": true, 129 | "defined-tags": {}, 130 | "display-name": "Canonical-Ubuntu-20.04-aarch64-2022.01.18-0", 131 | "freeform-tags": {}, 132 | "id": "ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q", 133 | "launch-mode": "NATIVE", 134 | "launch-options": { 135 | "boot-volume-type": "PARAVIRTUALIZED", 136 | "firmware": "UEFI_64", 137 | "is-consistent-volume-naming-enabled": true, 138 | "is-pv-encryption-in-transit-enabled": true, 139 | "network-type": "PARAVIRTUALIZED", 140 | "remote-data-volume-type": "PARAVIRTUALIZED" 141 | }, 142 | "lifecycle-state": "AVAILABLE", 143 | "listing-type": null, 144 | "operating-system": "Canonical Ubuntu", 145 | "operating-system-version": "20.04", 146 | "size-in-mbs": 47694, 147 | "time-created": "2022-01-27T22:53:34.270000+00:00" 148 | }, 149 | ``` 150 | 151 | **Note:** this setup was only tested with Ubuntu 20.04 152 | 153 | ### Firewall 154 | 155 | By default firewall on the compute instances is disabled (except for the nat instance). 156 | 157 | ### Software installed 158 | 159 | In the simple-instance example and in the instance-pool example nginx will be installed by default. 160 | Nginx is used for testing the security list rules an the correct setup of the Load Balancer. 161 | 162 | On the k3s-cluster example, k3s will be automatically installed on all the machines. **NOTE** k3s-cluster setup has moved to [this](https://github.com/garutilorenzo/k3s-oci-cluster) repository. 163 | 164 | ### OS 165 | 166 | The operating system used is Ubuntu 20.04 167 | 168 | ### Shape 169 | 170 | All the provisioned instances are VM.Standard.A1.Flex (Arm processor) with 6GB of ram and 1 CPU. 171 | 172 | With the Oracle always free you can run 4 VM.Standard.A1.Flex instances for free (24 GB of ram an 4 CPU). 173 | 174 | **Note** choose a region with enough ARM capacity 175 | 176 | ### Useful documentation 177 | 178 | Setup the [default vcn resources](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/terraformbestpractices_topic-vcndefaults.htm) documentation. 179 | -------------------------------------------------------------------------------- /examples/.terraform.lock.hcl: -------------------------------------------------------------------------------- 1 | # This file is maintained automatically by "terraform init". 2 | # Manual edits may be lost in future updates. 3 | 4 | provider "registry.terraform.io/hashicorp/cloudinit" { 5 | version = "2.2.0" 6 | hashes = [ 7 | "h1:tQLNREqesrdCQ/bIJnl0+yUK+XfdWzAG0wo4lp10LvM=", 8 | "zh:76825122171f9ea2287fd27e23e80a7eb482f6491a4f41a096d77b666896ee96", 9 | "zh:795a36dee548e30ca9c9d474af9ad6d29290e0a9816154ad38d55381cd0ab12d", 10 | "zh:9200f02cb917fb99e44b40a68936fd60d338e4d30a718b7e2e48024a795a61b9", 11 | "zh:a33cf255dc670c20678063aa84218e2c1b7a67d557f480d8ec0f68bc428ed472", 12 | "zh:ba3c1b2cd0879286c1f531862c027ec04783ece81de67c9a3b97076f1ce7f58f", 13 | "zh:bd575456394428a1a02191d2e46af0c00e41fd4f28cfe117d57b6aeb5154a0fb", 14 | "zh:c68dd1db83d8437c36c92dc3fc11d71ced9def3483dd28c45f8640cfcd59de9a", 15 | "zh:cbfe34a90852ed03cc074601527bb580a648127255c08589bc3ef4bf4f2e7e0c", 16 | "zh:d6ffd7398c6d1f359b96f5b757e77b99b339fbb91df1b96ac974fe71bc87695c", 17 | "zh:d9c15285f847d7a52df59e044184fb3ba1b7679fd0386291ed183782683d9517", 18 | "zh:f7dd02f6d36844da23c9a27bb084503812c29c1aec4aba97237fec16860fdc8c", 19 | ] 20 | } 21 | 22 | provider "registry.terraform.io/hashicorp/template" { 23 | version = "2.2.0" 24 | hashes = [ 25 | "h1:94qn780bi1qjrbC3uQtjJh3Wkfwd5+tTtJHOb7KTg9w=", 26 | "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", 27 | "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", 28 | "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", 29 | "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", 30 | "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", 31 | "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", 32 | "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", 33 | "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", 34 | "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", 35 | "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", 36 | ] 37 | } 38 | 39 | provider "registry.terraform.io/oracle/oci" { 40 | version = "4.105.0" 41 | constraints = ">= 4.64.0" 42 | hashes = [ 43 | "h1:/CC+3yPQLRp37dJSfcL/Tr5U1MqlnIfQ4G9VoB18gn4=", 44 | "zh:1af82982ed188d52d88af21d392d7f5284ffe855100edc1aec5821c47513e5af", 45 | "zh:1dfda986b069491070027ef235b6b985d8bcc8f250c8c9760ee05e710137f5a1", 46 | "zh:1e23c53207211846f52d0eb8cfbf32a9d67f07432a36228424242363ff2c689e", 47 | "zh:23f878c3e8cd2b0f2017b4b703f6956dae45596412443f257cdf21d41873d2f7", 48 | "zh:272a723136f309fc05616504bba35d8679e6ef895ed133b0ccd2345975c07ed9", 49 | "zh:47a7e36da90caed20bd960aa85b95f331506153dd6e3a65f12e6afc2a3bca2f2", 50 | "zh:765d793456a09a38af537fae363ec2ef0a464d412c562f538c654b28d57bb69f", 51 | "zh:9b12af85486a96aedd8d7984b0ff811a4b42e3d88dad1a3fb4c0b580d04fa425", 52 | "zh:9ee8c6e5aa8279c9cea5c47b81da6114b8f22848fc74b00dc4fb0fc89b71ec7f", 53 | "zh:a098d77dfc9b1123180f3beab3ce728303b67cae54e7d5ee40fc75156b3f4ee7", 54 | "zh:a607f78b8e6017968bf651b4b19039849bd06ef335633ee33e8dd6bc6341307a", 55 | "zh:b446b3d95112b535993ba0c3b309b4a235c7bd2003e49204d48bc3945bc729ba", 56 | "zh:b9e0527f6660674adacb036b6b7295f6061cdacb9c2db8333d9461228e37bcd0", 57 | "zh:bd933cd3f3463c6c566aca4e3349eab2949cc51331eaae82fa5b64be8a0b28cc", 58 | "zh:f0090a7556c80f5ad0e73bc53982e2844a381416d9bc35d4d27ff75ed24c87b8", 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | In this folder there are two examples: 4 | 5 | * main.tf - Use a private subnet with a nat instance, all services are deployed on the pivate subnet. (Default example) 6 | * main.tf-public - Use a public subnet, all the services are deployed in the public subnet. (Disabled example) 7 | 8 | If you want to use the public example, rename the *main.tf-public* in *main.tf*. Keep **ONLY ONE** *.tf file. 9 | 10 | Now adjust all the *change-me* variables inside the main.tf file. Once you have setup your environment, we are ready to init terraform: 11 | 12 | ``` 13 | Initializing modules... 14 | 15 | Initializing the backend... 16 | 17 | Initializing provider plugins... 18 | - Reusing previous version of hashicorp/oci from the dependency lock file 19 | - Reusing previous version of hashicorp/template from the dependency lock file 20 | - Using previously-installed hashicorp/oci v4.65.0 21 | - Using previously-installed hashicorp/template v2.2.0 22 | 23 | Terraform has been successfully initialized! 24 | 25 | You may now begin working with Terraform. Try running "terraform plan" to see 26 | any changes that are required for your infrastructure. All Terraform commands 27 | should now work. 28 | 29 | If you ever set or change modules or backend configuration for Terraform, 30 | rerun this command to reinitialize your working directory. If you forget, other 31 | commands will detect it and remind you to do so if necessary. 32 | ``` 33 | 34 | ### Deploy 35 | 36 | We are now ready to deploy our infrastructure. First we ask terraform to plan the execution with: 37 | 38 | ``` 39 | terraform plan 40 | 41 | ... 42 | ... 43 | ... 44 | 45 | + source_details { 46 | + boot_volume_size_in_gbs = (known after apply) 47 | + kms_key_id = (known after apply) 48 | + source_id = "ocid1.image.oc1.REGION.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q" 49 | + source_type = "image" 50 | } 51 | } 52 | 53 | Plan: 24 to add, 0 to change, 0 to destroy. 54 | 55 | Changes to Outputs: 56 | + instance_ip = (known after apply) 57 | + instance_pool_id = (known after apply) 58 | + instance_pool_ips = [ 59 | + (known after apply), 60 | + (known after apply), 61 | ] 62 | + instance_pool_size = 2 63 | + internal_lb_ip = (known after apply) 64 | + lb_ip = (known after apply) 65 | + nat_instance_id = (known after apply) 66 | + nat_instance_public_ip = (known after apply) 67 | + private_subnet_id = (known after apply) 68 | + public_subnet_cidr = "10.0.0.0/24" 69 | + public_subnet_id = (known after apply) 70 | + security_list_id = (known after apply) 71 | + vcn_id = (known after apply) 72 | 73 | ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 74 | 75 | Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now. 76 | ``` 77 | 78 | now we can deploy our resources with: 79 | 80 | ``` 81 | terraform apply 82 | 83 | ... 84 | ... 85 | ... 86 | 87 | Plan: 24 to add, 0 to change, 0 to destroy. 88 | 89 | Changes to Outputs: 90 | + instance_ip = (known after apply) 91 | + instance_pool_id = (known after apply) 92 | + instance_pool_ips = [ 93 | + (known after apply), 94 | + (known after apply), 95 | ] 96 | + instance_pool_size = 2 97 | + internal_lb_ip = (known after apply) 98 | + lb_ip = (known after apply) 99 | + nat_instance_id = (known after apply) 100 | + nat_instance_public_ip = (known after apply) 101 | + private_subnet_id = (known after apply) 102 | + public_subnet_cidr = "10.0.0.0/24" 103 | + public_subnet_id = (known after apply) 104 | + security_list_id = (known after apply) 105 | + vcn_id = (known after apply) 106 | 107 | Do you want to perform these actions? 108 | Terraform will perform the actions described above. 109 | Only 'yes' will be accepted to approve. 110 | 111 | Enter a value: yes 112 | 113 | ... 114 | ... 115 | ... 116 | 117 | Apply complete! Resources: 24 added, 0 changed, 0 destroyed. 118 | 119 | Outputs: 120 | 121 | instance_ip = "10..X.X.X" 122 | instance_pool_id = "ocid1.instancepool.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 123 | instance_pool_ips = [ 124 | "10..X.X.X", 125 | "10..X.X.X", 126 | ] 127 | instance_pool_size = 2 128 | internal_lb_ip = tolist([ 129 | { 130 | "ip_address" = "10..X.X.X" 131 | "ip_version" = "IPV4" 132 | "is_public" = false 133 | "reserved_ip" = tolist([]) 134 | }, 135 | ]) 136 | lb_ip = tolist([ 137 | "144.X.X.X", 138 | ]) 139 | nat_instance_id = "ocid1.instance.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 140 | nat_instance_public_ip = "152.X.X.X" 141 | private_subnet_id = "ocid1.subnet.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 142 | public_subnet_cidr = "10.0.0.0/24" 143 | public_subnet_id = "ocid1.subnet.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 144 | security_list_id = "ocid1.securitylist.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 145 | vcn_id = "ocid1.vcn.oc1.REGION.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" 146 | 147 | ``` 148 | 149 | ### Resources test 150 | 151 | #### Public LB Test 152 | 153 | ``` 154 | curl http://144.X.X.X 155 | 156 | 157 | 158 | 159 | Welcome to nginx! 160 | 167 | 168 | 169 |

Welcome to nginx!

170 |

If you see this page, the nginx web server is successfully installed and 171 | working. Further configuration is required.

172 | 173 |

For online documentation and support please refer to 174 | nginx.org.
175 | Commercial support is available at 176 | nginx.com.

177 | 178 |

Thank you for using nginx.

179 |

Hello from: inst-ikv6i-ubuntu-instance-pool

180 | 181 | 182 | ``` 183 | 184 | #### Private LB Test 185 | 186 | First we need to [connect](#connect-to-private-instances) via ssh on a private instance. **NOTE** we need to connect to the instance that is not part of the instance group. 187 | 188 | Now we can call the public LB ip: 189 | 190 | ``` 191 | curl http://10.X.X.X 192 | 193 | 194 | 195 | 196 | Welcome to nginx! 197 | 204 | 205 | 206 |

Welcome to nginx!

207 |

If you see this page, the nginx web server is successfully installed and 208 | working. Further configuration is required.

209 | 210 |

For online documentation and support please refer to 211 | nginx.org.
212 | Commercial support is available at 213 | nginx.com.

214 | 215 |

Thank you for using nginx.

216 |

Hello from: inst-ikv6i-ubuntu-instance-pool

217 | 218 | 219 | ``` 220 | 221 | ### Connect to private instances 222 | 223 | We can connect to the private instances using the nat instance as Jump server: 224 | 225 | ``` 226 | ssh -J bastion@ ubuntu@ 227 | 228 | Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.11.0-1027-oracle aarch64) 229 | 230 | * Documentation: https://help.ubuntu.com 231 | * Management: https://landscape.canonical.com 232 | * Support: https://ubuntu.com/advantage 233 | 234 | System information as of Thu Mar 3 14:34:39 UTC 2022 235 | 236 | System load: 0.0 Processes: 151 237 | Usage of /: 3.9% of 44.97GB Users logged in: 0 238 | Memory usage: 4% IPv4 address for enp0s3: 10.0.1.239 239 | Swap usage: 0% 240 | 241 | 242 | 7 updates can be applied immediately. 243 | 7 of these updates are standard security updates. 244 | To see these additional updates run: apt list --upgradable 245 | 246 | 247 | *** System restart required *** 248 | Last login: Thu Mar 3 14:34:20 2022 from 10.0.0.37 249 | To run a command as administrator (user "root"), use "sudo ". 250 | See "man sudo_root" for details. 251 | 252 | ubuntu@inst-a73cs-ubuntu-instance-pool:~$ 253 | ``` 254 | 255 | ### Start a project from scratch 256 | 257 | If you want to create a new project from scratch you need three files: 258 | 259 | * terraform.tfvars - More details in [Oracle provider setup](../README.md#oracle-provider-setup) 260 | * main.tf - download main.tf file or main.tf-public based on your needs. If you choose main.tf-public **remember** to rename the file in main.tf 261 | * provider.tf - download the file from this directory 262 | 263 | ### Cleanup 264 | 265 | ``` 266 | terraform destroy 267 | ``` -------------------------------------------------------------------------------- /examples/main.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | type = string 3 | } 4 | 5 | variable "tenancy_ocid" { 6 | type = string 7 | } 8 | 9 | variable "user_ocid" { 10 | type = string 11 | } 12 | 13 | variable "fingerprint" { 14 | type = string 15 | } 16 | 17 | variable "private_key_path" { 18 | type = string 19 | } 20 | 21 | variable "region" { 22 | default = "" 23 | } 24 | 25 | variable "environment" { 26 | default = "staging" 27 | } 28 | 29 | variable "availability_domain" { 30 | default = "" 31 | } 32 | 33 | module "private-vcn" { 34 | region = var.region 35 | compartment_ocid = var.compartment_ocid 36 | my_public_ip_cidr = "" 37 | environment = var.environment 38 | source = "../private-vcn" 39 | } 40 | 41 | output "vcn_id" { 42 | value = module.private-vcn.vcn_id 43 | } 44 | 45 | output "public_subnet_id" { 46 | value = module.private-vcn.public_subnet_id 47 | } 48 | 49 | output "private_subnet_id" { 50 | value = module.private-vcn.private_subnet_id 51 | } 52 | 53 | output "security_list_id" { 54 | value = module.private-vcn.security_list_id 55 | } 56 | 57 | output "public_subnet_cidr" { 58 | value = module.private-vcn.public_subnet_cidr 59 | } 60 | 61 | module "nat-instance" { 62 | region = var.region 63 | compartment_ocid = var.compartment_ocid 64 | availability_domain = var.availability_domain 65 | vcn_id = module.private-vcn.vcn_id 66 | private_subnet_id = module.private-vcn.private_subnet_id 67 | public_subnet_id = module.private-vcn.public_subnet_id 68 | environment = var.environment 69 | source = "../nat-instance" 70 | } 71 | 72 | output "nat_instance_id" { 73 | value = module.nat-instance.nat_instance_id 74 | } 75 | 76 | output "nat_instance_public_ip" { 77 | value = module.nat-instance.nat_instance_public_ip 78 | } 79 | 80 | module "simple-instance" { 81 | region = var.region 82 | compartment_ocid = var.compartment_ocid 83 | availability_domain = var.availability_domain 84 | is_private = true 85 | private_subnet_id = module.private-vcn.private_subnet_id 86 | public_subnet_id = module.private-vcn.public_subnet_id 87 | environment = var.environment 88 | source = "../simple-instance" 89 | } 90 | 91 | output "instance_ip" { 92 | value = module.simple-instance.instance_ip 93 | } 94 | 95 | module "instance-pool" { 96 | region = var.region 97 | compartment_ocid = var.compartment_ocid 98 | availability_domain = var.availability_domain 99 | is_private = true 100 | private_subnet_id = module.private-vcn.private_subnet_id 101 | public_subnet_id = module.private-vcn.public_subnet_id 102 | public_subnet_cidr = module.private-vcn.public_subnet_cidr 103 | environment = var.environment 104 | source = "../instance-pool" 105 | } 106 | 107 | output "instance_pool_ips" { 108 | value = module.instance-pool.instances_ips 109 | } 110 | 111 | output "instance_pool_id" { 112 | value = module.instance-pool.instance_pool_id 113 | } 114 | 115 | output "instance_pool_size" { 116 | value = module.instance-pool.instance_pool_size 117 | } 118 | 119 | 120 | module "load-balancer" { 121 | region = var.region 122 | compartment_ocid = var.compartment_ocid 123 | is_private = false 124 | instance_pool_id = module.instance-pool.instance_pool_id 125 | instance_pool_size = module.instance-pool.instance_pool_size 126 | vcn_id = module.private-vcn.vcn_id 127 | private_subnet_id = module.private-vcn.private_subnet_id 128 | public_subnet_id = module.private-vcn.public_subnet_id 129 | environment = var.environment 130 | source = "../load-balancer" 131 | } 132 | 133 | output "lb_ip" { 134 | value = module.load-balancer.lb_ip 135 | } 136 | 137 | module "network-load-balancer" { 138 | region = var.region 139 | compartment_ocid = var.compartment_ocid 140 | is_private = true 141 | instance_pool_id = module.instance-pool.instance_pool_id 142 | instance_pool_size = module.instance-pool.instance_pool_size 143 | vcn_id = module.private-vcn.vcn_id 144 | private_subnet_id = module.private-vcn.private_subnet_id 145 | public_subnet_id = module.private-vcn.public_subnet_id 146 | environment = var.environment 147 | source = "../network-load-balancer" 148 | } 149 | 150 | output "internal_lb_ip" { 151 | value = module.network-load-balancer.lb_ip 152 | } -------------------------------------------------------------------------------- /examples/main.tf-public: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | type = string 3 | } 4 | 5 | variable "tenancy_ocid" { 6 | type = string 7 | } 8 | 9 | variable "user_ocid" { 10 | type = string 11 | } 12 | 13 | variable "fingerprint" { 14 | type = string 15 | } 16 | 17 | variable "private_key_path" { 18 | type = string 19 | } 20 | 21 | variable "region" { 22 | default = "" 23 | } 24 | 25 | variable "environment" { 26 | default = "staging" 27 | } 28 | 29 | variable "availability_domain" { 30 | default = "" 31 | } 32 | 33 | module "simple-vcn" { 34 | region = var.region 35 | compartment_ocid = var.compartment_ocid 36 | my_public_ip_cidr = "" 37 | environment = var.environment 38 | source = "../simple-vcn" 39 | } 40 | 41 | output "vcn_id" { 42 | value = module.simple-vcn.vcn_id 43 | } 44 | 45 | output "public_subnet_id" { 46 | value = module.simple-vcn.public_subnet_id 47 | } 48 | 49 | output "secondary_public_subnet_id" { 50 | value = module.simple-vcn.secondary_public_subnet_id 51 | } 52 | 53 | output "security_list_id" { 54 | value = module.simple-vcn.security_list_id 55 | } 56 | 57 | output "public_subnet_cidr" { 58 | value = module.simple-vcn.public_subnet_cidr 59 | } 60 | 61 | module "simple-instance" { 62 | region = var.region 63 | compartment_ocid = var.compartment_ocid 64 | availability_domain = var.availability_domain 65 | private_subnet_id = module.simple-vcn.secondary_public_subnet_id 66 | public_subnet_id = module.simple-vcn.public_subnet_id 67 | environment = var.environment 68 | source = "../simple-instance" 69 | } 70 | 71 | output "instance_ip" { 72 | value = module.simple-instance.instance_ip 73 | } 74 | 75 | module "instance-pool" { 76 | region = var.region 77 | compartment_ocid = var.compartment_ocid 78 | availability_domain = var.availability_domain 79 | private_subnet_id = module.simple-vcn.secondary_public_subnet_id 80 | public_subnet_id = module.simple-vcn.public_subnet_id 81 | public_subnet_cidr = module.simple-vcn.public_subnet_cidr 82 | environment = var.environment 83 | source = "../instance-pool" 84 | } 85 | 86 | output "instance_pool_ips" { 87 | value = module.instance-pool.instances_ips 88 | } 89 | 90 | output "instance_pool_id" { 91 | value = module.instance-pool.instance_pool_id 92 | } 93 | 94 | output "instance_pool_size" { 95 | value = module.instance-pool.instance_pool_size 96 | } 97 | 98 | module "load-balancer" { 99 | region = var.region 100 | compartment_ocid = var.compartment_ocid 101 | is_private = false 102 | instance_pool_id = module.instance-pool.instance_pool_id 103 | instance_pool_size = module.instance-pool.instance_pool_size 104 | vcn_id = module.simple-vcn.vcn_id 105 | private_subnet_id = module.simple-vcn.secondary_public_subnet_id 106 | public_subnet_id = module.simple-vcn.public_subnet_id 107 | environment = var.environment 108 | source = "../load-balancer" 109 | } 110 | 111 | output "lb_ip" { 112 | value = module.load-balancer.lb_ip 113 | } 114 | 115 | module "network-load-balancer" { 116 | region = var.region 117 | compartment_ocid = var.compartment_ocid 118 | is_private = true 119 | instance_pool_id = module.instance-pool.instance_pool_id 120 | instance_pool_size = module.instance-pool.instance_pool_size 121 | vcn_id = module.simple-vcn.vcn_id 122 | private_subnet_id = module.simple-vcn.secondary_public_subnet_id 123 | public_subnet_id = module.simple-vcn.public_subnet_id 124 | environment = var.environment 125 | source = "../network-load-balancer" 126 | } 127 | 128 | output "internal_lb_ip" { 129 | value = module.network-load-balancer.lb_ip 130 | } -------------------------------------------------------------------------------- /examples/provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } 9 | 10 | provider "oci" { 11 | tenancy_ocid = var.tenancy_ocid 12 | user_ocid = var.user_ocid 13 | private_key_path = var.private_key_path 14 | fingerprint = var.fingerprint 15 | region = var.region 16 | } -------------------------------------------------------------------------------- /instance-pool/README.md: -------------------------------------------------------------------------------- 1 | # Instance pool 2 | 3 | This module will deploy an Instance pool made by two compute instances. Also this module will create one instance configuration used by the instance pool. 4 | 5 | If you choose to publish this compute instances in a private subnet, you need a NAT instance (refer to nat-instance module). The nat instance can be used also as bation host to reach the private instance, or if you prefer you can deploy a dedicated bastion host (refer to bastion-host module). 6 | 7 | ### Requirements 8 | 9 | * One vcn with a public or private subnet (simple-vcn or private-vcn module) 10 | * One nat instance if the instance pool *is_private* (nat-instance module) 11 | 12 | ### Module variables 13 | 14 | | Var | Required | Desc | 15 | | ------- | ------- | ----------- | 16 | | `region` | `yes` | set the correct OCI region based on your needs | 17 | | `availability_domain` | `yes` | Set the correct availability domain. See [how](../README.md#how-to-find-the-availability-doamin-name) to find the availability domain| 18 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 19 | | `environment` | `yes` | Current work environment (Example: staging/dev/prod). This value is used for tag all the deployed resources | 20 | | `private_subnet_id` | `yes` | Private subnet OCID | 21 | | `public_subnet_id` | `yes` | Public subnet OCID | 22 | | `public_subnet_cidr` | `yes` | Public subnet CIDR | 23 | | `instance_pool_size` | `no` | Number of instances in the instance pool. Default: 2 | 24 | | `fault_domains` | `no` | Fault list. Default: FAULT-DOMAIN-1, FAULT-DOMAIN-2, FAULT-DOMAIN-3 | 25 | | `PATH_TO_PUBLIC_KEY` | `no` | Path to your public ssh key (Default: "~/.ssh/id_rsa.pub) | 26 | | `is_private` | `no` | Bool value. If true the instance pool will be deployed in a private subnet. Default: false | 27 | | `os_image_id` | `no` | OS image OCID. Default: ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q - Canonical-Ubuntu-20.04-aarch64-2022.01.18-0 | 28 | 29 | ### Output 30 | 31 | The module will output: 32 | 33 | * instances_ips, IPs of the instances 34 | * instance_pool_id, Instance pool OCID -------------------------------------------------------------------------------- /instance-pool/data.tf: -------------------------------------------------------------------------------- 1 | data "cloudinit_config" "ubuntu_init" { 2 | gzip = true 3 | base64_encode = true 4 | 5 | part { 6 | content_type = "text/x-shellscript" 7 | content = templatefile("${path.module}/files/oci-ubuntu-install.sh", { public_subnet_cidr = var.public_subnet_cidr }) 8 | } 9 | } 10 | 11 | data "oci_core_instance_pool_instances" "ubuntu_instance_pool_instances" { 12 | depends_on = [ 13 | oci_core_instance_pool.ubuntu_instance_pool, 14 | ] 15 | compartment_id = var.compartment_ocid 16 | instance_pool_id = oci_core_instance_pool.ubuntu_instance_pool.id 17 | } 18 | 19 | data "oci_core_instance" "ubuntu_instance_pool_instances_ips" { 20 | count = var.instance_pool_size 21 | instance_id = data.oci_core_instance_pool_instances.ubuntu_instance_pool_instances.instances[count.index].id 22 | } -------------------------------------------------------------------------------- /instance-pool/files/oci-ubuntu-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update 4 | apt-get -y upgrade 5 | apt-get -y install nginx 6 | 7 | systemctl enable nginx 8 | systemctl start nginx 9 | 10 | hostname=$(hostname) 11 | 12 | cat < /etc/nginx/nginx.conf 13 | user www-data; 14 | worker_processes auto; 15 | pid /run/nginx.pid; 16 | include /etc/nginx/modules-enabled/*.conf; 17 | 18 | events { 19 | worker_connections 768; 20 | # multi_accept on; 21 | } 22 | 23 | http { 24 | 25 | ## 26 | # Basic Settings 27 | ## 28 | 29 | sendfile on; 30 | tcp_nopush on; 31 | tcp_nodelay on; 32 | keepalive_timeout 65; 33 | types_hash_max_size 2048; 34 | # server_tokens off; 35 | 36 | # server_names_hash_bucket_size 64; 37 | # server_name_in_redirect off; 38 | 39 | include /etc/nginx/mime.types; 40 | default_type application/octet-stream; 41 | 42 | ## 43 | # SSL Settings 44 | ## 45 | 46 | ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE 47 | ssl_prefer_server_ciphers on; 48 | 49 | ## 50 | # Set real ip 51 | ## 52 | 53 | set_real_ip_from 127.0.0.1; 54 | set_real_ip_from ${public_subnet_cidr}; 55 | real_ip_header X-Forwarded-For; 56 | real_ip_recursive on; 57 | 58 | ## 59 | # Logging Settings 60 | ## 61 | 62 | access_log /var/log/nginx/access.log; 63 | error_log /var/log/nginx/error.log; 64 | 65 | ## 66 | # Gzip Settings 67 | ## 68 | 69 | gzip on; 70 | gzip_disable "msie6"; 71 | 72 | gzip_vary on; 73 | gzip_proxied any; 74 | gzip_comp_level 6; 75 | gzip_buffers 16 8k; 76 | gzip_http_version 1.1; 77 | gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; 78 | 79 | ## 80 | # Virtual Host Configs 81 | ## 82 | 83 | include /etc/nginx/conf.d/*.conf; 84 | include /etc/nginx/sites-enabled/*; 85 | } 86 | EOF 87 | 88 | systemctl restart nginx.service 89 | 90 | cat < /var/www/html/index.nginx-debian.html 91 | 92 | 93 | 94 | Welcome to nginx! 95 | 102 | 103 | 104 |

Welcome to nginx!

105 |

If you see this page, the nginx web server is successfully installed and 106 | working. Further configuration is required.

107 | 108 |

For online documentation and support please refer to 109 | nginx.org.
110 | Commercial support is available at 111 | nginx.com.

112 | 113 |

Thank you for using nginx.

114 |

Hello from: $hostname

115 | 116 | 117 | EOF 118 | 119 | # Disable firewall 120 | /usr/sbin/netfilter-persistent stop 121 | /usr/sbin/netfilter-persistent flush 122 | 123 | systemctl stop netfilter-persistent.service 124 | systemctl disable netfilter-persistent.service -------------------------------------------------------------------------------- /instance-pool/instancepool.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_instance_pool" "ubuntu_instance_pool" { 2 | 3 | lifecycle { 4 | create_before_destroy = true 5 | ignore_changes = [load_balancers, freeform_tags] 6 | } 7 | 8 | display_name = var.instance_pool_name 9 | compartment_id = var.compartment_ocid 10 | instance_configuration_id = oci_core_instance_configuration.ubuntu_template.id 11 | 12 | placement_configurations { 13 | availability_domain = var.availability_domain 14 | primary_subnet_id = var.is_private == true ? var.private_subnet_id : var.public_subnet_id 15 | fault_domains = var.fault_domains 16 | } 17 | 18 | size = var.instance_pool_size 19 | 20 | freeform_tags = local.tags 21 | } -------------------------------------------------------------------------------- /instance-pool/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /instance-pool/output.tf: -------------------------------------------------------------------------------- 1 | output "instances_ips" { 2 | depends_on = [ 3 | data.oci_core_instance_pool_instances.ubuntu_instance_pool_instances, 4 | ] 5 | value = var.is_private == true ? data.oci_core_instance.ubuntu_instance_pool_instances_ips.*.private_ip : data.oci_core_instance.ubuntu_instance_pool_instances_ips.*.public_ip 6 | } 7 | 8 | output "instance_pool_id" { 9 | value = oci_core_instance_pool.ubuntu_instance_pool.id 10 | } 11 | 12 | output "instance_pool_size" { 13 | value = oci_core_instance_pool.ubuntu_instance_pool.size 14 | } -------------------------------------------------------------------------------- /instance-pool/template.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_instance_configuration" "ubuntu_template" { 2 | 3 | compartment_id = var.compartment_ocid 4 | display_name = "Ubuntu 20.04 instance config" 5 | 6 | instance_details { 7 | 8 | instance_type = "compute" 9 | 10 | launch_details { 11 | 12 | agent_config { 13 | is_management_disabled = "false" 14 | is_monitoring_disabled = "false" 15 | 16 | plugins_config { 17 | desired_state = "DISABLED" 18 | name = "Vulnerability Scanning" 19 | } 20 | 21 | plugins_config { 22 | desired_state = "ENABLED" 23 | name = "Compute Instance Monitoring" 24 | } 25 | 26 | plugins_config { 27 | desired_state = "DISABLED" 28 | name = "Bastion" 29 | } 30 | } 31 | 32 | availability_domain = var.availability_domain 33 | compartment_id = var.compartment_ocid 34 | 35 | create_vnic_details { 36 | assign_public_ip = var.is_private == true ? false : true 37 | subnet_id = var.is_private == true ? var.private_subnet_id : var.public_subnet_id 38 | } 39 | 40 | display_name = "Ubuntu Template" 41 | 42 | metadata = { 43 | "ssh_authorized_keys" = file(var.PATH_TO_PUBLIC_KEY) 44 | "user_data" = data.cloudinit_config.ubuntu_init.rendered 45 | } 46 | 47 | shape = "VM.Standard.A1.Flex" 48 | shape_config { 49 | memory_in_gbs = "6" 50 | ocpus = "1" 51 | } 52 | source_details { 53 | image_id = var.os_image_id 54 | source_type = "image" 55 | } 56 | } 57 | } 58 | 59 | freeform_tags = local.tags 60 | } -------------------------------------------------------------------------------- /instance-pool/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /instance-pool/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "availability_domain" { 10 | 11 | } 12 | 13 | variable "fault_domains" { 14 | type = list(any) 15 | default = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"] 16 | } 17 | 18 | variable "PATH_TO_PUBLIC_KEY" { 19 | type = string 20 | default = "~/.ssh/id_rsa.pub" 21 | description = "Path to your public key" 22 | } 23 | 24 | variable "environment" { 25 | type = string 26 | } 27 | 28 | variable "is_private" { 29 | type = bool 30 | default = false 31 | } 32 | 33 | variable "public_subnet_id" { 34 | type = string 35 | } 36 | 37 | variable "private_subnet_id" { 38 | type = string 39 | } 40 | 41 | variable "public_subnet_cidr" { 42 | type = string 43 | } 44 | 45 | variable "os_image_id" { 46 | default = "ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q" # Canonical-Ubuntu-20.04-aarch64-2022.01.18-0 47 | } 48 | 49 | variable "instance_pool_size" { 50 | type = number 51 | default = 2 52 | } 53 | 54 | variable "instance_pool_name" { 55 | type = string 56 | default = "ubuntu-instance-pool" 57 | } -------------------------------------------------------------------------------- /k3s-cluster/README.md: -------------------------------------------------------------------------------- 1 | # k3s cluster 2 | 3 | Please refer to [this](https://github.com/garutilorenzo/k3s-oci-cluster) repository -------------------------------------------------------------------------------- /load-balancer/README.md: -------------------------------------------------------------------------------- 1 | # Load balancer (Layer 7) 2 | 3 | This module will deploy a Load Balancer (L7). The LB can be public or private (*is_private* variable). The LB will be attached to the instances in a instance pool (*instance_pool_id* variable). Also this module will deploy one Network security group that will be attached to the Load Balancer, this NSG will allow traffic on port 80 only to the LB. 4 | 5 | ### Requirements 6 | 7 | * One vcn with a public or private subnet (simple-vcn or private-vcn module) 8 | 9 | ### Module variables 10 | 11 | | Var | Required | Desc | 12 | | ------- | ------- | ----------- | 13 | | `region` | `yes` | set the correct OCI region based on your needs | 14 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 15 | | `vcn_id` | `yes` | The VCN OCID | 16 | | `private_subnet_id` | `yes` | Private subnet OCID | 17 | | `public_subnet_id` | `yes` | Public subnet OCID | 18 | | `instance_pool_size` | `yes` | Instance pool size | 19 | | `instance_pool_id` | `yes` | Instance pool ocid OCID | 20 | | `is_private` | `no` | Bool value. If true the LB will be a private LB (no public ip) Default: false | 21 | | `lb_shape` | `no` | Load balancer shape. Default: flexible | 22 | 23 | ### Output 24 | 25 | lb_ip, LB public or private ip address -------------------------------------------------------------------------------- /load-balancer/data.tf: -------------------------------------------------------------------------------- 1 | data "oci_core_instance_pool_instances" "ubuntu_instance_pool_instances" { 2 | compartment_id = var.compartment_ocid 3 | instance_pool_id = var.instance_pool_id 4 | } 5 | 6 | data "oci_core_instance" "ubuntu_instance_pool_instances_ips" { 7 | count = var.instance_pool_size 8 | instance_id = data.oci_core_instance_pool_instances.ubuntu_instance_pool_instances.instances[count.index].id 9 | } -------------------------------------------------------------------------------- /load-balancer/lb.tf: -------------------------------------------------------------------------------- 1 | resource "oci_load_balancer_load_balancer" "load_balancer_l7" { 2 | compartment_id = var.compartment_ocid 3 | display_name = "LB Layer 7" 4 | shape = var.lb_shape 5 | subnet_ids = [var.public_subnet_id] 6 | network_security_group_ids = [oci_core_network_security_group.public_lb_nsg.id] 7 | 8 | ip_mode = "IPV4" 9 | is_private = var.is_private 10 | 11 | shape_details { 12 | maximum_bandwidth_in_mbps = 10 13 | minimum_bandwidth_in_mbps = 10 14 | } 15 | 16 | freeform_tags = local.tags 17 | } 18 | 19 | # HTTP 20 | resource "oci_load_balancer_listener" "http_listener" { 21 | default_backend_set_name = oci_load_balancer_backend_set.http_backend_set.name 22 | load_balancer_id = oci_load_balancer_load_balancer.load_balancer_l7.id 23 | name = "http_listener" 24 | port = 80 25 | protocol = "HTTP" 26 | } 27 | 28 | resource "oci_load_balancer_backend_set" "http_backend_set" { 29 | health_checker { 30 | protocol = "HTTP" 31 | port = 80 32 | url_path = "/" 33 | return_code = 200 34 | } 35 | 36 | load_balancer_id = oci_load_balancer_load_balancer.load_balancer_l7.id 37 | name = "http_backend_set" 38 | policy = "ROUND_ROBIN" 39 | } 40 | 41 | resource "oci_load_balancer_backend" "http_backend" { 42 | count = var.instance_pool_size 43 | backendset_name = oci_load_balancer_backend_set.http_backend_set.name 44 | ip_address = data.oci_core_instance.ubuntu_instance_pool_instances_ips[count.index].private_ip 45 | load_balancer_id = oci_load_balancer_load_balancer.load_balancer_l7.id 46 | port = 80 47 | } -------------------------------------------------------------------------------- /load-balancer/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /load-balancer/nsg.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_network_security_group" "public_lb_nsg" { 2 | compartment_id = var.compartment_ocid 3 | vcn_id = var.vcn_id 4 | display_name = "Public LB nsg" 5 | 6 | freeform_tags = local.tags 7 | } 8 | 9 | resource "oci_core_network_security_group_security_rule" "allow_http_from_all" { 10 | network_security_group_id = oci_core_network_security_group.public_lb_nsg.id 11 | direction = "INGRESS" 12 | protocol = 6 # tcp 13 | 14 | description = "Allow HTTP from all" 15 | 16 | source = "0.0.0.0/0" 17 | source_type = "CIDR_BLOCK" 18 | stateless = false 19 | 20 | tcp_options { 21 | destination_port_range { 22 | max = 80 23 | min = 80 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /load-balancer/output.tf: -------------------------------------------------------------------------------- 1 | output "lb_ip" { 2 | value = oci_load_balancer_load_balancer.load_balancer_l7.ip_addresses 3 | } -------------------------------------------------------------------------------- /load-balancer/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /load-balancer/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "environment" { 10 | type = string 11 | } 12 | 13 | variable "instance_pool_id" { 14 | type = string 15 | } 16 | 17 | variable "is_private" { 18 | type = bool 19 | default = false 20 | } 21 | 22 | variable "lb_shape" { 23 | type = string 24 | default = "flexible" 25 | } 26 | 27 | variable "vcn_id" { 28 | type = string 29 | } 30 | 31 | variable "public_subnet_id" { 32 | type = string 33 | } 34 | 35 | variable "private_subnet_id" { 36 | type = string 37 | } 38 | 39 | variable "instance_pool_size" { 40 | type = number 41 | default = 2 42 | } -------------------------------------------------------------------------------- /nat-instance/README.md: -------------------------------------------------------------------------------- 1 | # NAT instance 2 | 3 | This module will deploy a NAT instance. If you use a private subnet with an always free account you will need a nat instance to give internet access to the private subnet. With the always free account you can't use/deploy a NAT gateway. 4 | 5 | Also this module will setup a new route table and will attach this new route to the private subnet. 6 | 7 | ### Requirements 8 | 9 | * One vcn with a public or private subnet (simple-vcn or private-vcn module) 10 | 11 | ### Module variables 12 | 13 | | Var | Required | Desc | 14 | | ------- | ------- | ----------- | 15 | | `region` | `yes` | set the correct OCI region based on your needs | 16 | | `availability_domain` | `yes` | Set the correct availability domain. See [how](../README.md#how-to-find-the-availability-doamin-name) to find the availability domain| 17 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 18 | | `vcn_id` | `yes` | The VCN OCID | 19 | | `private_subnet_id` | `yes` | Private subnet OCID | 20 | | `public_subnet_id` | `yes` | Public subnet OCID | 21 | | `default_fault_domain` | `no` | Fault domain where the instance will be deployed. Default: FAULT-DOMAIN-1 | 22 | | `PATH_TO_PUBLIC_KEY` | `no` | Path to your public ssh key (Default: "~/.ssh/id_rsa.pub) | 23 | | `os_image_id` | `no` | OS image OCID. Default: ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q - Canonical-Ubuntu-20.04-aarch64-2022.01.18-0 | 24 | | `setup_bastion` | `no` | Bool variable. Setup the nat instance as bastion host. Default: true | 25 | | `bastion_user` | `no` | Bastion username. Default: bastion | 26 | | `bastion_group` | `no` | Bastion group. Default: bastion | 27 | | `ssh_keys_path` | `no` | List of ssh keys allowed to connect to the nat instance as bastion user. Default: ["~/.ssh/id_rsa.pub"] | 28 | 29 | 30 | ### Output 31 | 32 | The module will output: 33 | 34 | * nat_instance_id, NAT instance OCID 35 | * nat_instance_public_ip, NAT instance public ip -------------------------------------------------------------------------------- /nat-instance/data.tf: -------------------------------------------------------------------------------- 1 | data "cloudinit_config" "nat_instance_init" { 2 | gzip = true 3 | base64_encode = true 4 | 5 | part { 6 | content_type = "text/x-shellscript" 7 | content = templatefile("${path.module}/files/setup_nat.sh", {}) 8 | } 9 | 10 | part { 11 | content_type = "text/x-shellscript" 12 | content = templatefile("${path.module}/files/setup_bastion.sh", { 13 | ssh_keys = local.ssh_keys, 14 | setup_bastion = var.setup_bastion, 15 | bastion_user = var.bastion_user, 16 | bastion_group = var.bastion_group 17 | }) 18 | } 19 | } 20 | 21 | data "oci_core_vnic_attachments" "nat_instance_vnics" { 22 | depends_on = [ 23 | oci_core_instance.nat_instance 24 | ] 25 | 26 | compartment_id = var.compartment_ocid 27 | availability_domain = var.availability_domain 28 | instance_id = oci_core_instance.nat_instance.id 29 | } 30 | 31 | data "oci_core_private_ips" "nat_instance_private_ips_by_nic" { 32 | depends_on = [ 33 | oci_core_instance.nat_instance 34 | ] 35 | ip_address = oci_core_instance.nat_instance.private_ip 36 | subnet_id = var.public_subnet_id 37 | vnic_id = data.oci_core_vnic_attachments.nat_instance_vnics.vnic_id 38 | } -------------------------------------------------------------------------------- /nat-instance/files/setup_bastion.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | %{ if setup_bastion } 4 | 5 | 6 | groupadd ${bastion_group} 7 | useradd -d /home/${bastion_user} -r -g ${bastion_group} ${bastion_user} 8 | mkdir -p /home/${bastion_user}/.ssh 9 | touch /home/${bastion_user}/.ssh/authorized_keys 10 | %{ for ssh_key in ssh_keys } 11 | echo "${ssh_key}" >> /home/${bastion_user}/.ssh/authorized_keys 12 | %{ endfor } 13 | chown -R ${bastion_group}:${bastion_user} /home/${bastion_user}/ 14 | chmod 400 /home/${bastion_user}/.ssh/authorized_keys 15 | 16 | cat <> /etc/ssh/sshd_config 17 | Match Group ${bastion_group} 18 | AllowAgentForwarding no 19 | AllowTcpForwarding yes 20 | X11Forwarding no 21 | PermitTunnel no 22 | GatewayPorts no 23 | ForceCommand echo 'This account can only be used for ProxyJump (ssh -J)' 24 | EOD 25 | 26 | systemctl restart sshd.service 27 | 28 | %{ endif } -------------------------------------------------------------------------------- /nat-instance/files/setup_nat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update 4 | apt install -y firewalld 5 | 6 | # Firewall rules 7 | default_iface=$(ip route get 8.8.8.8 | grep -Po '(?<=(dev ))(\S+)') 8 | firewall-offline-cmd --direct --add-rule ipv4 nat POSTROUTING 0 -o $default_iface -j MASQUERADE 9 | firewall-offline-cmd --direct --add-rule ipv4 filter FORWARD 0 -i $default_iface -j ACCEPT 10 | /bin/systemctl restart firewalld 11 | 12 | # sysctl conf 13 | echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/98-ip-forward.conf 14 | sysctl -p /etc/sysctl.d/98-ip-forward.conf -------------------------------------------------------------------------------- /nat-instance/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | 7 | ssh_keys = [for ssh_key in var.ssh_keys_path : file(ssh_key)] 8 | } -------------------------------------------------------------------------------- /nat-instance/nat_instance.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_instance" "nat_instance" { 2 | agent_config { 3 | is_management_disabled = "false" 4 | is_monitoring_disabled = "false" 5 | 6 | plugins_config { 7 | desired_state = "DISABLED" 8 | name = "Vulnerability Scanning" 9 | } 10 | 11 | plugins_config { 12 | desired_state = "ENABLED" 13 | name = "Compute Instance Monitoring" 14 | } 15 | 16 | plugins_config { 17 | desired_state = "DISABLED" 18 | name = "Bastion" 19 | } 20 | } 21 | 22 | availability_config { 23 | recovery_action = "RESTORE_INSTANCE" 24 | } 25 | 26 | availability_domain = var.availability_domain 27 | compartment_id = var.compartment_ocid 28 | fault_domain = var.default_fault_domain 29 | 30 | create_vnic_details { 31 | assign_private_dns_record = true 32 | assign_public_ip = true 33 | subnet_id = var.public_subnet_id 34 | skip_source_dest_check = true 35 | } 36 | 37 | display_name = "NATINSTANCE" 38 | 39 | instance_options { 40 | are_legacy_imds_endpoints_disabled = false 41 | } 42 | 43 | is_pv_encryption_in_transit_enabled = true 44 | 45 | metadata = { 46 | "ssh_authorized_keys" = file(var.PATH_TO_PUBLIC_KEY) 47 | "user_data" = data.cloudinit_config.nat_instance_init.rendered 48 | } 49 | 50 | shape = "VM.Standard.A1.Flex" 51 | shape_config { 52 | memory_in_gbs = "6" 53 | ocpus = "1" 54 | } 55 | 56 | source_details { 57 | source_id = var.os_image_id 58 | source_type = "image" 59 | } 60 | 61 | freeform_tags = local.tags 62 | } -------------------------------------------------------------------------------- /nat-instance/output.tf: -------------------------------------------------------------------------------- 1 | output "nat_instance_id" { 2 | value = oci_core_instance.nat_instance.id 3 | } 4 | 5 | output "nat_instance_public_ip" { 6 | value = oci_core_instance.nat_instance.public_ip 7 | } -------------------------------------------------------------------------------- /nat-instance/route_table.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_route_table" "nat_instance_route_table" { 2 | 3 | depends_on = [ 4 | oci_core_instance.nat_instance 5 | ] 6 | 7 | compartment_id = var.compartment_ocid 8 | vcn_id = var.vcn_id 9 | display_name = "NAT instance route table" 10 | 11 | route_rules { 12 | network_entity_id = data.oci_core_private_ips.nat_instance_private_ips_by_nic.private_ips[0].id 13 | 14 | description = "Route internet traffic via nat instance" 15 | destination = "0.0.0.0/0" 16 | destination_type = "CIDR_BLOCK" 17 | } 18 | } 19 | 20 | resource "oci_core_route_table_attachment" "attach_route_table" { 21 | subnet_id = var.private_subnet_id 22 | route_table_id = oci_core_route_table.nat_instance_route_table.id 23 | } -------------------------------------------------------------------------------- /nat-instance/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /nat-instance/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "availability_domain" { 10 | 11 | } 12 | 13 | variable "environment" { 14 | type = string 15 | } 16 | 17 | variable "PATH_TO_PUBLIC_KEY" { 18 | type = string 19 | default = "~/.ssh/id_rsa.pub" 20 | description = "Path to your public key" 21 | } 22 | 23 | variable "setup_bastion" { 24 | type = bool 25 | default = true 26 | } 27 | 28 | variable "bastion_user" { 29 | type = string 30 | default = "bastion" 31 | } 32 | 33 | variable "bastion_group" { 34 | type = string 35 | default = "bastion" 36 | } 37 | 38 | variable "ssh_keys_path" { 39 | type = list(any) 40 | default = ["~/.ssh/id_rsa.pub"] 41 | } 42 | 43 | variable "default_fault_domain" { 44 | default = "FAULT-DOMAIN-1" 45 | } 46 | 47 | variable "fault_domains" { 48 | type = list(any) 49 | default = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"] 50 | } 51 | 52 | variable "vcn_id" { 53 | type = string 54 | } 55 | 56 | variable "private_subnet_id" { 57 | type = string 58 | } 59 | 60 | variable "public_subnet_id" { 61 | type = string 62 | } 63 | 64 | variable "os_image_id" { 65 | type = string 66 | default = "ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q" # Canonical-Ubuntu-20.04-aarch64-2022.01.18-0 67 | } -------------------------------------------------------------------------------- /network-load-balancer/README.md: -------------------------------------------------------------------------------- 1 | # Network load balancer (Layer 4) 2 | 3 | This module will deploy a Network Load Balancer (L4). The LB can be public or private (*is_private* variable). The LB will be attached to the instances in a instance pool (*instance_pool_id* variable). 4 | 5 | ### Requirements 6 | 7 | * One vcn with a public or private subnet (simple-vcn or private-vcn module) 8 | 9 | ### Module variables 10 | 11 | | Var | Required | Desc | 12 | | ------- | ------- | ----------- | 13 | | `region` | `yes` | set the correct OCI region based on your needs | 14 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 15 | | `vcn_id` | `yes` | The VCN OCID | 16 | | `private_subnet_id` | `yes` | Private subnet OCID | 17 | | `public_subnet_id` | `yes` | Public subnet OCID | 18 | | `instance_pool_size` | `yes` | Instance pool size | 19 | | `instance_pool_id` | `yes` | Instance pool ocid OCID | 20 | | `is_private` | `no` | Bool value. If true the LB will be a private LB (no public ip) Default: true | 21 | 22 | ### Output 23 | 24 | lb_ip, LB public or private ip address -------------------------------------------------------------------------------- /network-load-balancer/data.tf: -------------------------------------------------------------------------------- 1 | data "oci_core_instance_pool_instances" "ubuntu_instance_pool_instances" { 2 | compartment_id = var.compartment_ocid 3 | instance_pool_id = var.instance_pool_id 4 | } 5 | 6 | data "oci_core_instance" "ubuntu_instance_pool_instances_ips" { 7 | count = var.instance_pool_size 8 | instance_id = data.oci_core_instance_pool_instances.ubuntu_instance_pool_instances.instances[count.index].id 9 | } -------------------------------------------------------------------------------- /network-load-balancer/lb.tf: -------------------------------------------------------------------------------- 1 | resource "oci_network_load_balancer_network_load_balancer" "load_balancer_l4" { 2 | compartment_id = var.compartment_ocid 3 | display_name = "Network LB Layer 4" 4 | subnet_id = var.private_subnet_id 5 | 6 | is_private = var.is_private 7 | is_preserve_source_destination = false 8 | 9 | freeform_tags = local.tags 10 | } 11 | 12 | resource "oci_network_load_balancer_listener" "http_listener_l4" { 13 | default_backend_set_name = oci_network_load_balancer_backend_set.http_backend_set_l4.name 14 | name = "LB test listener" 15 | network_load_balancer_id = oci_network_load_balancer_network_load_balancer.load_balancer_l4.id 16 | port = 80 17 | protocol = "TCP" 18 | } 19 | 20 | resource "oci_network_load_balancer_backend_set" "http_backend_set_l4" { 21 | health_checker { 22 | protocol = "TCP" 23 | port = 80 24 | } 25 | 26 | name = "Backend set test" 27 | network_load_balancer_id = oci_network_load_balancer_network_load_balancer.load_balancer_l4.id 28 | policy = "FIVE_TUPLE" 29 | is_preserve_source = true 30 | } 31 | 32 | resource "oci_network_load_balancer_backend" "http_backend_l4" { 33 | count = var.instance_pool_size 34 | backend_set_name = oci_network_load_balancer_backend_set.http_backend_set_l4.name 35 | network_load_balancer_id = oci_network_load_balancer_network_load_balancer.load_balancer_l4.id 36 | port = 80 37 | 38 | target_id = data.oci_core_instance_pool_instances.ubuntu_instance_pool_instances.instances[count.index].id 39 | } -------------------------------------------------------------------------------- /network-load-balancer/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /network-load-balancer/output.tf: -------------------------------------------------------------------------------- 1 | output "lb_ip" { 2 | value = oci_network_load_balancer_network_load_balancer.load_balancer_l4.ip_addresses 3 | } -------------------------------------------------------------------------------- /network-load-balancer/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /network-load-balancer/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "environment" { 10 | type = string 11 | } 12 | 13 | variable "instance_pool_id" { 14 | type = string 15 | } 16 | 17 | variable "is_private" { 18 | type = bool 19 | default = true 20 | } 21 | 22 | variable "vcn_id" { 23 | type = string 24 | } 25 | 26 | variable "public_subnet_id" { 27 | type = string 28 | } 29 | 30 | variable "private_subnet_id" { 31 | type = string 32 | } 33 | 34 | variable "instance_pool_size" { 35 | type = number 36 | default = 2 37 | } -------------------------------------------------------------------------------- /private-vcn/README.md: -------------------------------------------------------------------------------- 1 | # VCN with private and public subnet 2 | 3 | This example will deploy a one VCN with one public subnet ad one private subnet. Also this modules deploy a security list with the following rueles: 4 | 5 | * egress, all traffic allowed 6 | * ingress, traffica allowed on port 22 only from *my_public_ip_cidr* 7 | 8 | ### Requirements 9 | 10 | No Requirement 11 | 12 | ### Module variables 13 | 14 | | Var | Required | Desc | 15 | | ------- | ------- | ----------- | 16 | | `region` | `yes` | set the correct OCI region based on your needs | 17 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 18 | | `my_public_ip_cidr` | `yes` | A public ip CIDR allowed to reach the OCI resources | 19 | | `environment` | `yes` | Current work environment (Example: staging/dev/prod). This value is used for tag all the deployed resources | 20 | | `oci_core_vcn_dns_label` | `no` | VCN DNS label. Default: defaultvcn | 21 | | `oci_core_subnet_dns_label10` | `no` | First subnet DNS label. Default: publicsubnet10 | 22 | | `oci_core_subnet_dns_label11` | `no` | Second subnet DNS label. Default: privatesubnet11 | 23 | | `oci_core_vcn_cidr` | `no` | VCN CIDR. Default: 10.0.0.0/16 | 24 | | `oci_core_subnet_cidr10` | `no` | First subnet CIDR. Default: 10.0.0.0/24 | 25 | | `oci_core_subnet_cidr11` | `no` | Second subnet CIDR. Default: 10.0.1.0/24 | 26 | 27 | ### Output 28 | 29 | The module will output: 30 | 31 | * vcn_id, the VCN OCID 32 | * public_subnet_id, the public subnet OCID 33 | * private_subnet_id, the private subnet OCID 34 | * security_list_id, the security list OCID 35 | * public_subnet_cidr, the public subnet CIDR -------------------------------------------------------------------------------- /private-vcn/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /private-vcn/network.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_vcn" "default_oci_core_vcn" { 2 | cidr_block = var.oci_core_vcn_cidr 3 | compartment_id = var.compartment_ocid 4 | display_name = "Default OCI core vcn" 5 | dns_label = var.oci_core_vcn_dns_label 6 | freeform_tags = local.tags 7 | } 8 | 9 | resource "oci_core_subnet" "default_oci_core_subnet10" { 10 | cidr_block = var.oci_core_subnet_cidr10 11 | compartment_id = var.compartment_ocid 12 | display_name = "${var.oci_core_subnet_cidr10} (default) PUBLIC OCI core subnet" 13 | dns_label = var.oci_core_subnet_dns_label10 14 | route_table_id = oci_core_vcn.default_oci_core_vcn.default_route_table_id 15 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 16 | security_list_ids = [oci_core_default_security_list.default_security_list.id] 17 | freeform_tags = local.tags 18 | } 19 | 20 | resource "oci_core_subnet" "oci_core_subnet11" { 21 | cidr_block = var.oci_core_subnet_cidr11 22 | compartment_id = var.compartment_ocid 23 | display_name = "${var.oci_core_subnet_cidr11} PRIVATE OCI core subnet" 24 | dns_label = var.oci_core_subnet_dns_label11 25 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 26 | prohibit_public_ip_on_vnic = true 27 | prohibit_internet_ingress = true 28 | security_list_ids = [oci_core_default_security_list.default_security_list.id] 29 | freeform_tags = local.tags 30 | } 31 | 32 | resource "oci_core_internet_gateway" "default_oci_core_internet_gateway" { 33 | compartment_id = var.compartment_ocid 34 | display_name = "Internet Gateway Default OCI core vcn" 35 | enabled = "true" 36 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 37 | freeform_tags = local.tags 38 | } 39 | 40 | resource "oci_core_default_route_table" "default_oci_core_default_route_table" { 41 | route_rules { 42 | destination = "0.0.0.0/0" 43 | destination_type = "CIDR_BLOCK" 44 | network_entity_id = oci_core_internet_gateway.default_oci_core_internet_gateway.id 45 | } 46 | manage_default_resource_id = oci_core_vcn.default_oci_core_vcn.default_route_table_id 47 | } -------------------------------------------------------------------------------- /private-vcn/output.tf: -------------------------------------------------------------------------------- 1 | output "vcn_id" { 2 | value = oci_core_vcn.default_oci_core_vcn.id 3 | } 4 | 5 | output "public_subnet_id" { 6 | value = oci_core_subnet.default_oci_core_subnet10.id 7 | } 8 | 9 | output "private_subnet_id" { 10 | value = oci_core_subnet.oci_core_subnet11.id 11 | } 12 | 13 | output "security_list_id" { 14 | value = oci_core_default_security_list.default_security_list.id 15 | } 16 | 17 | output "public_subnet_cidr" { 18 | value = oci_core_subnet.default_oci_core_subnet10.cidr_block 19 | } -------------------------------------------------------------------------------- /private-vcn/security.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_default_security_list" "default_security_list" { 2 | compartment_id = var.compartment_ocid 3 | manage_default_resource_id = oci_core_vcn.default_oci_core_vcn.default_security_list_id 4 | 5 | display_name = "Default security list" 6 | egress_security_rules { 7 | destination = "0.0.0.0/0" 8 | protocol = "all" 9 | } 10 | 11 | ingress_security_rules { 12 | protocol = 1 # icmp 13 | source = var.my_public_ip_cidr 14 | 15 | description = "Allow icmp from ${var.my_public_ip_cidr}" 16 | 17 | } 18 | 19 | ingress_security_rules { 20 | protocol = 6 # tcp 21 | source = var.my_public_ip_cidr 22 | 23 | description = "Allow SSH from ${var.my_public_ip_cidr}" 24 | 25 | tcp_options { 26 | min = 22 27 | max = 22 28 | } 29 | } 30 | 31 | ingress_security_rules { 32 | protocol = "all" 33 | source = var.oci_core_vcn_cidr 34 | 35 | description = "Allow all from vcn subnet" 36 | } 37 | 38 | freeform_tags = local.tags 39 | } -------------------------------------------------------------------------------- /private-vcn/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /private-vcn/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "fault_domains" { 10 | type = list(any) 11 | default = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"] 12 | } 13 | 14 | variable "oci_core_vcn_cidr" { 15 | default = "10.0.0.0/16" 16 | } 17 | 18 | variable "oci_core_subnet_cidr10" { 19 | default = "10.0.0.0/24" 20 | } 21 | 22 | variable "oci_core_subnet_cidr11" { 23 | default = "10.0.1.0/24" 24 | } 25 | 26 | variable "oci_core_subnet_dns_label10" { 27 | default = "publicsubnet10" 28 | } 29 | 30 | variable "oci_core_vcn_dns_label" { 31 | default = "defaultvcn" 32 | } 33 | 34 | variable "oci_core_subnet_dns_label11" { 35 | default = "privatesubnet11" 36 | } 37 | 38 | variable "my_public_ip_cidr" { 39 | type = string 40 | description = "My public ip CIDR" 41 | } 42 | 43 | variable "environment" { 44 | type = string 45 | } -------------------------------------------------------------------------------- /simple-instance/README.md: -------------------------------------------------------------------------------- 1 | # Simple compute instance 2 | 3 | This module will deploy a single Oracle compute instance, in a private or in a public subnet. 4 | 5 | If you choose to publish this compute instance in a private subnet, you need a NAT instance (refer to nat-instance module). The nat instance can be used also as bation host to reach the private instance, or if you prefer you can deploy a dedicated bastion host (refer to bastion-host module). 6 | 7 | ### Requirements 8 | 9 | * One vcn with a public or private subnet (simple-vcn or private-vcn module) 10 | * One nat instance if the instance *is_private* (nat-instance module) 11 | 12 | ### Module variables 13 | 14 | | Var | Required | Desc | 15 | | ------- | ------- | ----------- | 16 | | `region` | `yes` | set the correct OCI region based on your needs | 17 | | `availability_domain` | `yes` | Set the correct availability domain. See [how](../README.md#how-to-find-the-availability-doamin-name) to find the availability domain| 18 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 19 | | `vcn_id` | `yes` | The VCN OCID | 20 | | `private_subnet_id` | `yes` | Private subnet OCID | 21 | | `public_subnet_id` | `yes` | Public subnet OCID | 22 | | `environment` | `yes` | Current work environment (Example: staging/dev/prod). This value is used for tag all the deployed resources | 23 | | `default_fault_domain` | `no` | Fault domain where the instance will be deployed. Default: FAULT-DOMAIN-1 | 24 | | `is_private` | `no` | Bool value. If true the instance will be deployed in a private subnet. Default: false | 25 | | `os_image_id` | `no` | OS image OCID. Default: ocid1.image.oc1.eu-zurich-1.aaaaaaaag2uyozo7266bmg26j5ixvi42jhaujso2pddpsigtib6vfnqy5f6q - Canonical-Ubuntu-20.04-aarch64-2022.01.18-0 | 26 | 27 | ### Output 28 | 29 | The module will show the instane ip: public or private (based on the value of the variable *is_private*) -------------------------------------------------------------------------------- /simple-instance/compute.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_instance" "ubuntu_oci_instance" { 2 | agent_config { 3 | is_management_disabled = "false" 4 | is_monitoring_disabled = "false" 5 | 6 | plugins_config { 7 | desired_state = "DISABLED" 8 | name = "Vulnerability Scanning" 9 | } 10 | 11 | plugins_config { 12 | desired_state = "ENABLED" 13 | name = "Compute Instance Monitoring" 14 | } 15 | 16 | plugins_config { 17 | desired_state = "DISABLED" 18 | name = "Bastion" 19 | } 20 | } 21 | 22 | availability_config { 23 | recovery_action = "RESTORE_INSTANCE" 24 | } 25 | 26 | availability_domain = var.availability_domain 27 | compartment_id = var.compartment_ocid 28 | fault_domain = var.default_fault_domain 29 | 30 | create_vnic_details { 31 | assign_private_dns_record = true 32 | assign_public_ip = var.is_private == true ? false : true 33 | subnet_id = var.is_private == true ? var.private_subnet_id : var.public_subnet_id 34 | } 35 | 36 | display_name = "Ubuntu Instance" 37 | 38 | instance_options { 39 | are_legacy_imds_endpoints_disabled = false 40 | } 41 | 42 | is_pv_encryption_in_transit_enabled = true 43 | 44 | metadata = { 45 | "ssh_authorized_keys" = file(var.PATH_TO_PUBLIC_KEY) 46 | "user_data" = data.cloudinit_config.ubuntu_init.rendered 47 | } 48 | 49 | shape = var.shape 50 | shape_config { 51 | memory_in_gbs = var.memory_in_gbs 52 | ocpus = var.ocpus 53 | } 54 | 55 | source_details { 56 | source_id = var.os_image_id 57 | source_type = "image" 58 | } 59 | 60 | freeform_tags = local.tags 61 | } -------------------------------------------------------------------------------- /simple-instance/data.tf: -------------------------------------------------------------------------------- 1 | data "cloudinit_config" "ubuntu_init" { 2 | gzip = true 3 | base64_encode = true 4 | 5 | part { 6 | content_type = "text/x-shellscript" 7 | content = templatefile("${path.module}/files/oci-ubuntu-install.sh", {}) 8 | } 9 | } -------------------------------------------------------------------------------- /simple-instance/files/oci-ubuntu-install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | apt-get update 4 | apt-get -y upgrade 5 | apt-get -y install nginx 6 | 7 | systemctl enable nginx 8 | systemctl start nginx 9 | 10 | hostname=$(hostname) 11 | 12 | cat < /var/www/html/index.nginx-debian.html 13 | 14 | 15 | 16 | Welcome to nginx! 17 | 24 | 25 | 26 |

Welcome to nginx!

27 |

If you see this page, the nginx web server is successfully installed and 28 | working. Further configuration is required.

29 | 30 |

For online documentation and support please refer to 31 | nginx.org.
32 | Commercial support is available at 33 | nginx.com.

34 | 35 |

Thank you for using nginx.

36 |

Hello from: $hostname

37 | 38 | 39 | EOF 40 | 41 | # Disable firewall 42 | /usr/sbin/netfilter-persistent stop 43 | /usr/sbin/netfilter-persistent flush 44 | 45 | systemctl stop netfilter-persistent.service 46 | systemctl disable netfilter-persistent.service -------------------------------------------------------------------------------- /simple-instance/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /simple-instance/output.tf: -------------------------------------------------------------------------------- 1 | output "instance_ip" { 2 | value = var.is_private == true ? oci_core_instance.ubuntu_oci_instance.private_ip : oci_core_instance.ubuntu_oci_instance.public_ip 3 | } -------------------------------------------------------------------------------- /simple-instance/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /simple-instance/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "availability_domain" { 10 | 11 | } 12 | 13 | variable "PATH_TO_PUBLIC_KEY" { 14 | type = string 15 | default = "~/.ssh/id_rsa.pub" 16 | description = "Path to your public key" 17 | } 18 | 19 | variable "environment" { 20 | type = string 21 | } 22 | 23 | variable "is_private" { 24 | type = bool 25 | default = false 26 | } 27 | 28 | variable "public_subnet_id" { 29 | type = string 30 | } 31 | 32 | variable "private_subnet_id" { 33 | type = string 34 | } 35 | 36 | variable "default_fault_domain" { 37 | default = "FAULT-DOMAIN-1" 38 | } 39 | 40 | variable "os_image_id" { 41 | default = "ocid1.image.oc1.eu-zurich-1.aaaaaaaabt5i2qa7sdt65orrb66anzyljybm3furr2q7ykxodt5zmfxqbyzq" # Canonical-Ubuntu-22.04-aarch64-2023.07.20-0 42 | } 43 | 44 | variable "shape" { 45 | default = "VM.Standard.A1.Flex" # VM.Standard.E2.1.Micro 46 | } 47 | 48 | variable "memory_in_gbs" { 49 | default = "6" 50 | } 51 | 52 | variable "ocpus" { 53 | default = "1" 54 | } -------------------------------------------------------------------------------- /simple-vcn/README.md: -------------------------------------------------------------------------------- 1 | # VCN with two public subnets 2 | 3 | This module will deploy a one VCN with two public subnets. Also this modules deploy a security list with the following rueles: 4 | 5 | * egress, all traffic allowed 6 | * ingress, traffica allowed on port 22 only from *my_public_ip_cidr* 7 | 8 | ### Requirements 9 | 10 | No Requirement 11 | 12 | ### Module variables 13 | 14 | | Var | Required | Desc | 15 | | ------- | ------- | ----------- | 16 | | `region` | `yes` | set the correct OCI region based on your needs | 17 | | `compartment_ocid` | `yes` | Set the correct compartment ocid. See [how](../README.md#oracle-provider-setup) to find the compartment ocid | 18 | | `my_public_ip_cidr` | `yes` | A public ip CIDR allowed to reach the OCI resources | 19 | | `environment` | `yes` | Current work environment (Example: staging/dev/prod). This value is used for tag all the deployed resources | 20 | | `oci_core_vcn_dns_label` | `no` | VCN DNS label. Default: defaultvcn | 21 | | `oci_core_subnet_dns_label10` | `no` | First subnet DNS label. Default: publicsubnet10 | 22 | | `oci_core_subnet_dns_label11` | `no` | Second subnet DNS label. Default: publicsubnet11 | 23 | | `oci_core_vcn_cidr` | `no` | VCN CIDR. Default: 10.0.0.0/16 | 24 | | `oci_core_subnet_cidr10` | `no` | First subnet CIDR. Default: 10.0.0.0/24 | 25 | | `oci_core_subnet_cidr11` | `no` | Second subnet CIDR. Default: 10.0.1.0/24 | 26 | 27 | ### Output 28 | 29 | The module will output: 30 | 31 | * vcn_id, the VCN OCID 32 | * public_subnet_id, the public subnet OCID 33 | * secondary_public_subnet_id, the secondary public subnet OCID 34 | * security_list_id, the security list OCID 35 | * public_subnet_cidr, the public subnet CIDR -------------------------------------------------------------------------------- /simple-vcn/local.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | tags = { 3 | "oracle-tutorial" = "terraform" 4 | "environment" = "${var.environment}" 5 | } 6 | } -------------------------------------------------------------------------------- /simple-vcn/network.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_vcn" "default_oci_core_vcn" { 2 | cidr_block = var.oci_core_vcn_cidr 3 | compartment_id = var.compartment_ocid 4 | display_name = "Default OCI core vcn" 5 | dns_label = var.oci_core_vcn_dns_label 6 | freeform_tags = local.tags 7 | } 8 | 9 | resource "oci_core_subnet" "default_oci_core_subnet10" { 10 | cidr_block = var.oci_core_subnet_cidr10 11 | compartment_id = var.compartment_ocid 12 | display_name = "${var.oci_core_subnet_cidr10} (default) PUBLIC OCI core subnet" 13 | dns_label = var.oci_core_subnet_dns_label10 14 | route_table_id = oci_core_vcn.default_oci_core_vcn.default_route_table_id 15 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 16 | security_list_ids = [oci_core_default_security_list.default_security_list.id] 17 | freeform_tags = local.tags 18 | } 19 | 20 | resource "oci_core_subnet" "oci_core_subnet11" { 21 | cidr_block = var.oci_core_subnet_cidr11 22 | compartment_id = var.compartment_ocid 23 | display_name = "${var.oci_core_subnet_cidr11} PUBLIC OCI core subnet" 24 | dns_label = var.oci_core_subnet_dns_label11 25 | route_table_id = oci_core_vcn.default_oci_core_vcn.default_route_table_id 26 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 27 | security_list_ids = [oci_core_default_security_list.default_security_list.id] 28 | freeform_tags = local.tags 29 | } 30 | 31 | resource "oci_core_internet_gateway" "default_oci_core_internet_gateway" { 32 | compartment_id = var.compartment_ocid 33 | display_name = "Internet Gateway Default OCI core vcn" 34 | enabled = "true" 35 | vcn_id = oci_core_vcn.default_oci_core_vcn.id 36 | freeform_tags = local.tags 37 | } 38 | 39 | resource "oci_core_default_route_table" "default_oci_core_default_route_table" { 40 | route_rules { 41 | destination = "0.0.0.0/0" 42 | destination_type = "CIDR_BLOCK" 43 | network_entity_id = oci_core_internet_gateway.default_oci_core_internet_gateway.id 44 | } 45 | manage_default_resource_id = oci_core_vcn.default_oci_core_vcn.default_route_table_id 46 | } -------------------------------------------------------------------------------- /simple-vcn/output.tf: -------------------------------------------------------------------------------- 1 | output "vcn_id" { 2 | value = oci_core_vcn.default_oci_core_vcn.id 3 | } 4 | 5 | output "public_subnet_id" { 6 | value = oci_core_subnet.default_oci_core_subnet10.id 7 | } 8 | 9 | output "secondary_public_subnet_id" { 10 | value = oci_core_subnet.oci_core_subnet11.id 11 | } 12 | 13 | output "security_list_id" { 14 | value = oci_core_default_security_list.default_security_list.id 15 | } 16 | 17 | output "public_subnet_cidr" { 18 | value = oci_core_subnet.default_oci_core_subnet10.cidr_block 19 | } -------------------------------------------------------------------------------- /simple-vcn/security.tf: -------------------------------------------------------------------------------- 1 | resource "oci_core_default_security_list" "default_security_list" { 2 | compartment_id = var.compartment_ocid 3 | manage_default_resource_id = oci_core_vcn.default_oci_core_vcn.default_security_list_id 4 | 5 | display_name = "Default security list" 6 | egress_security_rules { 7 | destination = "0.0.0.0/0" 8 | protocol = "all" 9 | } 10 | 11 | ingress_security_rules { 12 | protocol = 1 # icmp 13 | source = var.my_public_ip_cidr 14 | 15 | description = "Allow icmp from ${var.my_public_ip_cidr}" 16 | 17 | } 18 | 19 | ingress_security_rules { 20 | protocol = 6 # tcp 21 | source = var.my_public_ip_cidr 22 | 23 | description = "Allow SSH from ${var.my_public_ip_cidr}" 24 | 25 | tcp_options { 26 | min = 22 27 | max = 22 28 | } 29 | } 30 | 31 | ingress_security_rules { 32 | protocol = "all" 33 | source = var.oci_core_vcn_cidr 34 | 35 | description = "Allow all from vcn subnet" 36 | } 37 | 38 | freeform_tags = local.tags 39 | } -------------------------------------------------------------------------------- /simple-vcn/terraform.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_providers { 3 | oci = { 4 | source = "oracle/oci" 5 | version = ">= 4.64.0" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /simple-vcn/vars.tf: -------------------------------------------------------------------------------- 1 | variable "compartment_ocid" { 2 | 3 | } 4 | 5 | variable "region" { 6 | 7 | } 8 | 9 | variable "fault_domains" { 10 | type = list(any) 11 | default = ["FAULT-DOMAIN-1", "FAULT-DOMAIN-2", "FAULT-DOMAIN-3"] 12 | } 13 | 14 | variable "oci_core_vcn_cidr" { 15 | default = "10.0.0.0/16" 16 | } 17 | 18 | variable "oci_core_subnet_cidr10" { 19 | default = "10.0.0.0/24" 20 | } 21 | 22 | variable "oci_core_subnet_cidr11" { 23 | default = "10.0.1.0/24" 24 | } 25 | 26 | variable "oci_core_vcn_dns_label" { 27 | default = "defaultvcn" 28 | } 29 | 30 | variable "oci_core_subnet_dns_label10" { 31 | default = "publicsubnet10" 32 | } 33 | 34 | variable "oci_core_subnet_dns_label11" { 35 | default = "publicsubnet11" 36 | } 37 | 38 | variable "my_public_ip_cidr" { 39 | type = string 40 | description = "My public ip CIDR" 41 | } 42 | 43 | variable "environment" { 44 | type = string 45 | } --------------------------------------------------------------------------------