From 8fb1d10565fb77f13529ffea354a55151bc002b6 Mon Sep 17 00:00:00 2001 From: scotttyso Date: Wed, 30 Jun 2021 18:18:43 -0400 Subject: [PATCH] initial commit --- .editorconfig | 30 ++ .gitignore | 1 + .pre-commit-config.yaml | 8 + LICENSE | 674 +++++++++++++++++++++++++++++++++++++ README.md | 152 +++++++++ app_hello/README.md | 42 +++ app_hello/main.tf | 44 +++ app_hello/provider.tf | 18 + app_hello/variables.tf | 28 ++ global_vars/README.md | 82 +++++ global_vars/variables.tf | 366 ++++++++++++++++++++ iks/README.md | 104 ++++++ iks/main.tf | 382 +++++++++++++++++++++ iks/outputs.tf | 94 ++++++ iks/provider.tf | 25 ++ iks/variables.tf | 270 +++++++++++++++ iwo/README.md | 42 +++ iwo/main.tf | 53 +++ iwo/provider.tf | 18 + iwo/variables.tf | 28 ++ kube/README.md | 46 +++ kube/main.tf | 37 ++ kube/outputs.tf | 9 + kube/provider.tf | 25 ++ kube/variables.tf | 40 +++ tfe/.gitignore | 6 + tfe/README.md | 291 ++++++++++++++++ tfe/agent_pool.tf | 15 + tfe/providers.tf | 20 ++ tfe/tfc_workspaces.tf | 66 ++++ tfe/variables.tf | 55 +++ tfe/ws_vars_app_hello.tf | 40 +++ tfe/ws_vars_global_vars.tf | 210 ++++++++++++ tfe/ws_vars_iks.tf | 494 +++++++++++++++++++++++++++ tfe/ws_vars_iwo.tf | 36 ++ tfe/ws_vars_kube.tf | 49 +++ 36 files changed, 3900 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 app_hello/README.md create mode 100644 app_hello/main.tf create mode 100644 app_hello/provider.tf create mode 100644 app_hello/variables.tf create mode 100644 global_vars/README.md create mode 100644 global_vars/variables.tf create mode 100644 iks/README.md create mode 100644 iks/main.tf create mode 100644 iks/outputs.tf create mode 100644 iks/provider.tf create mode 100644 iks/variables.tf create mode 100644 iwo/README.md create mode 100644 iwo/main.tf create mode 100644 iwo/provider.tf create mode 100644 iwo/variables.tf create mode 100644 kube/README.md create mode 100644 kube/main.tf create mode 100644 kube/outputs.tf create mode 100644 kube/provider.tf create mode 100644 kube/variables.tf create mode 100644 tfe/.gitignore create mode 100644 tfe/README.md create mode 100644 tfe/agent_pool.tf create mode 100644 tfe/providers.tf create mode 100644 tfe/tfc_workspaces.tf create mode 100644 tfe/variables.tf create mode 100644 tfe/ws_vars_app_hello.tf create mode 100644 tfe/ws_vars_global_vars.tf create mode 100644 tfe/ws_vars_iks.tf create mode 100644 tfe/ws_vars_iwo.tf create mode 100644 tfe/ws_vars_kube.tf diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ef952f5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +# EditorConfig is awesome: http://EditorConfig.org +# Uses editorconfig to maintain consistent coding styles + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true + +[*.{tf,tfvars,template}] +indent_size = 2 +indent_style = space + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +[Makefile] +tab_width = 2 +indent_style = tab + +[COMMIT_EDITMSG] +max_line_length = 0 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ + diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..eb82953 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +repos: +- repo: git://github.com/antonbabenko/pre-commit-terraform + rev: v1.45.0 + hooks: + - id: terraform_fmt + - id: terraform_docs + - id: terraform_tflint + - id: terraform_tfsec \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d126ec9 --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ +# Configuring IKS cluster with Cisco Intersight Service for HashiCorp Terraform on vSphere Infrastructure + +## Contents + +* Use Cases +* Pre-requisites and Guidelines +* Create TFCB Workspaces using the TFE Provider +* Execute Plans in Terraform Cloud Workspaces +* Provision IP Pools, Kubernetes Policies, and an IKS Cluster with TFCB +* Import the IKS Cluster kube_config into a TFCB Workspace +* Deploy IWO Performance Collector App using Helm +* Deploy the sample "Hello IKS" App using Helm +* Try with a Cisco DevNet Sandbox + +### Use Cases + +* As a Cloud Admin, Build Workspaces in TFCB to support Infrastructure as Code Provisioning. +* As a Cloud Admin, use TFCB to provision IP Pools, Kubernetes Policies, and an IKS Cluster on vSphere Infrastructure to be leveraged by DevOps Teams. +* As a Cloud Admin, use IST, ((Intersight Service for HashiCorp Terraform), to deploy IWO (Intersight Workload Optimizer) Collector to collect app and infrastructure insights. +* As an App Developer, use IST to deploy a sample "Hello IKS" Application. + +![alt text](https://github.com/prathjan/images/blob/main/iksnew.png?raw=true) + +### Pre-requisites and Guidelines + +1. Sign up for a user account on Intersight.com. You will need at least one Advantage Tier license as well as a Intersight Workload Optimizer license to complete this use case. Log in to intersight.com and generate API/Secret Keys. Both licensing requirements can utilize the available demo licensing if you don't have the subscription levels. + +2. Sign up for a TFCB (Terraform for Cloud Business) at . Log in and generate the User API Key. You will need this when you create the TF Cloud Target in Intersight. If not a paid version, you will need to enable the trial account. + +3. Clone this repository to your own VCS Repository for the VCS Integration with Terraform Cloud. + +4. Integrate your VCS Repository into the TFCB Orgnization following these instructions: . Be sure to copy the OAth Token which you will use later on for Workspace provisioning. + +5. You will need access to a vSphere infrastructure. You will use this to install the Intersight Assist Appliance and provision the Kubernetes (IKS) Cluster. + +6. You will log into your Intersight account and create the following targets. Please refer to Intersight docs for details on how to create these Targets: + + Intersight Assist - This will provide on-premise proxy communication services. i.e. vSphere and Kubernetes. + + vSphere Target - Requires Intersight Assist Appliance. + + TFC Cloud (This requires a Terraform for Cloud Business Account and at least 1 Advantage Tier License in Intersight) + + TFC Cloud Agent - After Claiming the TFCB Target, provising a Terraform Agent. Be sure to add the following Managed Hosts/Networks: + + network for vsphere host i.e. 198.18.0.0/24 + network for Kubernetes Pod IP Range, i.e 198.18.1.0/24 (CIDR Ranges are not required) + github-releases.githubusercontent.com + github.com + prathjan.github.io + +### Create TFCB Workspaces using the TFE Provider + +1. Follow the instructions in the "tfe" folder of this repository to provision the TFCB Workspaces. + +### Execute Plans in Terraform Cloud Workspaces + +1. Open the Workspace "{cluster_name}_global_vars" in TFCB and queue a plan manually. This will populate the global variables that will be used by the other TFCB workspaces. + +2. You will execute the Runs in the workspaces in this order: + + * {cluster_name}_iks - See section below on "Provision IKS Policies and IP Pools with TFCB" + + * {cluster_name}_kube - See section below on "Provision a IKS Cluster with TFCB" + + * {cluster_name}_iwo - See section below on "Deploy IWO collector using Helm" + + * {cluster_name}_app_hello - See section below on "Deploy a sample "Hello IKS" App using Helm" + +### Provision IP Pools, Kubernetes Policies, and an IKS Cluster with TFCB + +![alt text](https://github.com/prathjan/images/blob/main/prof.png?raw=true) + +### Get the Cluster kube_config + +Currently due to order of operations in Intersight you must use a seperate task after Cluster creation to download the kube_config. the {cluster_name}_kube Workspace will be used to accomplish this. + +Once you have confirmed in Intersight that the cluster has been fully provisioned run the plan in the {cluster_name}_kube workspace. + +Download the cluster kube_config from from the workspace and run a couple of kubectl commands to verify an operational cluster: + + kubectl get nodes + + kubectl get pods --all-namespaces + +### Deploy IWO Performance Collector App using Helm + +If you don't have Intersight Workload Optimizer licensing tied to your Intersight Instance you can skip this section. + +As a Cloud Admin it is imperative to be able to have insights into the infrastructure. The workspace "{cluster_name}_iwo" provides an example helm chart provisioning process to add the iwo collector pod to the deployed cluster. + +Open "{cluster_name}_iwo" and Queue a plan manually. + +Once successful, the collector is installed into your Kubernetes cluster and requires you to claim it as target in Intersight->Target. You will use the following steps to get the Device ID and Code: + +Download kube_config for the {cluster_name} from Intersight or your {cluster_name}_kube workspace. + +Execute: + + kubectl port-forward 9110 + +Execute this to get the Device ID: + + curl -s http://localhost:9110/DeviceIdentifiers + +Execute this to get the Claim Code: + + curl -s http://localhost:9110/SecurityTokens + +Once successful, open the Optimizer in Intersight and view insights for the App just deployed: + +Note: This can take approximately 30 minutes to begin to see the cluster in IWO. + +![alt text](https://github.com/prathjan/images/blob/main/insights.png?raw=true) + +### Deploy the sample "Hello IKS" App using Helm + +What use is a cluster without an Application? The workspace "{cluster_name}_app_hello" accounts for this. + +Open "{cluster_name}_app_hello" and Queue a plan manually. + +Once successful, access the app with the loadbalancer IP: + + kubectl get svc --all-namespaces + +or + + kubectl get ingress + +Open URL in a browser window : + +You should see this: + +![alt text](https://github.com/prathjan/images/blob/main/helloiks.png?raw=true) + +### De-provisioning + +There is a three step process to decomission the lab. + +1. Go into the IKS workspace and change the variable "action" from "Deploy" to "Delete" and Queue a Plan. Monitor in Intersight for the Completed deletion of the cluster deployment. Workspace > Variables > "action": edit. Then "Queue plan manually". + +2. Run a Destroy Infrastrucutre Plan on the {cluster_name}_iks workspace to delete the Kubernetes Policies from Intersight. Workspace > Settings > Destruction and Deletion > "Queue destroy plan". Wait for the Completion of the Destroy Apply. + +3. Back on your machine where you have downloaded the tfe folder and ran the plan to build the workspaces run the command: + + terraform destroy + +### Try with a Cisco DevNet Sandbox + +A sandbox covering a lot of the above concepts can be found here: + + diff --git a/app_hello/README.md b/app_hello/README.md new file mode 100644 index 0000000..4e0938f --- /dev/null +++ b/app_hello/README.md @@ -0,0 +1,42 @@ +# Kubernetes Applications - Hello Kubernetes + +## Use this module to deploy the Hello Kubernetes Application through the Intersight Assist Appliance + +Run the plan from the Terraform cloud workspace. + + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [helm](#provider\_helm) | n/a | +| [terraform](#provider\_terraform) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [helm_release.helloiksfrtfcb](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | +| [terraform_remote_state.global](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | +| [terraform_remote_state.kube](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [tfc\_organization](#input\_tfc\_organization) | Terraform Cloud Organization. | `string` | `"CiscoDevNet"` | no | +| [ws\_global\_vars](#input\_ws\_global\_vars) | Global Variables Workspace Name. The default value will be set to {cluster\_name}\_global\_vars by the tfe variable module. | `string` | `""` | no | +| [ws\_kube](#input\_ws\_kube) | Intersight Kubernetes Service (IKS) kube\_config Workspace Name. The default value will be set to {cluster\_name}\_kube by the tfe variable module. | `string` | `""` | no | + +## Outputs + +No outputs. + diff --git a/app_hello/main.tf b/app_hello/main.tf new file mode 100644 index 0000000..dca0f94 --- /dev/null +++ b/app_hello/main.tf @@ -0,0 +1,44 @@ +#__________________________________________________________ +# +# Get Outputs from the global_vars and kube Workspace(s) +#__________________________________________________________ + +data "terraform_remote_state" "global" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_global_vars + } + } +} + +data "terraform_remote_state" "kube" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_kube + } + } +} + +locals { + # IKS Cluster Name + cluster_name = yamldecode(data.terraform_remote_state.global.outputs.cluster_name) +} + +#_____________________________________________________________________ +# +# Deploy the Hello-Kubernetes Application Pod using the Helm Provider +#_____________________________________________________________________ + +resource "helm_release" "helloiksfrtfcb" { + name = "helloiksapp" + namespace = "default" + chart = "https://prathjan.github.io/helm-chart/helloiks-0.1.0.tgz" + set { + name = "MESSAGE" + value = "Hello Intersight Kubernetes Service from Terraform Cloud for Business!!" + } +} diff --git a/app_hello/provider.tf b/app_hello/provider.tf new file mode 100644 index 0000000..976855c --- /dev/null +++ b/app_hello/provider.tf @@ -0,0 +1,18 @@ +#_______________________________________________________________ +# +# Terraform Provider - Helm +# https://registry.terraform.io/providers/hashicorp/helm/latest +#_______________________________________________________________ + +provider "helm" { + kubernetes { + host = local.kube_config.clusters[0].cluster.server + client_certificate = base64decode(local.kube_config.users[0].user.client-certificate-data) + client_key = base64decode(local.kube_config.users[0].user.client-key-data) + cluster_ca_certificate = base64decode(local.kube_config.clusters[0].cluster.certificate-authority-data) + } +} + +locals { + kube_config = yamldecode(data.terraform_remote_state.kube.outputs.kube_config) +} diff --git a/app_hello/variables.tf b/app_hello/variables.tf new file mode 100644 index 0000000..a5fae52 --- /dev/null +++ b/app_hello/variables.tf @@ -0,0 +1,28 @@ +#__________________________________________________________ +# +# Terraform Cloud Organization +#__________________________________________________________ + +variable "tfc_organization" { + default = "CiscoDevNet" + description = "Terraform Cloud Organization." + type = string +} + + +#______________________________________________ +# +# Terraform Cloud global_vars Workspace +#______________________________________________ + +variable "ws_global_vars" { + default = "" + description = "Global Variables Workspace Name. The default value will be set to {cluster_name}_global_vars by the tfe variable module." + type = string +} + +variable "ws_kube" { + default = "" + description = "Intersight Kubernetes Service (IKS) kube_config Workspace Name. The default value will be set to {cluster_name}_kube by the tfe variable module." + type = string +} diff --git a/global_vars/README.md b/global_vars/README.md new file mode 100644 index 0000000..6b7cfc3 --- /dev/null +++ b/global_vars/README.md @@ -0,0 +1,82 @@ +# Global Variables Workspace + +## Use this module to create Global Variales consumed by the IKS workspaces + +Run the plan from the Terraform cloud workspace for the Given Workspace. + + +## Requirements + +No requirements. + +## Providers + +No providers. + +## Modules + +No modules. + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [addons\_list](#input\_addons\_list) | List of Add-ons for Intersight Kubernetes Service. Add-ons Options are {ccp-monitor\|kubernetes-dashboard}. | `list(string)` | `[]` | no | +| [cluster\_name](#input\_cluster\_name) | Intersight Kubernetes Service Cluster Name. | `string` | `"iks"` | no | +| [dns\_servers](#input\_dns\_servers) | List of DNS Server(s) for Kubernetes System Configuration Policy and IP Pool. | `list(string)` |
[
"10.200.0.100"
]
| no | +| [domain\_name](#input\_domain\_name) | Domain Name for Kubernetes Sysconfig Policy. | `string` | `"demo.intra"` | no | +| [endpoint](#input\_endpoint) | Intersight URL. | `string` | `"https://intersight.com"` | no | +| [ip\_pool](#input\_ip\_pool) | Intersight Kubernetes Service IP Pool. Default name is {cluster\_name}\_ip\_pool | `string` | `""` | no | +| [ip\_pool\_from](#input\_ip\_pool\_from) | IP Pool Starting IP last Octet. The var.network\_prefix will be combined with ip\_pool\_from for the Starting Address. | `string` | `"20"` | no | +| [ip\_pool\_gateway](#input\_ip\_pool\_gateway) | IP Pool Gateway last Octet. The var.network\_prefix will be combined with ip\_pool\_gateway for the Gateway Address. | `string` | `"254"` | no | +| [ip\_pool\_netmask](#input\_ip\_pool\_netmask) | IP Pool Netmask. | `string` | `"255.255.255.0"` | no | +| [ip\_pool\_size](#input\_ip\_pool\_size) | IP Pool Block Size. | `string` | `"30"` | no | +| [k8s\_addon\_policy](#input\_k8s\_addon\_policy) | Kubernetes Runtime Policy Name. Default name is {cluster\_name}-runtime. | `string` | `""` | no | +| [k8s\_runtime\_policy](#input\_k8s\_runtime\_policy) | Kubernetes Runtime Policy Name. Default name is {cluster\_name}-runtime. | `string` | `""` | no | +| [k8s\_trusted\_registry](#input\_k8s\_trusted\_registry) | Kubernetes Trusted Registry Policy Name. Default name is {cluster\_name}-registry. | `string` | `""` | no | +| [k8s\_version\_policy](#input\_k8s\_version\_policy) | Kubernetes Version Policy Name. Default name is {cluster\_name}-k8s-version. | `string` | `""` | no | +| [k8s\_vm\_infra\_policy](#input\_k8s\_vm\_infra\_policy) | Kubernetes Virtual Machine Infrastructure Configuration Policy. Default name is {cluster\_name}-vm-infra-config. | `string` | `""` | no | +| [k8s\_vm\_network\_policy](#input\_k8s\_vm\_network\_policy) | Kubernetes Network/System Configuration Policy (CIDR, dns, ntp, etc.). Default name is {cluster\_name}-sysconfig. | `string` | `""` | no | +| [network\_prefix](#input\_network\_prefix) | Network Prefix to Assign to DNS/NTP Servers & vCenter Target default values. | `string` | `"10.200.0"` | no | +| [ntp\_servers](#input\_ntp\_servers) | List of NTP Server for Kubernetes System Configuration Policy. If undefined then the dns\_servers will be used. | `list(string)` | `[]` | no | +| [organization](#input\_organization) | Intersight Organization. | `string` | `"default"` | no | +| [proxy\_http\_hostname](#input\_proxy\_http\_hostname) | HTTP Proxy Server Name or IP Address. | `string` | `""` | no | +| [proxy\_http\_username](#input\_proxy\_http\_username) | HTTP Proxy Username. | `string` | `""` | no | +| [proxy\_https\_hostname](#input\_proxy\_https\_hostname) | HTTPS Proxy Server Name or IP Address. | `string` | `""` | no | +| [proxy\_https\_username](#input\_proxy\_https\_username) | HTTPS Proxy Username. | `string` | `""` | no | +| [timezone](#input\_timezone) | Timezone for Kubernetes Sysconfig Policy. | `string` | `"America/New_York"` | no | +| [vsphere\_target](#input\_vsphere\_target) | vSphere Server registered as a Target in Intersight. The default, 210, only works if this is for the DevNet Sandbox. | `string` | `"210"` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [addons\_list](#output\_addons\_list) | List of Add-ons for Policy Creation. | +| [cluster\_name](#output\_cluster\_name) | Intersight Kubernetes Service Cluster Name. | +| [dns\_servers](#output\_dns\_servers) | List of DNS Server(s) for Kubernetes System Configuration Policy and IP Pool. | +| [domain\_name](#output\_domain\_name) | Domain Name. | +| [endpoint](#output\_endpoint) | Intersight URL. | +| [ip\_pool](#output\_ip\_pool) | IP Pool Policy Name. | +| [ip\_pool\_from](#output\_ip\_pool\_from) | IP Pool Starting IP Value. | +| [ip\_pool\_gateway](#output\_ip\_pool\_gateway) | IP Pool Gateway Value. | +| [ip\_pool\_netmask](#output\_ip\_pool\_netmask) | IP Pool Netmask Value. | +| [ip\_pool\_size](#output\_ip\_pool\_size) | IP Pool Block Size. | +| [k8s\_addon\_policy](#output\_k8s\_addon\_policy) | Kubernetes Trusted Registry Policy Name. | +| [k8s\_runtime\_policy](#output\_k8s\_runtime\_policy) | Kubernetes Trusted Registry Policy Name. | +| [k8s\_trusted\_registry](#output\_k8s\_trusted\_registry) | Kubernetes Trusted Registry Policy Name. | +| [k8s\_version\_policy](#output\_k8s\_version\_policy) | Kubernetes Version Policy Name. | +| [k8s\_vm\_infra\_policy](#output\_k8s\_vm\_infra\_policy) | Kubernetes VM Infrastructure Policy Name. | +| [k8s\_vm\_network\_policy](#output\_k8s\_vm\_network\_policy) | Kubernetes VM Network Policy Name. | +| [ntp\_servers](#output\_ntp\_servers) | List of NTP Server for Kubernetes System Configuration Policy. If undefined then the dns\_servers will be used. | +| [organization](#output\_organization) | Intersight Organization Name. | +| [proxy\_http\_hostname](#output\_proxy\_http\_hostname) | HTTP Proxy Server Name or IP Address. | +| [proxy\_http\_username](#output\_proxy\_http\_username) | HTTP Proxy Username. | +| [proxy\_https\_hostname](#output\_proxy\_https\_hostname) | HTTPS Proxy Server Name or IP Address. If Left blank, and proxy\_http\_hostname is defined, it will be copied to here. | +| [proxy\_https\_username](#output\_proxy\_https\_username) | HTTPS Proxy Username. | +| [timezone](#output\_timezone) | Timezone. | +| [vsphere\_target](#output\_vsphere\_target) | vSphere Target. | + diff --git a/global_vars/variables.tf b/global_vars/variables.tf new file mode 100644 index 0000000..4985ad8 --- /dev/null +++ b/global_vars/variables.tf @@ -0,0 +1,366 @@ +#__________________________________________________________ +# +# Intersight Provider Variables +#__________________________________________________________ + +variable "endpoint" { + default = "https://intersight.com" + description = "Intersight URL." + type = string +} +output "endpoint" { + description = "Intersight URL." + value = var.endpoint +} + +#__________________________________________________________ +# +# Intersight Organization Variables +#__________________________________________________________ + +variable "organization" { + default = "default" + description = "Intersight Organization." + type = string +} +output "organization" { + description = "Intersight Organization Name." + value = var.organization +} + +#______________________________________________ +# +# Prefix Variable +#______________________________________________ + +variable "network_prefix" { + default = "10.200.0" + description = "Network Prefix to Assign to DNS/NTP Servers & vCenter Target default values." + type = string + validation { + condition = (can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", var.network_prefix))) + error_message = "The network_prefix must be in the format X.X.X." + } +} + + +#______________________________________________ +# +# DNS Variables +#______________________________________________ + +variable "domain_name" { + default = "demo.intra" + description = "Domain Name for Kubernetes Sysconfig Policy." + type = string +} +output "domain_name" { + description = "Domain Name." + value = var.domain_name +} + +variable "dns_servers" { + default = ["10.200.0.100"] + description = "List of DNS Server(s) for Kubernetes System Configuration Policy and IP Pool." + type = list(string) + # validation { + # condition = ( + # can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", var.dns_primary)) + # ) + # error_message = "The dns_servers must be in the format X.X.X.X or X." + # } +} +output "dns_servers" { + description = "List of DNS Server(s) for Kubernetes System Configuration Policy and IP Pool." + value = var.dns_servers +} + +#______________________________________________ +# +# Time Variables +#______________________________________________ + +variable "timezone" { + default = "America/New_York" + description = "Timezone for Kubernetes Sysconfig Policy." + type = string +} +output "timezone" { + description = "Timezone." + value = var.timezone +} + +variable "ntp_servers" { + default = [] + description = "List of NTP Server for Kubernetes System Configuration Policy. If undefined then the dns_servers will be used." + type = list(string) +} +output "ntp_servers" { + description = "List of NTP Server for Kubernetes System Configuration Policy. If undefined then the dns_servers will be used." + value = length(var.ntp_servers) != 0 ? var.ntp_servers : var.dns_servers +} + +#______________________________________________ +# +# IKS Cluster Variable +#______________________________________________ + +variable "cluster_name" { + default = "iks" + description = "Intersight Kubernetes Service Cluster Name." + type = string +} +output "cluster_name" { + description = "Intersight Kubernetes Service Cluster Name." + value = var.cluster_name +} + + +#______________________________________________ +# +# Intersight IP Pool Variables +#______________________________________________ + +variable "ip_pool" { + default = "" + description = "Intersight Kubernetes Service IP Pool. Default name is {cluster_name}_ip_pool" + type = string +} +output "ip_pool" { + description = "IP Pool Policy Name." + value = var.ip_pool != "" ? var.ip_pool : join("-", [var.cluster_name, "ip_pool"]) +} + +variable "ip_pool_netmask" { + default = "255.255.255.0" + description = "IP Pool Netmask." + type = string + validation { + condition = ( + can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", var.ip_pool_netmask)) + ) + error_message = "The ip_pool_netmask must be in the format X.X.X.X." + } +} +output "ip_pool_netmask" { + description = "IP Pool Netmask Value." + value = var.ip_pool_netmask +} + +variable "ip_pool_gateway" { + default = "254" + description = "IP Pool Gateway last Octet. The var.network_prefix will be combined with ip_pool_gateway for the Gateway Address." + type = string + validation { + condition = ( + can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", var.ip_pool_gateway)) || + can(regex("^[0-9]{1,3}$", var.ip_pool_gateway)) + ) + error_message = "The ip_pool_gateway must be in the format X.X.X.X or X." + } +} +output "ip_pool_gateway" { + description = "IP Pool Gateway Value." + value = trimspace(<<-EOT + %{if can(regex("[\\d]{1,3}\\.[\\d]{1,3}\\.", var.ip_pool_gateway))}${var.ip_pool_gateway}%{endif} + %{if can(regex("^[0-9]{1,3}$", var.ip_pool_gateway))}${join(".", [var.network_prefix, var.ip_pool_gateway])}%{endif} + EOT + ) +} + +variable "ip_pool_from" { + default = "20" + description = "IP Pool Starting IP last Octet. The var.network_prefix will be combined with ip_pool_from for the Starting Address." + type = string + validation { + condition = ( + can(regex("^[0-9]{1,3}$", var.ip_pool_from)) + ) + error_message = "The ip_pool_from must be in the format X." + } +} +output "ip_pool_from" { + description = "IP Pool Starting IP Value." + value = join(".", [var.network_prefix, var.ip_pool_from]) +} + +variable "ip_pool_size" { + default = "30" + description = "IP Pool Block Size." + type = string + validation { + condition = ( + can(regex("^[0-9]{1,3}$", var.ip_pool_size)) + ) + error_message = "The ip_pool_size must be in the X." + } +} +output "ip_pool_size" { + description = "IP Pool Block Size." + value = var.ip_pool_size +} + +#______________________________________________ +# +# Kubernetes Add-ons Policy Variables +#______________________________________________ + +variable "addons_list" { + default = [] + description = "List of Add-ons for Intersight Kubernetes Service. Add-ons Options are {ccp-monitor|kubernetes-dashboard}." + type = list(string) +} +output "addons_list" { + description = "List of Add-ons for Policy Creation." + value = [ + for a in var.addons_list : + { + addon_policy_name = "${var.cluster_name}_${a}" + addon = a + description = "Policy for ${a}" + upgrade_strategy = "AlwaysReinstall" + install_strategy = "InstallOnly" + } + ] +} + + +#______________________________________________ +# +# Kubernetes Runtime Variables +#______________________________________________ + +variable "proxy_http_hostname" { + default = "" + description = "HTTP Proxy Server Name or IP Address." + type = string +} +output "proxy_http_hostname" { + description = "HTTP Proxy Server Name or IP Address." + value = var.proxy_http_hostname +} + +variable "proxy_http_username" { + default = "" + description = "HTTP Proxy Username." + type = string +} +output "proxy_http_username" { + description = "HTTP Proxy Username." + value = var.proxy_http_username +} + +variable "proxy_https_hostname" { + default = "" + description = "HTTPS Proxy Server Name or IP Address." + type = string +} +output "proxy_https_hostname" { + description = "HTTPS Proxy Server Name or IP Address. If Left blank, and proxy_http_hostname is defined, it will be copied to here." + value = var.proxy_https_hostname != [] ? var.proxy_https_hostname : var.proxy_http_hostname +} + +variable "proxy_https_username" { + default = "" + description = "HTTPS Proxy Username." + type = string +} +output "proxy_https_username" { + description = "HTTPS Proxy Username." + value = var.proxy_https_username != [] ? var.proxy_https_username : var.proxy_http_username +} + + +#______________________________________________ +# +# Kubernetes Policy Names +#______________________________________________ + +variable "k8s_addon_policy" { + default = "" + description = "Kubernetes Runtime Policy Name. Default name is {cluster_name}-runtime." + type = string +} +output "k8s_addon_policy" { + description = "Kubernetes Trusted Registry Policy Name." + value = var.k8s_addon_policy != "" ? var.k8s_addon_policy : join("-", [var.cluster_name, "addon"]) +} + +variable "k8s_runtime_policy" { + default = "" + description = "Kubernetes Runtime Policy Name. Default name is {cluster_name}-runtime." + type = string +} +output "k8s_runtime_policy" { + description = "Kubernetes Trusted Registry Policy Name." + value = var.k8s_runtime_policy != "" ? var.k8s_runtime_policy : join("-", [var.cluster_name, "runtime"]) +} + +variable "k8s_trusted_registry" { + default = "" + description = "Kubernetes Trusted Registry Policy Name. Default name is {cluster_name}-registry." + type = string +} +output "k8s_trusted_registry" { + description = "Kubernetes Trusted Registry Policy Name." + value = var.k8s_trusted_registry != "" ? var.k8s_trusted_registry : join("-", [var.cluster_name, "registry"]) +} + +variable "k8s_version_policy" { + default = "" + description = "Kubernetes Version Policy Name. Default name is {cluster_name}-k8s-version." + type = string +} +output "k8s_version_policy" { + description = "Kubernetes Version Policy Name." + value = var.k8s_version_policy != "" ? var.k8s_version_policy : join("-", [var.cluster_name, "k8s-version"]) +} + +variable "k8s_vm_network_policy" { + default = "" + description = "Kubernetes Network/System Configuration Policy (CIDR, dns, ntp, etc.). Default name is {cluster_name}-sysconfig." + type = string +} +output "k8s_vm_network_policy" { + description = "Kubernetes VM Network Policy Name." + value = var.k8s_vm_network_policy != "" ? var.k8s_vm_network_policy : join("-", [var.cluster_name, "sysconfig"]) +} + +variable "k8s_vm_infra_policy" { + default = "" + description = "Kubernetes Virtual Machine Infrastructure Configuration Policy. Default name is {cluster_name}-vm-infra-config." + type = string +} +output "k8s_vm_infra_policy" { + description = "Kubernetes VM Infrastructure Policy Name." + value = var.k8s_vm_infra_policy != "" ? var.k8s_vm_infra_policy : join("-", [var.cluster_name, "vm-infra-config"]) +} + + +#______________________________________________ +# +# K8S VM Infra Policy Variables +#______________________________________________ +# +variable "vsphere_target" { + default = "210" + description = "vSphere Server registered as a Target in Intersight. The default, 210, only works if this is for the DevNet Sandbox." + type = string + validation { + condition = ( + can(regex("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$", var.vsphere_target)) || + can(regex("^[0-9]{1,3}$", var.vsphere_target)) || + can(regex("^[[:alnum:]]+", var.vsphere_target)) + ) + error_message = "The vsphere_target must be in the format hostname or IPv4 Address or just a number." + } +} +output "vsphere_target" { + description = "vSphere Target." + value = trimspace(<<-EOT + %{if can(regex("[\\d]{1,3}\\.[\\d]{1,3}\\.", var.vsphere_target))}${var.vsphere_target}%{endif} + %{if can(regex("^[0-9]{1,3}$", var.vsphere_target))}${join(".", [var.network_prefix, var.vsphere_target])}%{endif} + %{if can(regex("^[[:alnum:]]+", var.vsphere_target))}${var.vsphere_target}%{endif} + EOT + ) +} diff --git a/iks/README.md b/iks/README.md new file mode 100644 index 0000000..e7fe981 --- /dev/null +++ b/iks/README.md @@ -0,0 +1,104 @@ +# IKS Policies and Cluster Profile Module + +## Use this module to create Kubernetes policies and an IKS Cluster profile in Intersight + +Run the plan from the Terraform cloud workspace. + + +## Requirements + +| Name | Version | +|------|---------| +| [intersight](#requirement\_intersight) | 1.0.9 | + +## Providers + +| Name | Version | +|------|---------| +| [intersight](#provider\_intersight) | 1.0.9 | +| [terraform](#provider\_terraform) | n/a | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [iks\_addon\_profile](#module\_iks\_addon\_profile) | terraform-cisco-modules/iks/intersight//modules/cluster_addon_profile | n/a | +| [iks\_cluster](#module\_iks\_cluster) | terraform-cisco-modules/iks/intersight//modules/cluster | n/a | +| [ip\_pool](#module\_ip\_pool) | terraform-cisco-modules/iks/intersight//modules/ip_pool | n/a | +| [k8s\_addons](#module\_k8s\_addons) | terraform-cisco-modules/iks/intersight//modules/addon_policy | n/a | +| [k8s\_instance\_large](#module\_k8s\_instance\_large) | terraform-cisco-modules/iks/intersight//modules/worker_profile | n/a | +| [k8s\_instance\_medium](#module\_k8s\_instance\_medium) | terraform-cisco-modules/iks/intersight//modules/worker_profile | n/a | +| [k8s\_instance\_small](#module\_k8s\_instance\_small) | terraform-cisco-modules/iks/intersight//modules/worker_profile | n/a | +| [k8s\_runtime\_policy](#module\_k8s\_runtime\_policy) | terraform-cisco-modules/iks/intersight//modules/runtime_policy | n/a | +| [k8s\_trusted\_registry](#module\_k8s\_trusted\_registry) | terraform-cisco-modules/iks/intersight//modules/trusted_registry | n/a | +| [k8s\_version\_policy](#module\_k8s\_version\_policy) | terraform-cisco-modules/iks/intersight//modules/version | n/a | +| [k8s\_vm\_infra\_policy](#module\_k8s\_vm\_infra\_policy) | terraform-cisco-modules/iks/intersight//modules/infra_config_policy | n/a | +| [k8s\_vm\_network\_policy](#module\_k8s\_vm\_network\_policy) | terraform-cisco-modules/iks/intersight//modules/k8s_network | n/a | +| [master\_instance\_type](#module\_master\_instance\_type) | terraform-cisco-modules/iks/intersight//modules/infra_provider | n/a | +| [master\_profile](#module\_master\_profile) | terraform-cisco-modules/iks/intersight//modules/node_profile | n/a | +| [worker\_instance\_type](#module\_worker\_instance\_type) | terraform-cisco-modules/iks/intersight//modules/infra_provider | n/a | +| [worker\_profile](#module\_worker\_profile) | terraform-cisco-modules/iks/intersight//modules/node_profile | n/a | + +## Resources + +| Name | Type | +|------|------| +| [intersight_organization_organization.organization_moid](https://registry.terraform.io/providers/CiscoDevNet/intersight/1.0.9/docs/data-sources/organization_organization) | data source | +| [terraform_remote_state.global](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [action](#input\_action) | Action to perform on the Intersight Kubernetes Cluster. Options are {Delete\|Deploy\|Ready\|Unassign}. | `string` | `"Deploy"` | no | +| [apikey](#input\_apikey) | Intersight API Key. | `string` | n/a | yes | +| [cni](#input\_cni) | Supported CNI type. Currently we only support Calico.
* Calico - Calico CNI plugin as described in:
https://github.com/projectcalico/cni-plugin. | `string` | `"Calico"` | no | +| [docker\_no\_proxy](#input\_docker\_no\_proxy) | Docker no proxy list, when using internet proxy. Default is no list. | `list(string)` | `[]` | no | +| [k8s\_pod\_cidr](#input\_k8s\_pod\_cidr) | Pod CIDR Block to be used to assign Pod IP Addresses. | `string` | `"100.65.0.0/16"` | no | +| [k8s\_service\_cidr](#input\_k8s\_service\_cidr) | Service CIDR Block used to assign Cluster Service IP Addresses. | `string` | `"100.64.0.0/16"` | no | +| [k8s\_version](#input\_k8s\_version) | Kubernetes Version to Deploy. | `string` | `"1.19.5"` | no | +| [load\_balancers](#input\_load\_balancers) | Intersight Kubernetes Load Balancer count. | `string` | `3` | no | +| [master\_desired\_size](#input\_master\_desired\_size) | K8S Master Desired Cluster Size. | `string` | `1` | no | +| [master\_instance\_type](#input\_master\_instance\_type) | K8S Master Virtual Machine Instance Type. Options are {small\|medium\|large}. | `string` | `"small"` | no | +| [master\_max\_size](#input\_master\_max\_size) | K8S Master Maximum Cluster Size. | `string` | `1` | no | +| [proxy\_http\_password](#input\_proxy\_http\_password) | Password for the HTTP Proxy Server, If required. | `string` | `""` | no | +| [proxy\_http\_port](#input\_proxy\_http\_port) | Proxy HTTP Port. | `string` | `"8080"` | no | +| [proxy\_http\_protocol](#input\_proxy\_http\_protocol) | Proxy HTTP Protocol. | `string` | `"http"` | no | +| [proxy\_https\_password](#input\_proxy\_https\_password) | Password for the HTTPS Proxy Server, If required. | `string` | `""` | no | +| [proxy\_https\_port](#input\_proxy\_https\_port) | Proxy HTTP Port. | `string` | `"8443"` | no | +| [proxy\_https\_protocol](#input\_proxy\_https\_protocol) | Proxy HTTP Protocol. | `string` | `"https"` | no | +| [root\_ca\_registries](#input\_root\_ca\_registries) | List of root CA Signed Registries. | `list(string)` | `[]` | no | +| [secretkey](#input\_secretkey) | Intersight Secret Key. | `string` | n/a | yes | +| [ssh\_key](#input\_ssh\_key) | Intersight Kubernetes Service Cluster SSH Public Key. | `string` | n/a | yes | +| [ssh\_user](#input\_ssh\_user) | Intersight Kubernetes Service Cluster Default User. | `string` | `"iksadmin"` | no | +| [tags](#input\_tags) | Tags to be Associated with Objects Created in Intersight. | `list(map(string))` | `[]` | no | +| [tfc\_organization](#input\_tfc\_organization) | Terraform Cloud Organization. | `string` | `"CiscoDevNet"` | no | +| [unsigned\_registries](#input\_unsigned\_registries) | List of unsigned registries to be supported. | `list(string)` | `[]` | no | +| [vsphere\_cluster](#input\_vsphere\_cluster) | vSphere Cluster to assign the K8S Cluster Deployment. | `string` | `"hx-demo"` | no | +| [vsphere\_datastore](#input\_vsphere\_datastore) | vSphere Datastore to assign the K8S Cluster Deployment. | `string` | `"hx-demo-ds1"` | no | +| [vsphere\_password](#input\_vsphere\_password) | vSphere Password. Note: this is the password of the Credentials used to register the vSphere Target. | `string` | n/a | yes | +| [vsphere\_portgroup](#input\_vsphere\_portgroup) | vSphere Port Group to assign the K8S Cluster Deployment. | `list` |
[
"Management"
]
| no | +| [vsphere\_resource\_pool](#input\_vsphere\_resource\_pool) | vSphere Resource Pool to assign the K8S Cluster Deployment. | `string` | `""` | no | +| [worker\_desired\_size](#input\_worker\_desired\_size) | K8S Worker Desired Cluster Size. | `string` | `0` | no | +| [worker\_instance\_type](#input\_worker\_instance\_type) | K8S Worker Virtual Machine Instance Type. Options are {small\|medium\|large}. | `string` | `"small"` | no | +| [worker\_max\_size](#input\_worker\_max\_size) | K8S Worker Maximum Cluster Size. | `string` | `4` | no | +| [ws\_global\_vars](#input\_ws\_global\_vars) | Global Variables Workspace Name. The default value will be set to {cluster\_name}\_global\_vars by the tfe variable module. | `string` | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [iks\_cluster](#output\_iks\_cluster) | moid of the IKS Cluster. | +| [ip\_pool](#output\_ip\_pool) | moid of the IP Pool | +| [k8s\_instance\_large](#output\_k8s\_instance\_large) | moid of the Large Kubernetes Instance Type. | +| [k8s\_instance\_medium](#output\_k8s\_instance\_medium) | moid of the Medium Kubernetes Instance Type. | +| [k8s\_instance\_small](#output\_k8s\_instance\_small) | moid of the Small Kubernetes Instance Type. | +| [k8s\_network\_cidr](#output\_k8s\_network\_cidr) | moid of the Kubernetes CIDR Policy. | +| [k8s\_nodeos\_config](#output\_k8s\_nodeos\_config) | moid of the Kubernetes Node OS Config Policy. | +| [k8s\_trusted\_registry](#output\_k8s\_trusted\_registry) | moid of the Kubernetes Trusted Registry Policy. | +| [k8s\_version\_policy](#output\_k8s\_version\_policy) | moid of the Kubernetes Version Policy. | +| [k8s\_vm\_infra\_policy](#output\_k8s\_vm\_infra\_policy) | moid of the Kubernetes VM Infrastructure Policy. | +| [master\_profile](#output\_master\_profile) | moid of the Master Node Profile. | +| [organization\_moid](#output\_organization\_moid) | moid of the Intersight Organization. | +| [worker\_profile](#output\_worker\_profile) | moid of the Worker Node Profile. | + diff --git a/iks/main.tf b/iks/main.tf new file mode 100644 index 0000000..55117e8 --- /dev/null +++ b/iks/main.tf @@ -0,0 +1,382 @@ +#__________________________________________________________ +# +# Get Outputs from the Global Variables Workspace +#__________________________________________________________ + +data "terraform_remote_state" "global" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_global_vars + } + } +} + + +#__________________________________________________________ +# +# Assign Global Attributes from global_vars Workspace +#__________________________________________________________ + +locals { + # Intersight Provider Variables + endpoint = yamldecode(data.terraform_remote_state.global.outputs.endpoint) + # Intersight Organization + organization = yamldecode(data.terraform_remote_state.global.outputs.organization) + # DNS Variables + dns_servers = data.terraform_remote_state.global.outputs.dns_servers + domain_name = yamldecode(data.terraform_remote_state.global.outputs.domain_name) + # Time Variables + ntp_servers = data.terraform_remote_state.global.outputs.ntp_servers + timezone = yamldecode(data.terraform_remote_state.global.outputs.timezone) + # IKS Cluster Variable + cluster_name = yamldecode(data.terraform_remote_state.global.outputs.cluster_name) + # IP Pool Variables + ip_pool = yamldecode(data.terraform_remote_state.global.outputs.ip_pool) + ip_pool_netmask = yamldecode(data.terraform_remote_state.global.outputs.ip_pool_netmask) + ip_pool_gateway = yamldecode(data.terraform_remote_state.global.outputs.ip_pool_gateway) + ip_pool_from = yamldecode(data.terraform_remote_state.global.outputs.ip_pool_from) + ip_pool_size = yamldecode(data.terraform_remote_state.global.outputs.ip_pool_size) + # Kubernetes Add-ons List + addons_list = data.terraform_remote_state.global.outputs.addons_list + # Kubernetes Runtime Variables + proxy_http_hostname = data.terraform_remote_state.global.outputs.proxy_http_hostname != "" ? yamldecode( + data.terraform_remote_state.global.outputs.proxy_http_hostname + ) : "" + proxy_http_username = data.terraform_remote_state.global.outputs.proxy_http_username != "" ? yamldecode( + data.terraform_remote_state.global.outputs.proxy_http_username + ) : "" + proxy_https_hostname = data.terraform_remote_state.global.outputs.proxy_https_hostname != "" ? yamldecode( + data.terraform_remote_state.global.outputs.proxy_https_hostname + ) : "" + proxy_https_username = data.terraform_remote_state.global.outputs.proxy_https_username != "" ? yamldecode( + data.terraform_remote_state.global.outputs.proxy_https_username + ) : "" + # Kubernetes Policy Names Variables + k8s_addon_policy = yamldecode(data.terraform_remote_state.global.outputs.k8s_addon_policy) + k8s_runtime_policy = yamldecode(data.terraform_remote_state.global.outputs.k8s_runtime_policy) + k8s_trusted_registry = yamldecode(data.terraform_remote_state.global.outputs.k8s_trusted_registry) + k8s_version_policy = yamldecode(data.terraform_remote_state.global.outputs.k8s_version_policy) + k8s_vm_network_policy = yamldecode(data.terraform_remote_state.global.outputs.k8s_vm_network_policy) + k8s_vm_infra_policy = yamldecode(data.terraform_remote_state.global.outputs.k8s_vm_infra_policy) + # vSphere Target Variable + vsphere_target = yamldecode(data.terraform_remote_state.global.outputs.vsphere_target) +} + + +#__________________________________________________________ +# +# GET the Intersight Organization moid +#__________________________________________________________ + +data "intersight_organization_organization" "organization_moid" { + name = local.organization +} + + +#__________________________________________________________ +# +# Create Kubernetes Policies +#__________________________________________________________ + +#______________________________________________ +# +# Create the IP Pool +#______________________________________________ + +module "ip_pool" { + source = "terraform-cisco-modules/iks/intersight//modules/ip_pool" + org_name = local.organization + name = local.ip_pool + gateway = local.ip_pool_gateway + netmask = local.ip_pool_netmask + pool_size = local.ip_pool_size + primary_dns = local.dns_servers[0] + secondary_dns = length(local.dns_servers) > 1 ? local.dns_servers[1] : null + starting_address = local.ip_pool_from + tags = var.tags +} + +#_____________________________________________________ +# +# Configure Add-Ons Policy for the Kubernetes Cluster +#_____________________________________________________ + +module "k8s_addons" { + source = "terraform-cisco-modules/iks/intersight//modules/addon_policy" + addons = local.addons_list + org_name = local.organization + tags = var.tags +} + +#______________________________________________ +# +# Create the Kubernetes VM Infra Config +#______________________________________________ + +module "k8s_vm_infra_policy" { + source = "terraform-cisco-modules/iks/intersight//modules/infra_config_policy" + device_name = local.vsphere_target + name = local.k8s_vm_infra_policy + org_name = local.organization + tags = var.tags + vc_password = var.vsphere_password + vc_cluster = var.vsphere_cluster + vc_datastore = var.vsphere_datastore + vc_portgroup = var.vsphere_portgroup + vc_resource_pool = var.vsphere_resource_pool +} + +#______________________________________________ +# +# Create the Kubernetes VM Node OS Config Policy +#______________________________________________ + +module "k8s_vm_network_policy" { + source = "terraform-cisco-modules/iks/intersight//modules/k8s_network" + org_name = local.organization + policy_name = local.k8s_vm_network_policy + cni = var.cni + dns_servers = local.dns_servers + domain_name = local.domain_name + ntp_servers = local.ntp_servers + pod_cidr = var.k8s_pod_cidr + service_cidr = var.k8s_service_cidr + timezone = local.timezone + tags = var.tags +} + +#______________________________________________ +# +# Create the Kubernetes Version Policy +#______________________________________________ + +module "k8s_version_policy" { + source = "terraform-cisco-modules/iks/intersight//modules/version" + org_name = local.organization + k8s_version_name = local.k8s_version_policy + k8s_version = var.k8s_version + tags = var.tags +} + +#______________________________________________ +# +# Create the Kubernetes VM Instance Type Policies +# * Small +# * Medium +# * Large +#______________________________________________ + +module "k8s_instance_small" { + source = "terraform-cisco-modules/iks/intersight//modules/worker_profile" + org_name = local.organization + name = join("-", [local.cluster_name, "small"]) + cpu = 4 + disk_size = 40 + memory = 16384 + tags = var.tags +} + +module "k8s_instance_medium" { + source = "terraform-cisco-modules/iks/intersight//modules/worker_profile" + org_name = local.organization + name = join("-", [local.cluster_name, "medium"]) + cpu = 8 + disk_size = 60 + memory = 24576 + tags = var.tags +} + +module "k8s_instance_large" { + source = "terraform-cisco-modules/iks/intersight//modules/worker_profile" + org_name = local.organization + name = join("-", [local.cluster_name, "large"]) + cpu = 12 + disk_size = 80 + memory = 32768 + tags = var.tags +} + +#______________________________________________ +# +# Create the Kubernetes Runtime Policy +#______________________________________________ + +module "k8s_runtime_policy" { + source = "terraform-cisco-modules/iks/intersight//modules/runtime_policy" + count = local.proxy_http_hostname != "" && local.proxy_https_hostname != "" ? 1 : 0 + docker_no_proxy = var.docker_no_proxy + org_name = local.organization + name = local.k8s_runtime_policy + proxy_http_hostname = local.proxy_http_hostname + proxy_http_port = var.proxy_http_port + proxy_http_password = var.proxy_http_password + proxy_http_protocol = var.proxy_http_protocol + proxy_http_username = local.proxy_http_username + proxy_https_hostname = local.proxy_https_hostname + proxy_https_password = var.proxy_https_password + proxy_https_port = var.proxy_https_port + proxy_https_protocol = var.proxy_https_protocol + proxy_https_username = local.proxy_https_username + tags = var.tags +} + +#______________________________________________ +# +# Create the Kubernetes Trusted Registry Policy +#______________________________________________ + +module "k8s_trusted_registry" { + count = length(var.unsigned_registries) > 0 || length(var.root_ca_registries) > 0 ? 1 : 0 + source = "terraform-cisco-modules/iks/intersight//modules/trusted_registry" + org_name = local.organization + policy_name = local.k8s_trusted_registry + root_ca_registries = var.root_ca_registries + unsigned_registries = var.unsigned_registries + tags = var.tags +} + + +#__________________________________________________________ +# +# Create Intersight Kubernetes Cluster +#__________________________________________________________ + +#______________________________________________ +# +# Create the IKS Cluster Profile +#______________________________________________ + +module "iks_cluster" { + depends_on = [ + module.ip_pool, + module.k8s_instance_small, + module.k8s_instance_medium, + module.k8s_instance_large, + module.k8s_trusted_registry, + module.k8s_version_policy, + module.k8s_vm_infra_policy, + module.k8s_vm_network_policy, + ] + source = "terraform-cisco-modules/iks/intersight//modules/cluster" + org_name = local.organization + action = var.action + wait_for_completion = false + name = local.cluster_name + load_balancer = var.load_balancers + ssh_key = var.ssh_key + ssh_user = var.ssh_user + tags = var.tags + # Attach Kubernetes Policies + ip_pool_moid = module.ip_pool.ip_pool_moid + net_config_moid = module.k8s_vm_network_policy.network_policy_moid + sys_config_moid = module.k8s_vm_network_policy.sys_config_policy_moid + runtime_policy_moid = length(module.k8s_runtime_policy) > 0 ? module.k8s_runtime_policy[0].runtime_policy_moid : null + trusted_registry_policy_moid = length(module.k8s_trusted_registry) > 0 ? module.k8s_trusted_registry[0].trusted_registry_moid : null +} + +#_____________________________________________________ +# +# Attach the Add-Ons Policy to the Kubernetes Cluster +#_____________________________________________________ + +module "iks_addon_profile" { + source = "terraform-cisco-modules/iks/intersight//modules/cluster_addon_profile" + count = local.addons_list != null ? 1 : 0 + depends_on = [ + module.k8s_addons, + module.iks_cluster + ] + # source = "terraform-cisco-modules/iks/intersight//modules/cluster_addon_profile" + profile_name = local.k8s_addon_policy + + addons = keys(module.k8s_addons.addon_policy) + cluster_moid = module.iks_cluster.k8s_cluster_moid + org_name = local.organization + tags = var.tags +} + + +#______________________________________________ +# +# Create the Master Profile +#______________________________________________ + +module "master_profile" { + depends_on = [ + module.iks_cluster, + ] + source = "terraform-cisco-modules/iks/intersight//modules/node_profile" + desired_size = var.master_desired_size + max_size = var.master_max_size + name = "${local.cluster_name}-master_profile" + profile_type = trimspace(<<-EOT + %{if var.worker_desired_size == "0"~}ControlPlaneWorker + %{else~}ControlPlane + %{endif~} + EOT + ) + # Attach Kubernetes Policies + cluster_moid = module.iks_cluster.cluster_moid + ip_pool_moid = module.ip_pool.ip_pool_moid + version_moid = module.k8s_version_policy.version_policy_moid +} + +module "master_instance_type" { + depends_on = [ + module.master_profile + ] + source = "terraform-cisco-modules/iks/intersight//modules/infra_provider" + name = "${local.cluster_name}-master" + instance_type_moid = trimspace(<<-EOT + %{if var.master_instance_type == "small"~}${module.k8s_instance_small.worker_profile_moid}%{endif~} + %{if var.master_instance_type == "medium"~}${module.k8s_instance_medium.worker_profile_moid}%{endif~} + %{if var.master_instance_type == "large"~}${module.k8s_instance_large.worker_profile_moid}%{endif~} + EOT + ) + node_group_moid = module.master_profile.node_group_profile_moid + infra_config_policy_moid = module.k8s_vm_infra_policy.infra_config_moid + tags = var.tags +} + +#______________________________________________ +# +# Create the Worker Profile +#______________________________________________ + +module "worker_profile" { + count = var.worker_desired_size == "0" ? 0 : 1 + depends_on = [ + module.iks_cluster + ] + source = "terraform-cisco-modules/iks/intersight//modules/node_profile" + desired_size = var.worker_desired_size + max_size = var.worker_max_size + name = "${local.cluster_name}-worker_profile" + profile_type = "Worker" + tags = var.tags + # Attach Kubernetes Policies + cluster_moid = module.iks_cluster.cluster_moid + ip_pool_moid = module.ip_pool.ip_pool_moid + version_moid = module.k8s_version_policy.version_policy_moid +} + +module "worker_instance_type" { + # skip this module if the worker_desired_size is 0 + count = var.worker_desired_size == "0" ? 0 : 1 + depends_on = [ + module.worker_profile + ] + source = "terraform-cisco-modules/iks/intersight//modules/infra_provider" + name = "${local.cluster_name}-worker" + instance_type_moid = trimspace(<<-EOT + %{if var.worker_instance_type == "small"~}${module.k8s_instance_small.worker_profile_moid}%{endif~} + %{if var.worker_instance_type == "medium"~}${module.k8s_instance_medium.worker_profile_moid}%{endif~} + %{if var.worker_instance_type == "large"~}${module.k8s_instance_large.worker_profile_moid}%{endif~} + EOT + ) + node_group_moid = var.worker_desired_size != "0" ? module.worker_profile[0].node_group_profile_moid : null + infra_config_policy_moid = module.k8s_vm_infra_policy.infra_config_moid + tags = var.tags +} diff --git a/iks/outputs.tf b/iks/outputs.tf new file mode 100644 index 0000000..205893b --- /dev/null +++ b/iks/outputs.tf @@ -0,0 +1,94 @@ +#__________________________________________________________ +# +# Organization moid Ouptut +#__________________________________________________________ + +output "organization_moid" { + description = "moid of the Intersight Organization." + value = data.intersight_organization_organization.organization_moid.id +} + +#__________________________________________________________ +# +# IP Pool Output +#__________________________________________________________ + +output "ip_pool" { + description = "moid of the IP Pool" + value = module.ip_pool.ip_pool_moid +} + + +#__________________________________________________________ +# +# Kubernetes Policies Outputs +#__________________________________________________________ + +output "k8s_instance_small" { + description = "moid of the Small Kubernetes Instance Type." + value = module.k8s_instance_small.worker_profile_moid +} + +output "k8s_instance_medium" { + description = "moid of the Medium Kubernetes Instance Type." + value = module.k8s_instance_medium.worker_profile_moid +} + +output "k8s_instance_large" { + description = "moid of the Large Kubernetes Instance Type." + value = module.k8s_instance_large.worker_profile_moid +} + +output "k8s_network_cidr" { + description = "moid of the Kubernetes CIDR Policy." + value = module.k8s_vm_network_policy.network_policy_moid +} + +output "k8s_nodeos_config" { + description = "moid of the Kubernetes Node OS Config Policy." + value = module.k8s_vm_network_policy.sys_config_policy_moid +} + +output "k8s_trusted_registry" { + depends_on = [ + module.k8s_trusted_registry + ] + description = "moid of the Kubernetes Trusted Registry Policy." + value = module.k8s_trusted_registry[0].trusted_registry_moid +} + +output "k8s_version_policy" { + description = "moid of the Kubernetes Version Policy." + value = module.k8s_version_policy.version_policy_moid +} + +output "k8s_vm_infra_policy" { + description = "moid of the Kubernetes VM Infrastructure Policy." + value = module.k8s_vm_infra_policy.infra_config_moid +} + + +#__________________________________________________________ +# +# Kubernetes Cluster Outputs +#__________________________________________________________ + +output "iks_cluster" { + description = "moid of the IKS Cluster." + value = module.iks_cluster.cluster_moid +} + +output "master_profile" { + description = "moid of the Master Node Profile." + value = module.master_profile.node_group_profile_moid +} + +output "worker_profile" { + description = "moid of the Worker Node Profile." + value = trimspace(<<-EOT + %{if var.worker_desired_size != "0"~}${module.worker_profile[0].node_group_profile_moid} + %{else~}blank + %{endif~} + EOT + ) +} diff --git a/iks/provider.tf b/iks/provider.tf new file mode 100644 index 0000000..3152e73 --- /dev/null +++ b/iks/provider.tf @@ -0,0 +1,25 @@ +#_______________________________________________________________________ +# +# Terraform Required Parameters - Intersight Provider +# https://registry.terraform.io/providers/CiscoDevNet/intersight/latest +#_______________________________________________________________________ + +terraform { + required_providers { + intersight = { + source = "CiscoDevNet/intersight" + version = "1.0.11" + } + } +} + +#______________________________________________ +# +# Intersight Provider Settings +#______________________________________________ + +provider "intersight" { + apikey = var.apikey + endpoint = local.endpoint + secretkey = var.secretkey +} diff --git a/iks/variables.tf b/iks/variables.tf new file mode 100644 index 0000000..45cbb91 --- /dev/null +++ b/iks/variables.tf @@ -0,0 +1,270 @@ +#__________________________________________________________ +# +# Terraform Cloud Organization +#__________________________________________________________ + +variable "tfc_organization" { + default = "CiscoDevNet" + description = "Terraform Cloud Organization." + type = string +} + + +#______________________________________________ +# +# Terraform Cloud global_vars Workspace +#______________________________________________ + +variable "ws_global_vars" { + default = "" + description = "Global Variables Workspace Name. The default value will be set to {cluster_name}_global_vars by the tfe variable module." + type = string +} + + +#__________________________________________________________ +# +# Intersight Provider Variables +#__________________________________________________________ + +variable "apikey" { + description = "Intersight API Key." + sensitive = true + type = string +} + +variable "secretkey" { + description = "Intersight Secret Key." + sensitive = true + type = string +} + + +#__________________________________________________________ +# +# Kubernetes Policy Variables +#__________________________________________________________ + +#______________________________________________ +# +# Kubernetes Network CIDR/System Policies +#______________________________________________ + +variable "cni" { + type = string + description = "Supported CNI type. Currently we only support Calico.\r\n* Calico - Calico CNI plugin as described in:\r\n https://github.com/projectcalico/cni-plugin." + default = "Calico" +} + +variable "k8s_pod_cidr" { + default = "100.65.0.0/16" + description = "Pod CIDR Block to be used to assign Pod IP Addresses." + type = string +} + +variable "k8s_service_cidr" { + default = "100.64.0.0/16" + description = "Service CIDR Block used to assign Cluster Service IP Addresses." + type = string +} + +variable "k8s_version" { + default = "1.19.5" + description = "Kubernetes Version to Deploy." + type = string +} + + +#______________________________________________ +# +# Kubernetes Runtime Policy Variables +#______________________________________________ + +variable "docker_no_proxy" { + default = [] + description = "Docker no proxy list, when using internet proxy. Default is no list." + type = list(string) +} + +variable "proxy_http_port" { + default = "8080" + description = "Proxy HTTP Port." + type = string +} + +variable "proxy_http_protocol" { + default = "http" + description = "Proxy HTTP Protocol." + type = string +} + +variable "proxy_http_password" { + default = "" + description = "Password for the HTTP Proxy Server, If required." + sensitive = true + type = string +} + +variable "proxy_https_password" { + default = "" + description = "Password for the HTTPS Proxy Server, If required." + sensitive = true + type = string +} + +variable "proxy_https_port" { + default = "8443" + description = "Proxy HTTP Port." + type = string +} + +variable "proxy_https_protocol" { + default = "https" + description = "Proxy HTTP Protocol." + type = string +} + + +#______________________________________________ +# +# Kubernetes VM Infra Policy Variables +#______________________________________________ + +variable "vsphere_password" { + description = "vSphere Password. Note: this is the password of the Credentials used to register the vSphere Target." + sensitive = true + type = string +} + +variable "vsphere_cluster" { + default = "hx-demo" + description = "vSphere Cluster to assign the K8S Cluster Deployment." + type = string +} + +variable "vsphere_datastore" { + default = "hx-demo-ds1" + description = "vSphere Datastore to assign the K8S Cluster Deployment." + type = string +} + +variable "vsphere_portgroup" { + default = ["Management"] + description = "vSphere Port Group to assign the K8S Cluster Deployment." +} + +variable "vsphere_resource_pool" { + default = "" + description = "vSphere Resource Pool to assign the K8S Cluster Deployment." + type = string +} + +#______________________________________________ +# +# Trusted Registries Variables +#______________________________________________ + +variable "root_ca_registries" { + default = [] + description = "List of root CA Signed Registries." + type = list(string) +} + +variable "unsigned_registries" { + default = [] + description = "List of unsigned registries to be supported." + type = list(string) +} + +#______________________________________________ +# +# Tags to Assign to the Policies and Cluster +#______________________________________________ + +variable "tags" { + default = [] + description = "Tags to be Associated with Objects Created in Intersight." + type = list(map(string)) +} + + +#__________________________________________________________ +# +# Intersight Kubernetes Service Cluster Variables +#__________________________________________________________ + +#______________________________________________ +# +# IKS Cluster Variables +#______________________________________________ + +variable "action" { + default = "Deploy" + description = "Action to perform on the Intersight Kubernetes Cluster. Options are {Delete|Deploy|Ready|Unassign}." + type = string +} + +variable "load_balancers" { + default = 3 + description = "Intersight Kubernetes Load Balancer count." + type = string +} + +variable "ssh_user" { + default = "iksadmin" + description = "Intersight Kubernetes Service Cluster Default User." + type = string +} + +variable "ssh_key" { + description = "Intersight Kubernetes Service Cluster SSH Public Key." + sensitive = true + type = string +} + + +#______________________________________________ +# +# Kubernetes Master Variables +#______________________________________________ + +variable "master_instance_type" { + default = "small" + description = "K8S Master Virtual Machine Instance Type. Options are {small|medium|large}." + type = string +} + +variable "master_desired_size" { + default = 1 + description = "K8S Master Desired Cluster Size." + type = string +} + +variable "master_max_size" { + default = 1 + description = "K8S Master Maximum Cluster Size." + type = string +} + +#______________________________________________ +# +# Kubernetes Worker Variables +#______________________________________________ + +variable "worker_instance_type" { + default = "small" + description = "K8S Worker Virtual Machine Instance Type. Options are {small|medium|large}." + type = string +} + +variable "worker_desired_size" { + default = 0 + description = "K8S Worker Desired Cluster Size." + type = string +} + +variable "worker_max_size" { + default = 4 + description = "K8S Worker Maximum Cluster Size." + type = string +} diff --git a/iwo/README.md b/iwo/README.md new file mode 100644 index 0000000..d4f61cb --- /dev/null +++ b/iwo/README.md @@ -0,0 +1,42 @@ +# Kubernetes Applications Workspace + +## Use this module to deploy Intersight Workload Optimizer and Hello Kubernetes through the Intersight Assist Appliance + +Run the plan from the Terraform cloud workspace. + + +## Requirements + +No requirements. + +## Providers + +| Name | Version | +|------|---------| +| [helm](#provider\_helm) | n/a | +| [terraform](#provider\_terraform) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [helm_release.iwok8scollector](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | +| [terraform_remote_state.global](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | +| [terraform_remote_state.kube](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [tfc\_organization](#input\_tfc\_organization) | Terraform Cloud Organization. | `string` | `"CiscoDevNet"` | no | +| [ws\_global\_vars](#input\_ws\_global\_vars) | Global Variables Workspace Name. The default value will be set to {cluster\_name}\_global\_vars by the tfe variable module. | `string` | `""` | no | +| [ws\_kube](#input\_ws\_kube) | Intersight Kubernetes Service (IKS) kube\_config Workspace Name. The default value will be set to {cluster\_name}\_kube by the tfe variable module. | `string` | `""` | no | + +## Outputs + +No outputs. + diff --git a/iwo/main.tf b/iwo/main.tf new file mode 100644 index 0000000..513f917 --- /dev/null +++ b/iwo/main.tf @@ -0,0 +1,53 @@ +#__________________________________________________________ +# +# Get Outputs from the global_vars and kube Workspace(s) +#__________________________________________________________ + +data "terraform_remote_state" "global" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_global_vars + } + } +} + +data "terraform_remote_state" "kube" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_kube + } + } +} + +locals { + # IKS Cluster Name + cluster_name = yamldecode(data.terraform_remote_state.global.outputs.cluster_name) +} + +#______________________________________________________________________ +# +# Deploy the Intersight Workload Optimizer Pod using the Helm Provider +#______________________________________________________________________ + +resource "helm_release" "iwok8scollector" { + name = "iwok8scollector" + namespace = "default" + # namespace = "iwo-collector" + chart = "https://prathjan.github.io/helm-chart/iwok8scollector-0.6.2.tgz" + set { + name = "iwoServerVersion" + value = "8.0" + } + set { + name = "collectorImage.tag" + value = "8.0.6" + } + set { + name = "targetName" + value = "${local.cluster_name}_sample" + } +} diff --git a/iwo/provider.tf b/iwo/provider.tf new file mode 100644 index 0000000..976855c --- /dev/null +++ b/iwo/provider.tf @@ -0,0 +1,18 @@ +#_______________________________________________________________ +# +# Terraform Provider - Helm +# https://registry.terraform.io/providers/hashicorp/helm/latest +#_______________________________________________________________ + +provider "helm" { + kubernetes { + host = local.kube_config.clusters[0].cluster.server + client_certificate = base64decode(local.kube_config.users[0].user.client-certificate-data) + client_key = base64decode(local.kube_config.users[0].user.client-key-data) + cluster_ca_certificate = base64decode(local.kube_config.clusters[0].cluster.certificate-authority-data) + } +} + +locals { + kube_config = yamldecode(data.terraform_remote_state.kube.outputs.kube_config) +} diff --git a/iwo/variables.tf b/iwo/variables.tf new file mode 100644 index 0000000..a5fae52 --- /dev/null +++ b/iwo/variables.tf @@ -0,0 +1,28 @@ +#__________________________________________________________ +# +# Terraform Cloud Organization +#__________________________________________________________ + +variable "tfc_organization" { + default = "CiscoDevNet" + description = "Terraform Cloud Organization." + type = string +} + + +#______________________________________________ +# +# Terraform Cloud global_vars Workspace +#______________________________________________ + +variable "ws_global_vars" { + default = "" + description = "Global Variables Workspace Name. The default value will be set to {cluster_name}_global_vars by the tfe variable module." + type = string +} + +variable "ws_kube" { + default = "" + description = "Intersight Kubernetes Service (IKS) kube_config Workspace Name. The default value will be set to {cluster_name}_kube by the tfe variable module." + type = string +} diff --git a/kube/README.md b/kube/README.md new file mode 100644 index 0000000..1d75521 --- /dev/null +++ b/kube/README.md @@ -0,0 +1,46 @@ +# Intersight Kubernetes Service kube_config Workspace + +## Use this module to obtain the kube_config through Intersight + +Run the plan from the Terraform cloud workspace. + + +## Requirements + +| Name | Version | +|------|---------| +| [intersight](#requirement\_intersight) | 1.0.9 | + +## Providers + +| Name | Version | +|------|---------| +| [intersight](#provider\_intersight) | 1.0.9 | +| [terraform](#provider\_terraform) | n/a | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [intersight_kubernetes_cluster.kube_config](https://registry.terraform.io/providers/CiscoDevNet/intersight/1.0.9/docs/data-sources/kubernetes_cluster) | data source | +| [terraform_remote_state.global](https://registry.terraform.io/providers/hashicorp/terraform/latest/docs/data-sources/remote_state) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [apikey](#input\_apikey) | Intersight API Key. | `string` | n/a | yes | +| [secretkey](#input\_secretkey) | Intersight Secret Key. | `string` | n/a | yes | +| [tfc\_organization](#input\_tfc\_organization) | Terraform Cloud Organization. | `string` | `"CiscoDevNet"` | no | +| [ws\_global\_vars](#input\_ws\_global\_vars) | Global Variables Workspace Name. The default value will be set to {cluster\_name}\_global\_vars by the tfe variable module. | `string` | `""` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [kube\_config](#output\_kube\_config) | The Intersight Kubernetes Service kube\_config output. | + diff --git a/kube/main.tf b/kube/main.tf new file mode 100644 index 0000000..003c6f3 --- /dev/null +++ b/kube/main.tf @@ -0,0 +1,37 @@ +#__________________________________________________________ +# +# Get Outputs from the Global Variables Workspace +#__________________________________________________________ + +data "terraform_remote_state" "global" { + backend = "remote" + config = { + organization = var.tfc_organization + workspaces = { + name = var.ws_global_vars + } + } +} + + +#__________________________________________________________ +# +# Assign Global Attributes from global_vars Workspace +#__________________________________________________________ + +locals { + # Intersight Provider Variables + endpoint = yamldecode(data.terraform_remote_state.global.outputs.endpoint) + # IKS Cluster Variable + cluster_name = yamldecode(data.terraform_remote_state.global.outputs.cluster_name) +} + + +#______________________________________________ +# +# Get kube_config from IKS Cluster +#______________________________________________ + +data "intersight_kubernetes_cluster" "kube_config" { + name = local.cluster_name +} diff --git a/kube/outputs.tf b/kube/outputs.tf new file mode 100644 index 0000000..7753996 --- /dev/null +++ b/kube/outputs.tf @@ -0,0 +1,9 @@ +#______________________________________________ +# +# kube_config output +#______________________________________________ + +output "kube_config" { + description = "The Intersight Kubernetes Service kube_config output." + value = base64decode(data.intersight_kubernetes_cluster.kube_config.results[0].kube_config) +} diff --git a/kube/provider.tf b/kube/provider.tf new file mode 100644 index 0000000..3152e73 --- /dev/null +++ b/kube/provider.tf @@ -0,0 +1,25 @@ +#_______________________________________________________________________ +# +# Terraform Required Parameters - Intersight Provider +# https://registry.terraform.io/providers/CiscoDevNet/intersight/latest +#_______________________________________________________________________ + +terraform { + required_providers { + intersight = { + source = "CiscoDevNet/intersight" + version = "1.0.11" + } + } +} + +#______________________________________________ +# +# Intersight Provider Settings +#______________________________________________ + +provider "intersight" { + apikey = var.apikey + endpoint = local.endpoint + secretkey = var.secretkey +} diff --git a/kube/variables.tf b/kube/variables.tf new file mode 100644 index 0000000..e514c9a --- /dev/null +++ b/kube/variables.tf @@ -0,0 +1,40 @@ + +#__________________________________________________________ +# +# Terraform Cloud Organization +#__________________________________________________________ + +variable "tfc_organization" { + default = "CiscoDevNet" + description = "Terraform Cloud Organization." + type = string +} + +#______________________________________________ +# +# Terraform Cloud global_vars Workspace +#______________________________________________ + +variable "ws_global_vars" { + default = "" + description = "Global Variables Workspace Name. The default value will be set to {cluster_name}_global_vars by the tfe variable module." + type = string +} + + +#__________________________________________________________ +# +# Intersight Provider Variables +#__________________________________________________________ + +variable "apikey" { + description = "Intersight API Key." + sensitive = true + type = string +} + +variable "secretkey" { + description = "Intersight Secret Key." + sensitive = true + type = string +} diff --git a/tfe/.gitignore b/tfe/.gitignore new file mode 100644 index 0000000..72370f4 --- /dev/null +++ b/tfe/.gitignore @@ -0,0 +1,6 @@ +.terraform +.terraform.lock.hcl +main.plan +terraform.tfstate +terraform.tfstate.backup +states diff --git a/tfe/README.md b/tfe/README.md new file mode 100644 index 0000000..67889f3 --- /dev/null +++ b/tfe/README.md @@ -0,0 +1,291 @@ +# Workspace and Variable Creation + +## VERY IMPORTANT NOTE: This provider stores terraform state in plain text. Do not remove the .gitignore that is protecting you from uploading the state files + +## Obtain tokens and keys + +Follow the base repository instructions to obtain values for the following variables: + +### Terraform Cloud Variables + +* terraform_cloud_token + + instructions: + +* tfc_oath_token + + instructions: + +* tfc_organization (TFCB Organization Name) +* tfc_email (Must be an Email Assigned to the TFCB Account) +* agent_pool (The Name of the Agent Pool in the TFCB Account) +* vcs_repo (The Name of your Version Control Repository. i.e. CiscoDevNet/intersight-tfb-iks) + +### Intersight Variables + +* apikey +* secretkey + + instructions: + +### When assigning the vSphere Password - It Must match the password used to register the Target in Intersight + +* vsphere_password + +### Generate SSH Key + +* ssh_key (Note this must be a ecdsa key type) + + instructions: + +### Import the Variables into your Environment before Running the Terraform Cloud Provider module(s) in this directory + +The Following examples are for a Linux based Operating System. Note that the TF_VAR_ prefix is used as a notification to the terraform engine that the environment variable will be consumed by terraform. + +* Terraform Cloud Variables + +```bash +export TF_VAR_terraform_cloud_token="your_cloud_token" +export TF_VAR_tfc_oath_token="your_oath_token" +export TF_VAR_tfc_email="your_email" +export TF_VAR_agent_pool="your_agent_pool_name" +export TF_VAR_vcs_repo="your_vcs_repo" +``` + +* Intersight Variables + +```bash +export TF_VAR_apikey="your_api_key" +export TF_VAR_secretkey="your_secret_key" +``` + +* Global Variables + Refer to explanation below on the purpose of the network_prefix variable + +```bash +export TF_VAR_network_prefix="10.200.0" +``` + +* vSphere Variables + +```bash +export TF_VAR_vsphere_password="your_vshpere_password" +``` + +* Kubernetes Cluster Variables + +```bash +export TF_VAR_ssh_key="your_ssh_key" +``` + +* Kubernetes Cluster Add-ons Variables + +If you want to add both Add-ons that are supported today {ccp-monitor|kubernetes-dashboard} use the following list: + +```bash +export TF_VAR_addons_list="[\"ccp-monitor\", \"kubernetes-dashboard\"]" +``` + +You can also just include one or the other add-ons. + +## Optional Variables + +Below are additional variables that have been assigned default values already. Confirm anything that needs to change for your environment. The default values are shown below. + +* Terraform Cloud Default Variables + +```bash +export TF_VAR_tfc_organization="CiscoDevNet" +export TF_VAR_terraform_version="1.0.0" +``` + +* Intersight Default Variables + +```bash +export TF_VAR_organization="default" +``` + +* Kubernetes Cluster and Policies Default Variables + + To help simplify the number of variables that are required, the following manipulation rules have been added to the global_vars. + + network_prefix function ip_pool_gateway, ip_pool_from, and vsphere_target: + + The default value is shown below. For Example with vsphere_target showing the IPv4 last octet of 210. + + This is combined with the network_prefix to become 10.200.0.210. + + This combine function works with the following variables: + + ip_pool_gateway + + ip_pool_from + + vsphere_target + + Secondary Note: dns_servers will also be assigned to ntp_servers if you don't assign anything to ntp_servers. + +```bash +export TF_VAR_domain_name="demo.intra" +export TF_VAR_dns_servers="[\"10.200.0.100\"]" +export TF_VAR_ntp_servers="[]" +export TF_VAR_ip_pool_gateway="254" +export TF_VAR_ip_pool_from="20" +export TF_VAR_k8s_pod_cidr="100.65.0.0/16" +export TF_VAR_k8s_service_cidr="100.64.0.0/16" +export TF_VAR_k8s_k8s_version="1.19.5" +export TF_VAR_root_ca_registries="[]" +export TF_VAR_unsigned_registries="[]" +``` + +* Kubernetes Runtime Optional Variables + +```bash +export TF_VAR_docker_no_proxy="[]" +export TF_VAR_proxy_http_hostname="" +export TF_VAR_proxy_http_password="" +export TF_VAR_proxy_http_port="8080" +export TF_VAR_proxy_http_protocol="http" +export TF_VAR_proxy_http_username="" +export TF_VAR_proxy_https_hostname="" +export TF_VAR_proxy_https_password="" +export TF_VAR_proxy_https_port="8443" +export TF_VAR_proxy_https_username="" +``` + +Note: The proxy_http_hostname will be cloned to the proxy_https_hostname if left blank, when configuring runtime policies. + +Note: The proxy_http_username will be cloned to the proxy_https_username if left blank, when configuring runtime policies. + +* Kubernetes Cluster Optional Variables + +```bash +export TF_VAR_tags="[]" +export TF_VAR_action="Deploy" +export TF_VAR_cluster_name="iks" +export TF_VAR_load_balancers="3" +export TF_VAR_ssh_user="iksadmin" +export TF_VAR_master_instance_type="small" +export TF_VAR_master_desired_size="1" +export TF_VAR_master_max_size="1" +export TF_VAR_worker_instance_type="small" +export TF_VAR_worker_desired_size="0" +export TF_VAR_worker_max_size="1" +``` + +* vSphere Optional Variables + + Note: The same rules above apply to the vsphere_target address. But you can use dns or IPv4 values when modifying. + +```bash +export TF_VAR_vsphere_target="210" +export TF_VAR_vsphere_cluster="hx-demo" +export TF_VAR_vsphere_datastore="hx-demo-ds1" +export TF_VAR_vsphere_portgroup="[\"Management\"]" +export TF_VAR_vsphere_resource_pool="" +``` + +For the Cluster tags; below is an example key/value format. + +```bash +export TF_VAR_tags="[ { key = \"Terraform\", value = \"Module\" }, { key = \"Owner\", value = \"CiscoDevNet\" } ]" +``` + +Once all Variables have been imported into your environment, run the plan in the tfe folder: + +```bash +terraform plan -out=main.plan +terraform apply main.plan +``` + +When run, this module will Create the Terraform Cloud Workspace(s) and Assign the Variables to the workspace(s). + + +## Requirements + +| Name | Version | +|------|---------| +| [tfe](#requirement\_tfe) | 0.25.3 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [tfc\_agent\_pool](#module\_tfc\_agent\_pool) | ../../terraform-cloud/modules/tfc_agent_pool | n/a | +| [tfc\_variables\_app\_hello](#module\_tfc\_variables\_app\_hello) | ../../terraform-cloud/modules/tfc_variables | n/a | +| [tfc\_variables\_apps](#module\_tfc\_variables\_apps) | ../../terraform-cloud/modules/tfc_variables | n/a | +| [tfc\_variables\_global](#module\_tfc\_variables\_global) | ../../terraform-cloud/modules/tfc_variables | n/a | +| [tfc\_variables\_iks](#module\_tfc\_variables\_iks) | ../../terraform-cloud/modules/tfc_variables | n/a | +| [tfc\_variables\_kube](#module\_tfc\_variables\_kube) | ../../terraform-cloud/modules/tfc_variables | n/a | +| [tfc\_workspaces](#module\_tfc\_workspaces) | ../../terraform-cloud/modules/tfc_workspaces | n/a | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [action](#input\_action) | Action to perform on the Intersight Kubernetes Cluster. Options are {Deploy\|Ready\|Unassign}. | `string` | `"Deploy"` | no | +| [addons\_list](#input\_addons\_list) | List of Add-ons to be added to Cluster. | `string` | `"[]"` | no | +| [agent\_pool](#input\_agent\_pool) | Terraform Cloud Agent Pool. | `string` | n/a | yes | +| [apikey](#input\_apikey) | Intersight API Key. | `string` | n/a | yes | +| [cluster\_name](#input\_cluster\_name) | Intersight Kubernetes Service Cluster Name. | `string` | `"iks"` | no | +| [dns\_servers](#input\_dns\_servers) | Primary DNS Server for Kubernetes Sysconfig Policy. | `string` | `"[\"10.200.0.100\"]"` | no | +| [docker\_no\_proxy](#input\_docker\_no\_proxy) | Docker no proxy list, when using internet proxy. Default is no list. | `string` | `"[]"` | no | +| [domain\_name](#input\_domain\_name) | Domain Name for Kubernetes Sysconfig Policy. | `string` | `"demo.intra"` | no | +| [ip\_pool\_from](#input\_ip\_pool\_from) | IP Pool Starting IP last Octet. The var.network\_prefix will be combined with ip\_pool\_from for the Gateway Address. | `string` | `"20"` | no | +| [ip\_pool\_gateway](#input\_ip\_pool\_gateway) | IP Pool Gateway last Octet. The var.network\_prefix will be combined with ip\_pool\_gateway for the Gateway Address. | `string` | `"254"` | no | +| [k8s\_pod\_cidr](#input\_k8s\_pod\_cidr) | Pod CIDR Block to be used to assign Pod IP Addresses. | `string` | `"100.65.0.0/16"` | no | +| [k8s\_service\_cidr](#input\_k8s\_service\_cidr) | Service CIDR Block used to assign Cluster Service IP Addresses. | `string` | `"100.64.0.0/16"` | no | +| [k8s\_version](#input\_k8s\_version) | Kubernetes Version to Deploy. | `string` | `"1.19.5"` | no | +| [load\_balancers](#input\_load\_balancers) | Intersight Kubernetes Load Balancer count. | `string` | `3` | no | +| [master\_desired\_size](#input\_master\_desired\_size) | K8S Master Desired Cluster Size. | `string` | `1` | no | +| [master\_instance\_type](#input\_master\_instance\_type) | K8S Master Virtual Machine Instance Type. Options are {small\|medium\|large}. | `string` | `"small"` | no | +| [master\_max\_size](#input\_master\_max\_size) | K8S Master Maximum Cluster Size. | `string` | `1` | no | +| [network\_prefix](#input\_network\_prefix) | IP Pool Gateway last Octet. The var.network\_prefix will be combined with ip\_pool\_gateway for the Gateway Address. | `string` | `"10.200.0"` | no | +| [organization](#input\_organization) | Intersight Organization Name. | `string` | `"default"` | no | +| [proxy\_http\_hostname](#input\_proxy\_http\_hostname) | HTTP Proxy Server Name or IP Address. | `string` | `""` | no | +| [proxy\_http\_password](#input\_proxy\_http\_password) | Password for the HTTP Proxy Server, If required. | `string` | `""` | no | +| [proxy\_http\_port](#input\_proxy\_http\_port) | Proxy HTTP Port. | `string` | `"8080"` | no | +| [proxy\_http\_protocol](#input\_proxy\_http\_protocol) | Proxy HTTP Protocol. | `string` | `"http"` | no | +| [proxy\_http\_username](#input\_proxy\_http\_username) | HTTP Proxy Username. | `string` | `""` | no | +| [proxy\_https\_hostname](#input\_proxy\_https\_hostname) | HTTPS Proxy Server Name or IP Address. | `string` | `""` | no | +| [proxy\_https\_password](#input\_proxy\_https\_password) | Password for the HTTPS Proxy Server, If required. | `string` | `""` | no | +| [proxy\_https\_port](#input\_proxy\_https\_port) | Proxy HTTP Port. | `string` | `"8443"` | no | +| [proxy\_https\_protocol](#input\_proxy\_https\_protocol) | Proxy HTTP Protocol. | `string` | `"https"` | no | +| [proxy\_https\_username](#input\_proxy\_https\_username) | HTTPS Proxy Username. | `string` | `""` | no | +| [root\_ca\_registries](#input\_root\_ca\_registries) | List of root CA Signed Registries. | `string` | `"[]"` | no | +| [secretkey](#input\_secretkey) | Intersight Secret Key. | `string` | n/a | yes | +| [ssh\_key](#input\_ssh\_key) | Intersight Kubernetes Service Cluster SSH Public Key. | `string` | n/a | yes | +| [ssh\_user](#input\_ssh\_user) | Intersight Kubernetes Service Cluster Default User. | `string` | `"iksadmin"` | no | +| [tags](#input\_tags) | Tags to be Associated with Objects Created in Intersight. | `string` | `"[]"` | no | +| [terraform\_cloud\_token](#input\_terraform\_cloud\_token) | Token to Authenticate to the Terraform Cloud. | `string` | n/a | yes | +| [terraform\_version](#input\_terraform\_version) | Terraform Target Version. | `string` | `"1.0.0"` | no | +| [tfc\_oath\_token](#input\_tfc\_oath\_token) | Terraform Cloud OAuth Token for VCS\_Repo Integration. | `string` | n/a | yes | +| [tfc\_organization](#input\_tfc\_organization) | Terraform Cloud Organization Name. | `string` | n/a | yes | +| [timezone](#input\_timezone) | Timezone for Kubernetes Sysconfig Policy. | `string` | `"America/New_York"` | no | +| [unsigned\_registries](#input\_unsigned\_registries) | List of unsigned registries to be supported. | `string` | `"[]"` | no | +| [vcs\_repo](#input\_vcs\_repo) | Version Control System Repository. | `string` | n/a | yes | +| [vsphere\_cluster](#input\_vsphere\_cluster) | vSphere Cluster to assign the K8S Cluster Deployment. | `string` | `"hx-demo"` | no | +| [vsphere\_datastore](#input\_vsphere\_datastore) | vSphere Datastore to assign the K8S Cluster Deployment. | `string` | `"hx-demo-ds1"` | no | +| [vsphere\_password](#input\_vsphere\_password) | vSphere Password. Note: this is the password of the Credentials used to register the vSphere Target. | `string` | n/a | yes | +| [vsphere\_portgroup](#input\_vsphere\_portgroup) | vSphere Port Group to assign the K8S Cluster Deployment. | `string` | `"[Management]"` | no | +| [vsphere\_resource\_pool](#input\_vsphere\_resource\_pool) | vSphere Resource Pool to assign the K8S Cluster Deployment. | `string` | `""` | no | +| [vsphere\_target](#input\_vsphere\_target) | vSphere Server registered as a Target in Intersight. The default, 210, only works if this is for the DevNet Sandbox. | `string` | `"210"` | no | +| [worker\_desired\_size](#input\_worker\_desired\_size) | K8S Worker Desired Cluster Size. | `string` | `1` | no | +| [worker\_instance\_type](#input\_worker\_instance\_type) | K8S Worker Virtual Machine Instance Type. Options are {small\|medium\|large}. | `string` | `"small"` | no | +| [worker\_max\_size](#input\_worker\_max\_size) | K8S Worker Maximum Cluster Size. | `string` | `4` | no | + +## Outputs + +| Name | Description | +|------|-------------| +| [tfc\_agent\_pool](#output\_tfc\_agent\_pool) | Terraform Cloud Agent Pool ID. | +| [tfc\_workspaces](#output\_tfc\_workspaces) | Terraform Cloud Workspace ID(s). | + diff --git a/tfe/agent_pool.tf b/tfe/agent_pool.tf new file mode 100644 index 0000000..66499de --- /dev/null +++ b/tfe/agent_pool.tf @@ -0,0 +1,15 @@ +#__________________________________________________________ +# +# Obtain Agent Pool ID from Terraform Cloud +#__________________________________________________________ + +module "tfc_agent_pool" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_agent_pool" + agent_pool = var.agent_pool + tfc_org_name = var.tfc_organization +} + +output "tfc_agent_pool" { + description = "Terraform Cloud Agent Pool ID." + value = module.tfc_agent_pool +} diff --git a/tfe/providers.tf b/tfe/providers.tf new file mode 100644 index 0000000..07d6f4e --- /dev/null +++ b/tfe/providers.tf @@ -0,0 +1,20 @@ +#______________________________________________________________ +# +# Terraform Cloud Provider +# https://registry.terraform.io/providers/hashicorp/tfe/latest +#______________________________________________________________ + +terraform { + required_providers { + tfe = { + source = "hashicorp/tfe" + version = "0.25.3" + } + } +} + +provider "tfe" { + # Configuration options + hostname = "app.terraform.io" + token = var.terraform_cloud_token +} diff --git a/tfe/tfc_workspaces.tf b/tfe/tfc_workspaces.tf new file mode 100644 index 0000000..0df7ef2 --- /dev/null +++ b/tfe/tfc_workspaces.tf @@ -0,0 +1,66 @@ +#__________________________________________________________ +# +# Terraform Cloud Workspaces +#__________________________________________________________ + +module "tfc_workspaces" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_workspaces" + depends_on = [ + module.tfc_agent_pool + ] + tfc_oath_token = var.tfc_oath_token + tfc_org_name = var.tfc_organization + workspace_list = { + "global_vars" = { + auto_apply = true + description = "Global Variables Workspace." + global_remote_state = true + name = "${var.cluster_name}_global_vars" + terraform_version = var.terraform_version + vcs_repo = var.vcs_repo + working_directory = "global_vars" + }, + "iks" = { + auto_apply = true + description = "Intersight Kubernetes Service Workspace." + name = "${var.cluster_name}_iks" + terraform_version = var.terraform_version + vcs_repo = var.vcs_repo + working_directory = "iks" + }, + "kube" = { + auto_apply = true + description = "Intersight Kubernetes Service - kube_config Workspace." + global_remote_state = true + name = "${var.cluster_name}_kube" + terraform_version = var.terraform_version + vcs_repo = var.vcs_repo + working_directory = "kube" + }, + "iwo" = { + auto_apply = true + agent_pool = module.tfc_agent_pool.tfc_agent_pool + description = "Application Workspace - Intersight Workload Optimizer." + execution_mode = "agent" + name = "${var.cluster_name}_iwo" + terraform_version = var.terraform_version + vcs_repo = var.vcs_repo + working_directory = "iwo" + }, + "app_hello" = { + auto_apply = true + agent_pool = module.tfc_agent_pool.tfc_agent_pool + description = "Application Workspace - Hello Kubernetes." + execution_mode = "agent" + name = "${var.cluster_name}_app_hello" + terraform_version = var.terraform_version + vcs_repo = var.vcs_repo + working_directory = "app_hello" + }, + } +} + +output "tfc_workspaces" { + description = "Terraform Cloud Workspace ID(s)." + value = module.tfc_workspaces +} diff --git a/tfe/variables.tf b/tfe/variables.tf new file mode 100644 index 0000000..602d997 --- /dev/null +++ b/tfe/variables.tf @@ -0,0 +1,55 @@ +#__________________________________________________________ +# +# Terraform Cloud Variables +#__________________________________________________________ + +variable "agent_pool" { + description = "Terraform Cloud Agent Pool." + type = string +} + +variable "terraform_cloud_token" { + description = "Token to Authenticate to the Terraform Cloud." + sensitive = true + type = string +} + +variable "tfc_oath_token" { + description = "Terraform Cloud OAuth Token for VCS_Repo Integration." + sensitive = true + type = string +} + +variable "tfc_organization" { + description = "Terraform Cloud Organization Name." + type = string +} + +variable "terraform_version" { + default = "1.0.0" + description = "Terraform Target Version." + type = string +} + +variable "vcs_repo" { + description = "Version Control System Repository." + type = string +} + + +#__________________________________________________________ +# +# Intersight Variables +#__________________________________________________________ + +variable "apikey" { + description = "Intersight API Key." + sensitive = true + type = string +} + +variable "secretkey" { + description = "Intersight Secret Key." + sensitive = true + type = string +} diff --git a/tfe/ws_vars_app_hello.tf b/tfe/ws_vars_app_hello.tf new file mode 100644 index 0000000..b411654 --- /dev/null +++ b/tfe/ws_vars_app_hello.tf @@ -0,0 +1,40 @@ +#__________________________________________________________ +# +# Terraform Cloud Workspace Variables: app_hello +#__________________________________________________________ + +module "tfc_variables_app_hello" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_variables" + depends_on = [ + module.tfc_workspaces + ] + category = "terraform" + workspace_id = module.tfc_workspaces.tfe_workspace_id.app_hello + variable_list = [ + { + description = "Terraform Cloud Organization." + hcl = false + key = "tfc_organization" + sensitive = false + value = var.tfc_organization + }, + { + description = "global_vars Workspace." + hcl = false + key = "ws_global_vars" + sensitive = false + value = "${var.cluster_name}_global_vars" + }, + { + description = "Intersight Kubernetes Service kube_config Workspace." + hcl = false + key = "ws_kube" + sensitive = false + value = "${var.cluster_name}_kube" + }, + ] +} + +output "app_hello_vars" { + value = module.tfc_variables_app_hello.tfe_variable_id +} diff --git a/tfe/ws_vars_global_vars.tf b/tfe/ws_vars_global_vars.tf new file mode 100644 index 0000000..1910c00 --- /dev/null +++ b/tfe/ws_vars_global_vars.tf @@ -0,0 +1,210 @@ +#__________________________________________________________ +# +# Global Variables +#__________________________________________________________ + +variable "organization" { + default = "default" + description = "Intersight Organization Name." + type = string +} + +variable "cluster_name" { + default = "iks" + description = "Intersight Kubernetes Service Cluster Name." + type = string +} + +#______________________________________________ +# +# DNS Variables +#______________________________________________ + +variable "domain_name" { + default = "demo.intra" + description = "Domain Name for Kubernetes Sysconfig Policy." + type = string +} + +variable "dns_servers" { + default = "[\"10.200.0.100\"]" + description = "DNS Servers for Kubernetes Sysconfig Policy." + type = string +} + +#______________________________________________ +# +# Time Variables +#______________________________________________ + +variable "ntp_servers" { + default = "[]" + description = "NTP Servers for Kubernetes Sysconfig Policy." + type = string +} + +variable "timezone" { + default = "America/New_York" + description = "Timezone for Kubernetes Sysconfig Policy." + type = string +} + + +#______________________________________________ +# +# IP Pool Variables +#______________________________________________ + +variable "network_prefix" { + default = "10.200.0" + description = "IP Pool Gateway last Octet. The var.network_prefix will be combined with ip_pool_gateway for the Gateway Address." + type = string +} + +variable "ip_pool_gateway" { + default = "254" + description = "IP Pool Gateway last Octet. The var.network_prefix will be combined with ip_pool_gateway for the Gateway Address." + type = string +} + +variable "ip_pool_from" { + default = "20" + description = "IP Pool Starting IP last Octet. The var.network_prefix will be combined with ip_pool_from for the Gateway Address." + type = string +} + +#______________________________________________ +# +# Kubernetes Add-ons List +#______________________________________________ + +variable "addons_list" { + default = "[]" + description = "List of Add-ons to be added to Cluster." + type = string +} + +#______________________________________________ +# +# Kubernetes VM Infra Policy Variables +#______________________________________________ + +variable "vsphere_target" { + default = "210" + description = "vSphere Server registered as a Target in Intersight. The default, 210, only works if this is for the DevNet Sandbox." + type = string +} + +#__________________________________________________________ +# +# Terraform Cloud Workspace Variables: global_vars +#__________________________________________________________ + +module "tfc_variables_global" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_variables" + depends_on = [ + module.tfc_workspaces + ] + category = "terraform" + workspace_id = module.tfc_workspaces.tfe_workspace_id.global_vars + variable_list = [ + { + description = "Intersight Organization." + hcl = false + key = "organization" + sensitive = false + value = var.organization + }, + { + description = "Domain Name." + hcl = false + key = "domain_name" + sensitive = false + value = var.domain_name + }, + { + description = "DNS Servers." + hcl = true + key = "dns_servers" + sensitive = false + value = var.dns_servers + }, + { + description = "NTP Servers." + hcl = true + key = "ntp_servers" + sensitive = false + value = var.ntp_servers + }, + { + description = "IKS Cluster Name." + hcl = false + key = "cluster_name" + sensitive = false + value = var.cluster_name + }, + { + description = "Kubernetes Add-ons Policy List." + hcl = true + key = "addons_list" + sensitive = false + value = var.addons_list + }, + { + description = "Network Prefix for IP Pool Policy." + hcl = false + key = "network_prefix" + sensitive = false + value = var.network_prefix + }, + { + description = "IP Pool Gateway last Octet." + hcl = false + key = "ip_pool_gateway" + sensitive = false + value = var.ip_pool_gateway + }, + { + description = "IP Pool Starting Address." + hcl = false + key = "ip_pool_from" + sensitive = false + value = var.ip_pool_from + }, + { + description = "HTTP Proxy Server Name or IP Address." + hcl = false + key = "proxy_http_hostname" + sensitive = false + value = var.proxy_http_hostname + }, + { + description = "HTTP Proxy Username." + hcl = false + key = "proxy_http_username" + sensitive = false + value = var.proxy_http_username + }, + { + description = "HTTPS Proxy Server Name or IP Address." + hcl = false + key = "proxy_https_hostname" + sensitive = false + value = var.proxy_https_hostname + }, + { + description = "HTTPS Proxy Username." + hcl = false + key = "proxy_https_username" + sensitive = false + value = var.proxy_https_username + }, + { + description = "vSphere Server registered as a Target in Intersight." + hcl = false + key = "vsphere_target" + sensitive = false + value = var.vsphere_target + }, + ] +} diff --git a/tfe/ws_vars_iks.tf b/tfe/ws_vars_iks.tf new file mode 100644 index 0000000..ad820b6 --- /dev/null +++ b/tfe/ws_vars_iks.tf @@ -0,0 +1,494 @@ +#__________________________________________________________ +# +# Required Variables +#__________________________________________________________ + + +#______________________________________________ +# +# Kubernetes Network CIDR/System Policies +#______________________________________________ + +variable "k8s_pod_cidr" { + default = "100.65.0.0/16" + description = "Pod CIDR Block to be used to assign Pod IP Addresses." + type = string +} + +variable "k8s_service_cidr" { + default = "100.64.0.0/16" + description = "Service CIDR Block used to assign Cluster Service IP Addresses." + type = string +} + +variable "k8s_version" { + default = "1.19.5" + description = "Kubernetes Version to Deploy." + type = string +} + +#______________________________________________ +# +# Kubernetes Runtime Variables +#______________________________________________ + +variable "docker_no_proxy" { + default = "[]" + description = "Docker no proxy list, when using internet proxy. Default is no list." + type = string +} + +variable "proxy_http_hostname" { + default = "" + description = "HTTP Proxy Server Name or IP Address." + type = string +} + +variable "proxy_http_password" { + default = "" + description = "Password for the HTTP Proxy Server, If required." + sensitive = true + type = string +} + +variable "proxy_http_port" { + default = "8080" + description = "Proxy HTTP Port." + type = string +} + +variable "proxy_http_protocol" { + default = "http" + description = "Proxy HTTP Protocol." + type = string +} + +variable "proxy_http_username" { + default = "" + description = "HTTP Proxy Username." + type = string +} + +variable "proxy_https_hostname" { + default = "" + description = "HTTPS Proxy Server Name or IP Address." + type = string +} + +variable "proxy_https_password" { + default = "" + description = "Password for the HTTPS Proxy Server, If required." + sensitive = true + type = string +} + +variable "proxy_https_port" { + default = "8443" + description = "Proxy HTTP Port." + type = string +} + +variable "proxy_https_protocol" { + default = "https" + description = "Proxy HTTP Protocol." + type = string +} + +variable "proxy_https_username" { + default = "" + description = "HTTPS Proxy Username." + type = string +} + + +#______________________________________________ +# +# K8S VM Infrastructure Policy Variables +#______________________________________________ +# +variable "vsphere_password" { + description = "vSphere Password. Note: this is the password of the Credentials used to register the vSphere Target." + sensitive = true + type = string +} + +variable "vsphere_cluster" { + default = "hx-demo" + description = "vSphere Cluster to assign the K8S Cluster Deployment." + type = string +} + +variable "vsphere_datastore" { + default = "hx-demo-ds1" + description = "vSphere Datastore to assign the K8S Cluster Deployment." + type = string +} + +variable "vsphere_portgroup" { + default = "[Management]" + description = "vSphere Port Group to assign the K8S Cluster Deployment." + type = string +} + +variable "vsphere_resource_pool" { + default = "" + description = "vSphere Resource Pool to assign the K8S Cluster Deployment." + type = string +} + +#______________________________________________ +# +# Trusted Registries Variables +#______________________________________________ + +variable "root_ca_registries" { + default = "[]" + description = "List of root CA Signed Registries." + type = string +} + +variable "unsigned_registries" { + default = "[]" + description = "List of unsigned registries to be supported." + type = string +} + +#______________________________________________ +# +# Intersight Tags +#______________________________________________ + +variable "tags" { + default = "[]" + description = "Tags to be Associated with Objects Created in Intersight." + type = string +} + + +#______________________________________________ +# +# Intersight Kubernetes Cluster Variables +#______________________________________________ + +variable "action" { + default = "Deploy" + description = "Action to perform on the Intersight Kubernetes Cluster. Options are {Deploy|Ready|Unassign}." + type = string +} + +variable "load_balancers" { + default = 3 + description = "Intersight Kubernetes Load Balancer count." + type = string +} + +variable "ssh_user" { + default = "iksadmin" + description = "Intersight Kubernetes Service Cluster Default User." + type = string +} + +variable "ssh_key" { + description = "Intersight Kubernetes Service Cluster SSH Public Key." + sensitive = false + type = string +} + +#______________________________________________ +# +# Master Node Profile Variables +#______________________________________________ + +variable "master_instance_type" { + default = "small" + description = "K8S Master Virtual Machine Instance Type. Options are {small|medium|large}." + type = string +} + +variable "master_desired_size" { + default = 1 + description = "K8S Master Desired Cluster Size." + type = string +} + +variable "master_max_size" { + default = 1 + description = "K8S Master Maximum Cluster Size." + type = string +} + +#______________________________________________ +# +# Worker Node Profile Variables +#______________________________________________ + +variable "worker_instance_type" { + default = "small" + description = "K8S Worker Virtual Machine Instance Type. Options are {small|medium|large}." + type = string +} + +variable "worker_desired_size" { + default = 1 + description = "K8S Worker Desired Cluster Size." + type = string +} + +variable "worker_max_size" { + default = 4 + description = "K8S Worker Maximum Cluster Size." + type = string +} + + +#__________________________________________________________ +# +# Terraform Cloud Workspace Variables: iks +#__________________________________________________________ + +module "tfc_variables_iks" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_variables" + depends_on = [ + module.tfc_workspaces + ] + category = "terraform" + workspace_id = module.tfc_workspaces.tfe_workspace_id.iks + variable_list = [ + #--------------------------- + # Terraform Cloud Variables + #--------------------------- + { + description = "Terraform Cloud Organization." + hcl = false + key = "tfc_organization" + sensitive = false + value = var.tfc_organization + }, + { + description = "global_vars Workspace." + hcl = false + key = "ws_global_vars" + sensitive = false + value = "${var.cluster_name}_global_vars" + }, + #--------------------------- + # Intersight Variables + #--------------------------- + { + description = "Intersight API Key." + hcl = false + key = "apikey" + sensitive = true + value = var.apikey + }, + { + description = "Intersight Secret Key." + hcl = false + key = "secretkey" + sensitive = true + value = var.secretkey + }, + #----------------------------- + # Kubernetes Policy Variables + #----------------------------- + { + description = "Kubernetes Network Pod CIDR." + hcl = false + key = "k8s_pod_cidr" + sensitive = false + value = var.k8s_pod_cidr + }, + { + description = "Kubernetes Network Service CIDR." + hcl = false + key = "k8s_service_cidr" + sensitive = false + value = var.k8s_service_cidr + }, + { + description = "Kubernetes Version." + hcl = false + key = "k8s_version" + sensitive = false + value = var.k8s_version + }, + { + description = "Docker no proxy list, when using internet proxy. Default is no list." + hcl = true + key = "docker_no_proxy" + sensitive = false + value = var.docker_no_proxy + }, + { + description = "Password for the HTTP Proxy Server, If required." + hcl = false + key = "proxy_http_password" + sensitive = true + value = var.proxy_http_password + }, + { + description = "Proxy HTTP Port." + hcl = false + key = "proxy_http_port" + sensitive = false + value = var.proxy_http_port + }, + { + description = "Proxy HTTP Protocol." + hcl = false + key = "proxy_http_protocol" + sensitive = false + value = var.proxy_http_protocol + }, + { + description = "Password for the HTTPS Proxy Server, If required." + hcl = false + key = "proxy_https_password" + sensitive = true + value = var.proxy_https_password + }, + { + description = "Proxy HTTPS Port." + hcl = false + key = "proxy_https_port" + sensitive = false + value = var.proxy_https_port + }, + { + description = "Proxy HTTPS Protocol." + hcl = false + key = "proxy_https_protocol" + sensitive = false + value = var.proxy_https_protocol + }, + { + description = "vSphere Password. Note: this is the password of the Credentials used to register the vSphere Target." + hcl = false + key = "vsphere_password" + sensitive = true + value = var.vsphere_password + }, + { + description = "vSphere Cluster to assign the K8S Cluster Deployment." + hcl = false + key = "vsphere_cluster" + sensitive = false + value = var.vsphere_cluster + }, + { + description = "vSphere Datastore to assign the K8S Cluster Deployment." + hcl = false + key = "vsphere_datastore" + sensitive = false + value = var.vsphere_datastore + }, + { + description = "vSphere Port Group to assign the K8S Cluster Deployment." + hcl = true + key = "vsphere_portgroup" + sensitive = false + value = var.vsphere_portgroup + }, + { + description = "vSphere Resource Pool to assign the K8S Cluster Deployment." + hcl = false + key = "vsphere_resource_pool" + sensitive = false + value = var.vsphere_resource_pool + }, + { + description = "List of root CA Signed Registries." + hcl = true + key = "root_ca_registries" + sensitive = false + value = var.root_ca_registries + }, + { + description = "List of unsigned registries to be supported." + hcl = true + key = "unsigned_registries" + sensitive = false + value = var.unsigned_registries + }, + { + description = "Tags to be Associated with Objects Created in Intersight." + hcl = true + key = "tags" + sensitive = false + value = var.tags + }, + #--------------------------- + # IKS Cluster Variables + #--------------------------- + { + description = "Action to perform on the Intersight Kubernetes Cluster. Options are {Delete|Deploy|Ready|Unassign}." + hcl = false + key = "action" + sensitive = false + value = var.action + }, + { + description = "Intersight Kubernetes Load Balancer count." + hcl = false + key = "load_balancers" + sensitive = false + value = var.load_balancers + }, + { + description = "Intersight Kubernetes Service Cluster Default User." + hcl = false + key = "ssh_user" + sensitive = false + value = var.ssh_user + }, + { + description = "Intersight Kubernetes Service Cluster Default User." + hcl = false + key = "ssh_key" + sensitive = true + value = var.ssh_key + }, + { + description = "K8S Master Virtual Machine Instance Type. Options are {small|medium|large}." + hcl = false + key = "master_instance_type" + sensitive = false + value = var.master_instance_type + }, + { + description = "K8S Master Desired Cluster Size." + hcl = false + key = "master_desired_size" + sensitive = false + value = var.master_desired_size + }, + { + description = "K8S Master Maximum Cluster Size." + hcl = false + key = "master_max_size" + sensitive = false + value = var.master_max_size + }, + { + description = "K8S Worker Virtual Machine Instance Type. Options are {small|medium|large}." + hcl = false + key = "worker_instance_type" + sensitive = false + value = var.worker_instance_type + }, + { + description = "K8S Worker Desired Cluster Size." + hcl = false + key = "worker_desired_size" + sensitive = false + value = var.worker_desired_size + }, + { + description = "K8S Worker Maximum Cluster Size." + hcl = false + key = "worker_max_size" + sensitive = false + value = var.worker_max_size + }, + ] +} diff --git a/tfe/ws_vars_iwo.tf b/tfe/ws_vars_iwo.tf new file mode 100644 index 0000000..1db463a --- /dev/null +++ b/tfe/ws_vars_iwo.tf @@ -0,0 +1,36 @@ +#__________________________________________________________ +# +# Terraform Cloud Workspace Variables: iwo +#__________________________________________________________ + +module "tfc_variables_apps" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_variables" + depends_on = [ + module.tfc_workspaces + ] + category = "terraform" + workspace_id = module.tfc_workspaces.tfe_workspace_id.iwo + variable_list = [ + { + description = "Terraform Cloud Organization." + hcl = false + key = "tfc_organization" + sensitive = false + value = var.tfc_organization + }, + { + description = "global_vars Workspace." + hcl = false + key = "ws_global_vars" + sensitive = false + value = "${var.cluster_name}_global_vars" + }, + { + description = "Intersight Kubernetes Service kube_config Workspace." + hcl = false + key = "ws_kube" + sensitive = false + value = "${var.cluster_name}_kube" + }, + ] +} diff --git a/tfe/ws_vars_kube.tf b/tfe/ws_vars_kube.tf new file mode 100644 index 0000000..42bec8b --- /dev/null +++ b/tfe/ws_vars_kube.tf @@ -0,0 +1,49 @@ +#__________________________________________________________ +# +# Terraform Cloud Workspace Variables: kube +#__________________________________________________________ + +module "tfc_variables_kube" { + source = "terraform-cisco-modules/modules/tfe//modules/tfc_variables" + depends_on = [ + module.tfc_workspaces + ] + category = "terraform" + workspace_id = module.tfc_workspaces.tfe_workspace_id.kube + variable_list = [ + #--------------------------- + # Terraform Cloud Variables + #--------------------------- + { + description = "Terraform Cloud Organization." + hcl = false + key = "tfc_organization" + sensitive = false + value = var.tfc_organization + }, + { + description = "global_vars Workspace." + hcl = false + key = "ws_global_vars" + sensitive = false + value = "${var.cluster_name}_global_vars" + }, + #--------------------------- + # Intersight Variables + #--------------------------- + { + description = "Intersight API Key." + hcl = false + key = "apikey" + sensitive = true + value = var.apikey + }, + { + description = "Intersight Secret Key." + hcl = false + key = "secretkey" + sensitive = true + value = var.secretkey + }, + ] +}