diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..2c77321 --- /dev/null +++ b/.env.dev @@ -0,0 +1,14 @@ +TFLOG= +TF_LOG_PATH= +TF_INPUT= +#TF_VAR_name= +#TF_CLI_ARGS= +#TF_CLI_ARGS_name= +TF_DATA_DIR= +TF_WORKSPACE= +TF_IN_AUTOMATION= +TF_REGISTRY_DISCOVERY_RETRY= +TF_REGISTRY_CLIENT_TIMEOUT= +TF_CLI_CONFIG_FILE= +TF_PLUGIN_CACHE_DIR= +TF_IGNORE= diff --git a/.github/ISSUE_TEMPLATE/1-FEATURE-REQUEST.yaml b/.github/ISSUE_TEMPLATE/1-FEATURE-REQUEST.yaml new file mode 100644 index 0000000..998acfb --- /dev/null +++ b/.github/ISSUE_TEMPLATE/1-FEATURE-REQUEST.yaml @@ -0,0 +1,47 @@ +name: "💡 Feature Request" +description: "Create a new ticket for a new feature request." +title: "feat: " +labels: + - "enhancement" +assignees: + - "caerulescens" +body: + # Feature + - type: textarea + id: summary + attributes: + label: "Summary" + description: What feature would you like to add? + placeholder: ... + validations: + required: true + + # Implementation + - type: textarea + id: implementation + attributes: + label: "Implementation" + description: How would the feature work in more detail? + placeholder: ... + validations: + required: true + + # Drawbacks + - type: textarea + id: drawback + attributes: + label: "Drawbacks" + description: What drawbacks does this feature have? + placeholder: ... + validations: + required: false + + # Questions + - type: textarea + id: question + attributes: + label: "Questions" + description: Are there any unsolved question related to the feature? + placeholder: ... + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/2-BUG-REPORT.yaml b/.github/ISSUE_TEMPLATE/2-BUG-REPORT.yaml new file mode 100644 index 0000000..7db6c40 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/2-BUG-REPORT.yaml @@ -0,0 +1,87 @@ +name: "🐞 Bug Report" +description: "Create a new issue for a bug." +title: "fix: <title>" +labels: + - "bug" +assignees: + - "caerulescens" +body: + # Version + - type: textarea + id: version + attributes: + label: "Version" + description: Which version were you running? + placeholder: e.g. '0.1.0' + validations: + required: true + + # Terraform Version + - type: textarea + id: terraform-version + attributes: + label: "Terraform version" + description: Which terraform version were you using? + placeholder: e.g. '1.8.5' + validations: + required: true + + # Operating System + - type: dropdown + id: operating-system + attributes: + label: "Operating system" + description: Which operating system were you using? + multiple: false + options: + - Windows + - macOS + - GNU/Linux + validations: + required: true + + # Description + - type: textarea + id: description + attributes: + label: "Description" + description: Provide details of the issue you encountered + placeholder: ... + validations: + required: true + + # Reproduction + - type: textarea + id: reproduction + attributes: + label: "Reproduction" + description: Provide details on how to reproduce the issue + placeholder: | + #. Use config '...' + #. Run program '...' + #. See error '...' + render: bash + validations: + required: true + + # Screenshots + - type: textarea + id: screenshot + attributes: + label: "Screenshots" + description: Provide any relevant screenshots + value: | + ![DESCRIPTION](LINK.png) + render: bash + validations: + required: false + + # Logs + - type: textarea + id: log + attributes: + label: "Logs" + description: Provide any raw log output + render: bash + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yaml b/.github/ISSUE_TEMPLATE/config.yaml new file mode 100644 index 0000000..d24f832 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yaml @@ -0,0 +1,5 @@ +blank_issues_enabled: false +contact_links: + - name: Genericware Discussions + url: https://github.com/orgs/genericware/discussions + about: Please ask and answer questions here. diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..fb8a9e5 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,28 @@ +<!--- Provide a general summary of your changes in the Title above --> + +## Description +<!--- Describe your changes in detail --> + +## Motivation and Context +<!--- Why is this change required? What problem does it solve? --> +<!--- If it fixes an open issue, please link to the issue here. --> + +## How has this been tested? +<!--- Please describe in detail how you tested your changes. --> +<!--- Include details of your testing environment, tests ran to see how --> +<!--- your change affects other areas of the code, etc. --> + +## Screenshots (if appropriate): + +## Types of changes +<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: --> +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) + +## Checklist: +<!--- Go over all the following points, and put an `x` in all the boxes that apply. --> +<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> +- [ ] My code follows the code style of this project. +- [ ] My change requires a change to the documentation. +- [ ] I have updated the documentation accordingly. diff --git a/.github/actions/terraform-init/action.yaml b/.github/actions/terraform-init/action.yaml new file mode 100644 index 0000000..cbd418e --- /dev/null +++ b/.github/actions/terraform-init/action.yaml @@ -0,0 +1,64 @@ +name: Terraform Init +description: Run `terraform init` with optional caching + +inputs: + args: + description: Arguments for `terraform init` + terraform-version: + description: Desired semver compatible Terraform version + required: true + cache: + description: Enable caching terraform project files + default: 'true' + +outputs: + terraform-version: + description: The Terraform version setup + value: ${{ steps.version-terraform.outputs.terraform-version }} + cache-hit: + description: Whether an exact cache hit occurred + value: ${{ steps.cache.outputs.cache-hit }} + +runs: + using: composite + steps: + - name: Setup Terraform + id: setup-terraform + uses: hashicorp/setup-terraform@v3 + with: + terraform_version: ${{ inputs.terraform-version }} + + - name: Get Version + id: version-terraform + run: printf 'terraform-version=%s\n' "$(terraform version -json | jq -r '.terraform_version')" >> $GITHUB_OUTPUT + shell: bash + + - run: printf 'date=%s\n' "$(date -I)" >> $GITHUB_OUTPUT + id: get-date + if: inputs.cache == 'true' + shell: bash + + - name: Configure Plugin Cache Directory + id: cache-config + if: inputs.cache == 'true' + run: | + echo 'plugin_cache_dir="~/.terraform.d/plugin-cache"' > ~/.terraformrc + mkdir -p ~/.terraform.d/plugin-cache + shell: bash + + - uses: actions/cache@v4 + name: Cache Terraform Plugins + id: cache-terraform + if: inputs.cache == 'true' + with: + path: | + ~/.terraform.d/plugin-cache + key: terraform-${{ steps.get-date.outputs.date }}-${{ runner.os }}-${{ hashFiles('.terraform.lock.hcl') }} + restore-keys: | + terraform-${{ steps.get-date.outputs.date }}-${{ runner.os }}- + terraform-${{ steps.get-date.outputs.date }}- + + - name: Init Terraform + id: init-terraform + run: terraform init ${{ inputs.args }} + shell: bash diff --git a/.github/workflows/.tests-matrix.yaml b/.github/workflows/.tests-matrix.yaml new file mode 100644 index 0000000..08da20e --- /dev/null +++ b/.github/workflows/.tests-matrix.yaml @@ -0,0 +1,63 @@ +on: + workflow_call: + inputs: + runner: + required: true + type: string + terraform-version: + required: true + type: string + tflint-version: + required: true + type: string + run-tflint: + required: true + type: boolean + run-tftest: + required: true + type: boolean + +defaults: + run: + shell: bash + +jobs: + + tflint: + name: Lint Terraform + runs-on: ${{ inputs.runner }} + if: inputs.run-tflint + steps: + - uses: actions/cache@v4 + name: Cache tflint plugins + with: + path: ~/.tflint.d/plugins + key: tflint-${{ inputs.runner }}-${{ hashFiles('.tflint.hcl') }} + restore-keys: | + tflint-${{ inputs.runner }}- + + - uses: terraform-linters/setup-tflint@v4 + name: Setup TFLint + with: + tflint_version: ${{ inputs.tflint-version }} + + - name: Init TFLint + run: tflint --init + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Run TFLint + run: tflint -f compact + + tftest: + name: Test Terraform + runs-on: ${{ inputs.runner }} + if: inputs.run-tftest + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/terraform-init + with: + terraform-version: ${{ inputs.terraform-version }} + + - run: terraform test diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..22c839c --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,101 @@ +name: Tests + +on: + push: + branches: + - master + pull_request: + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +defaults: + run: + shell: bash + +jobs: + changes: + name: Detect Changes + runs-on: ubuntu-latest + outputs: + project: ${{ steps.changes.outputs.project }} + src: ${{ steps.changes.outputs.src }} + tests: ${{ steps.changes.outputs.tests }} + steps: + - uses: actions/checkout@v4 + + - uses: dorny/paths-filter@v3 + id: changes + with: + filters: | + workflow: &workflow + - '.github/actions/**' + - '.github/workflows/tests.yaml' + - '.github/workflows/.tests-matrix.yaml' + project: &project + - *workflow + - '.terraform.lock.hcl' + src: + - *project + - '*.tf' + tests: + - *project + - '*.tf' + - 'tests/**' + + validate: + name: Validate Configuration + runs-on: ubuntu-latest + outputs: + terraform-version: ${{ steps.terraform-init.outputs.terraform-version }} + if: needs.changes.outputs.project == 'true' + needs: + - changes + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/terraform-init + id: terraform-init + with: + args: '-backend=false' + terraform-version: "latest" + + - run: terraform validate + + tests-matrix: + uses: ./.github/workflows/.tests-matrix.yaml + name: "${{ matrix.os.name }} (Terraform ${{ needs.validate.outputs.terraform-version }})" + if: '!failure()' + needs: + - changes + - validate + strategy: + matrix: + os: + - name: Ubuntu + image: ubuntu-latest + - name: macOS + image: macos-latest + - name: Windows + image: windows-latest + fail-fast: false + with: + runner: ${{ matrix.os.image }} + terraform-version: "latest" + tflint-version: "latest" + run-tflint: ${{ needs.changes.outputs.tests == 'true' }} + run-tftest: ${{ needs.changes.outputs.tests == 'true' }} + secrets: inherit + + status: + name: Status + runs-on: ubuntu-latest + if: always() + needs: + - changes + - validate + - tests-matrix + steps: + - run: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'false' || 'true' }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38d2545 --- /dev/null +++ b/.gitignore @@ -0,0 +1,158 @@ +### Emacs ### +# -*- mode: gitignore; -*- +*~ +\#*\# +/.emacs.desktop +/.emacs.desktop.lock +*.elc +auto-save-list +tramp +.\#* + +# Org-mode +.org-id-locations +*_archive + +# flymake-mode +*_flymake.* + +# eshell files +/eshell/history +/eshell/lastdir + +# elpa packages +/elpa/ + +# reftex files +*.rel + +# AUCTeX auto folder +/auto/ + +# cask packages +.cask/ +dist/ + +# Flycheck +flycheck_*.el + +# server auth directory +/server/ + +# projectiles files +.projectile + +# directory configuration +.dir-locals.el + +# network security +/network-security.data +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Terraform ### +# Local .terraform directories +**/.terraform/* + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..4a4f930 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,42 @@ +repos: + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: no-commit-to-branch + - id: check-symlinks + - id: destroyed-symlinks + - id: check-vcs-permalinks + - id: check-added-large-files + - id: check-merge-conflict + - id: check-ast + - id: check-case-conflict + - id: check-docstring-first + - id: check-json + - id: check-xml + - id: check-yaml + - id: check-toml + - id: check-merge-conflict + - id: check-symlinks + - id: check-vcs-permalinks + - id: pretty-format-json + - id: detect-private-key + - id: debug-statements + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/terraform-docs/terraform-docs + rev: v0.17.0 + hooks: + - id: terraform-docs-docker + args: ["--output-file", "README.terraform.md", "."] + + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.22 + hooks: + - id: terraform-fmt + - id: terraform-validate + - id: terragrunt-hclfmt + - id: tflint + - id: helmlint + - id: shellcheck diff --git a/.terraform-version b/.terraform-version new file mode 100644 index 0000000..bd8bf88 --- /dev/null +++ b/.terraform-version @@ -0,0 +1 @@ +1.7.0 diff --git a/.terraformignore b/.terraformignore new file mode 100644 index 0000000..e69de29 diff --git a/.tflint.hcl b/.tflint.hcl new file mode 100644 index 0000000..1679a00 --- /dev/null +++ b/.tflint.hcl @@ -0,0 +1,5 @@ +config { + format = "compact" + module = true + disabled_by_default = true +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..af98b3e --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ + +Copyright 2024 terraform-module-minikube + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + diff --git a/README.md b/README.md index 8106837..6f57a92 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -# demo.terraform-module-minikube +# terraform-module-minikube diff --git a/backend.tf b/backend.tf new file mode 100644 index 0000000..3de9d3e --- /dev/null +++ b/backend.tf @@ -0,0 +1,5 @@ +terraform { + backend "local" { + path = "terraform.tfstate" + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..4ff4e95 --- /dev/null +++ b/main.tf @@ -0,0 +1,112 @@ +terraform { + required_version = ">= 1.7.0" + required_providers { + minikube = { + source = "scott-the-programmer/minikube" + version = ">= 0.3.10" + } + } +} + +module "minikube_cluster" { + for_each = var.minikube_clusters + source = "./modules/minikube_cluster" + providers = { minikube = minikube } + addons = each.value.addons + apiserver_ips = each.value.apiserver_ips + apiserver_name = each.value.apiserver_name + apiserver_names = each.value.apiserver_names + apiserver_port = each.value.apiserver_port + auto_pause_interval = each.value.auto_pause_interval + auto_update_drivers = each.value.auto_update_drivers + base_image = each.value.base_image + binary_mirror = each.value.binary_mirror + cache_images = each.value.cache_images + cert_expiration = each.value.cert_expiration + cluster_name = each.value.cluster_name + cni = each.value.cni + container_runtime = each.value.container_runtime + cpus = each.value.cpus + cri_socket = each.value.cri_socket + delete_on_failure = each.value.delete_on_failure + disable_driver_mounts = each.value.disable_driver_mounts + disable_metrics = each.value.disable_metrics + disable_optimizations = each.value.disable_optimizations + disk_size = each.value.disk_size + dns_domain = each.value.dns_domain + dns_proxy = each.value.dns_proxy + docker_env = each.value.docker_env + docker_opt = each.value.docker_opt + download_only = each.value.download_only + driver = each.value.driver + dry_run = each.value.dry_run + embed_certs = each.value.embed_certs + extra_config = each.value.extra_config + extra_disks = each.value.extra_disks + feature_gates = each.value.feature_gates + force = each.value.force + force_systemd = each.value.force_systemd + gpus = each.value.gpus + ha = each.value.ha + host_dns_resolver = each.value.host_dns_resolver + host_only_cidr = each.value.host_only_cidr + host_only_nic_type = each.value.host_only_nic_type + hyperkit_vpnkit_sock = each.value.hyperkit_vpnkit_sock + hyperkit_vsock_ports = each.value.hyperkit_vsock_ports + hyperv_external_adapter = each.value.hyperv_external_adapter + hyperv_use_external_switch = each.value.hyperv_use_external_switch + hyperv_virtual_switch = each.value.hyperv_virtual_switch + image_mirror_country = each.value.image_mirror_country + image_repository = each.value.image_repository + insecure_registry = each.value.insecure_registry + install_addons = each.value.install_addons + interactive = each.value.interactive + iso_url = each.value.iso_url + keep_context = each.value.keep_context + kubernetes_version = each.value.kubernetes_version + kvm_gpu = each.value.kvm_gpu + kvm_hidden = each.value.kvm_hidden + kvm_network = each.value.kvm_network + kvm_numa_count = each.value.kvm_numa_count + kvm_qemu_uri = each.value.kvm_qemu_uri + listen_address = each.value.listen_address + memory = each.value.memory + mount = each.value.mount + mount_9p_version = each.value.mount_9p_version + mount_gid = each.value.mount_gid + mount_ip = each.value.mount_ip + mount_msize = each.value.mount_msize + mount_options = each.value.mount_options + mount_port = each.value.mount_port + mount_string = each.value.mount_string + mount_type = each.value.mount_type + mount_uid = each.value.mount_uid + namespace = each.value.namespace + nat_nic_type = each.value.nat_nic_type + native_ssh = each.value.native_ssh + network = each.value.network + nfs_share = each.value.nfs_share + nfs_shares_root = each.value.nfs_shares_root + no_kubernetes = each.value.no_kubernetes + no_vtx_check = each.value.no_vtx_check + nodes = each.value.nodes + output = each.value.output + ports = each.value.ports + preload = each.value.preload + qemu_firmware_path = each.value.qemu_firmware_path + registry_mirror = each.value.registry_mirror + service_cluster_ip_range = each.value.service_cluster_ip_range + socket_vmnet_client_path = each.value.socket_vmnet_client_path + socket_vmnet_path = each.value.socket_vmnet_path + ssh_ip_address = each.value.ssh_ip_address + ssh_key = each.value.ssh_key + ssh_port = each.value.ssh_port + ssh_user = each.value.ssh_user + static_ip = each.value.static_ip + subnet = each.value.subnet + trace = each.value.trace + uuid = each.value.uuid + vm = each.value.vm + wait = each.value.wait + wait_timeout = each.value.wait_timeout +} diff --git a/modules/minikube_cluster/README.md b/modules/minikube_cluster/README.md new file mode 100644 index 0000000..c769d1c --- /dev/null +++ b/modules/minikube_cluster/README.md @@ -0,0 +1 @@ +# terraform-module-minikube Minikube Cluster diff --git a/modules/minikube_cluster/main.tf b/modules/minikube_cluster/main.tf new file mode 100644 index 0000000..a6d0693 --- /dev/null +++ b/modules/minikube_cluster/main.tf @@ -0,0 +1,112 @@ +terraform { + required_version = ">= 1.7.0" + required_providers { + minikube = { + source = "scott-the-programmer/minikube" + version = ">= 0.3.10" + } + } +} + +# todo: 'auto_pause_interval' missing completions? +# todo: 'gpus' missing completions? +# todo: 'output' missing completion? +resource "minikube_cluster" "default" { + addons = var.addons + apiserver_ips = var.apiserver_ips + apiserver_name = var.apiserver_name + apiserver_names = var.apiserver_names + apiserver_port = var.apiserver_port + auto_pause_interval = var.auto_pause_interval + auto_update_drivers = var.auto_update_drivers + base_image = var.base_image + binary_mirror = var.binary_mirror + cache_images = var.cache_images + cert_expiration = var.cert_expiration + cluster_name = var.cluster_name + cni = var.cni + container_runtime = var.container_runtime + cpus = var.cpus + cri_socket = var.cri_socket + delete_on_failure = var.delete_on_failure + disable_driver_mounts = var.disable_driver_mounts + disable_metrics = var.disable_metrics + disable_optimizations = var.disable_optimizations + disk_size = var.disk_size + dns_domain = var.dns_domain + dns_proxy = var.dns_proxy + docker_env = var.docker_env + docker_opt = var.docker_opt + download_only = var.download_only + driver = var.driver + dry_run = var.dry_run + embed_certs = var.embed_certs + extra_config = var.extra_config + extra_disks = var.extra_disks + feature_gates = var.feature_gates + force = var.force + force_systemd = var.force_systemd + gpus = var.gpus + ha = var.ha + host_dns_resolver = var.host_dns_resolver + host_only_cidr = var.host_only_cidr + host_only_nic_type = var.host_only_nic_type + hyperkit_vpnkit_sock = var.hyperkit_vpnkit_sock + hyperkit_vsock_ports = var.hyperkit_vsock_ports + hyperv_external_adapter = var.hyperv_external_adapter + hyperv_use_external_switch = var.hyperv_use_external_switch + hyperv_virtual_switch = var.hyperv_virtual_switch + image_mirror_country = var.image_mirror_country + image_repository = var.image_repository + insecure_registry = var.insecure_registry + install_addons = var.install_addons + interactive = var.interactive + iso_url = var.iso_url + keep_context = var.keep_context + kubernetes_version = var.kubernetes_version + kvm_gpu = var.kvm_gpu + kvm_hidden = var.kvm_hidden + kvm_network = var.kvm_network + kvm_numa_count = var.kvm_numa_count + kvm_qemu_uri = var.kvm_qemu_uri + listen_address = var.listen_address + memory = var.memory + mount = var.mount + mount_9p_version = var.mount_9p_version + mount_gid = var.mount_gid + mount_ip = var.mount_ip + mount_msize = var.mount_msize + mount_options = var.mount_options + mount_port = var.mount_port + mount_string = var.mount_string + mount_type = var.mount_type + mount_uid = var.mount_uid + namespace = var.namespace + nat_nic_type = var.nat_nic_type + native_ssh = var.native_ssh + network = var.network + nfs_share = var.nfs_share + nfs_shares_root = var.nfs_shares_root + no_kubernetes = var.no_kubernetes + no_vtx_check = var.no_vtx_check + nodes = var.nodes + output = var.output + ports = var.ports + preload = var.preload + qemu_firmware_path = var.qemu_firmware_path + registry_mirror = var.registry_mirror + service_cluster_ip_range = var.service_cluster_ip_range + socket_vmnet_client_path = var.socket_vmnet_client_path + socket_vmnet_path = var.socket_vmnet_path + ssh_ip_address = var.ssh_ip_address + ssh_key = var.ssh_key + ssh_port = var.ssh_port + ssh_user = var.ssh_user + static_ip = var.static_ip + subnet = var.subnet + trace = var.trace + uuid = var.uuid + vm = var.vm + wait = var.wait + wait_timeout = var.wait_timeout +} diff --git a/modules/minikube_cluster/outputs.tf b/modules/minikube_cluster/outputs.tf new file mode 100644 index 0000000..f5e5830 --- /dev/null +++ b/modules/minikube_cluster/outputs.tf @@ -0,0 +1,27 @@ +output "client_certificate" { + value = minikube_cluster.default.client_certificate + description = "Cluster client certificate" + sensitive = true +} + +output "client_key" { + value = minikube_cluster.default.client_key + description = "Cluster client key" + sensitive = true +} + +output "cluster_ca_certificate" { + value = minikube_cluster.default.cluster_ca_certificate + description = "Cluster certificate authority certificate" + sensitive = true +} + +output "host" { + value = minikube_cluster.default.host + description = "Cluster host" +} + +output "id" { + value = minikube_cluster.default.id + description = "Cluster resource ID" +} diff --git a/modules/minikube_cluster/variables.tf b/modules/minikube_cluster/variables.tf new file mode 100644 index 0000000..6c0cf7d --- /dev/null +++ b/modules/minikube_cluster/variables.tf @@ -0,0 +1,704 @@ +variable "addons" { + type = set(string) + description = "" + default = ["default-storageclass", "storage-provisioner"] + nullable = false + + # todo: validate addons +} + +variable "apiserver_ips" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "apiserver_name" { + type = string + description = "" + default = "minikubeCA" + nullable = false +} + +variable "apiserver_names" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "apiserver_port" { + type = number + description = "" + default = 8443 + nullable = false +} + +variable "auto_pause_interval" { + type = number + description = "" + default = 1 + nullable = false +} + +variable "auto_update_drivers" { + type = bool + description = "" + default = true + nullable = false +} + +variable "base_image" { + type = string + description = "" + default = null + nullable = true +} + +variable "binary_mirror" { + type = string + description = "" + default = null + nullable = true +} + +variable "cache_images" { + type = bool + description = "" + default = true + nullable = false +} + +variable "cert_expiration" { + type = number + description = "" + default = 1576800 + nullable = false +} + +variable "cluster_name" { + type = string + description = "" + default = "minikube" + nullable = false +} + +variable "cni" { + type = string + description = "" + default = "auto" + nullable = false + + # todo: validate cni +} + +variable "container_runtime" { + type = string + description = "" + default = "docker" + nullable = false + + # todo: validate container_runtime +} + +variable "cpus" { + type = number + description = "" + default = 2 + nullable = false +} + +variable "cri_socket" { + type = string + description = "" + default = null + nullable = true +} + +variable "delete_on_failure" { + type = bool + description = "" + default = false + nullable = false +} + +variable "disable_driver_mounts" { + type = bool + description = "" + default = false + nullable = false +} + +variable "disable_metrics" { + type = bool + description = "" + default = false + nullable = false +} + +variable "disable_optimizations" { + type = bool + description = "" + default = false + nullable = false +} + +variable "disk_size" { + type = string + description = "" + default = "20000mb" + nullable = false + + # todo: validate disk_size +} + +variable "dns_domain" { + type = string + description = "" + default = "cluster.local" + nullable = false +} + +variable "dns_proxy" { + type = bool + description = "" + default = false + nullable = false +} + +variable "docker_env" { + type = set(string) + description = "" + default = null + nullable = true +} + +variable "docker_opt" { + type = set(string) + description = "" + default = null + nullable = true +} + +variable "download_only" { + type = bool + description = "" + default = false + nullable = false +} + +variable "driver" { + type = string + description = "" + default = "docker" + nullable = false + + # todo: validate driver +} + +variable "dry_run" { + type = bool + description = "" + default = false + nullable = false +} + +variable "embed_certs" { + type = bool + description = "" + default = false + nullable = false +} + +variable "extra_config" { + type = set(string) + description = "" + default = [] + nullable = false + + # todo: validate extra_config +} + +variable "extra_disks" { + type = number + description = "" + default = 0 + nullable = false + + # todo: validate driver for extra_disks +} + +variable "feature_gates" { + type = string + description = "" + default = null + nullable = true +} + +variable "force" { + type = bool + description = "" + default = false + nullable = false +} + +variable "force_systemd" { + type = bool + description = "" + default = false + nullable = false +} + +variable "gpus" { + type = string + description = "" + default = null + nullable = true + + # todo: validate gpus +} + +variable "ha" { + type = bool + description = "" + default = null + nullable = true +} + +variable "host_dns_resolver" { + type = bool + description = "" + default = true + nullable = false +} + +variable "host_only_cidr" { + type = string + description = "" + default = "192.168.59.1/24" + nullable = false +} + +variable "host_only_nic_type" { + type = string + description = "" + default = "virtio" + nullable = false +} + +variable "hyperkit_vpnkit_sock" { + type = string + description = "" + default = null + nullable = true +} + +variable "hyperkit_vsock_ports" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "hyperv_external_adapter" { + type = string + description = "" + default = null + nullable = true +} + +variable "hyperv_use_external_switch" { + type = bool + description = "" + default = false + nullable = false +} + +variable "hyperv_virtual_switch" { + type = string + description = "" + default = null + nullable = true +} + +variable "image_mirror_country" { + type = string + description = "" + default = null + nullable = true +} + +variable "image_repository" { + type = string + description = "" + default = null + nullable = true +} + +variable "insecure_registry" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "install_addons" { + type = bool + description = "" + default = true + nullable = false +} + +variable "interactive" { + type = bool + description = "" + default = true + nullable = false +} + +variable "iso_url" { + type = set(string) + description = "" + default = null + nullable = true +} + +variable "keep_context" { + type = bool + description = "" + default = false + nullable = false +} + +variable "kubernetes_version" { + type = string + description = "" + default = null + nullable = true + + # todo: validate kubernetes_version +} + +variable "kvm_gpu" { + type = bool + description = "" + default = false + nullable = false +} + +variable "kvm_hidden" { + type = bool + description = "" + default = false + nullable = false +} + +variable "kvm_network" { + type = string + description = "" + default = "default" + nullable = false +} + +variable "kvm_numa_count" { + type = number + description = "" + default = 1 + nullable = false +} + +variable "kvm_qemu_uri" { + type = string + description = "" + default = "qemu:///system" + nullable = false +} + +variable "listen_address" { + type = string + description = "" + default = null + nullable = true +} + +variable "memory" { + type = string + description = "" + default = "4096mb" + nullable = false + + # todo: validate memory +} + +variable "mount" { + type = bool + description = "" + default = false + nullable = false +} + +variable "mount_9p_version" { + type = string + description = "" + default = "9p2000.L" + nullable = false +} + +variable "mount_gid" { + type = string + description = "" + default = "docker" + nullable = false +} + +variable "mount_ip" { + type = string + description = "" + default = null + nullable = true +} + +variable "mount_msize" { + type = number + description = "" + default = 262144 + nullable = false +} + +variable "mount_options" { + type = set(string) + description = "" + default = null + nullable = true +} + +variable "mount_port" { + type = number + description = "" + default = 0 + nullable = false +} + +variable "mount_string" { + type = string + description = "" + default = "/home:/minikube-host" + nullable = false +} + +variable "mount_type" { + type = string + description = "" + default = "9p" + nullable = false +} + +variable "mount_uid" { + type = string + description = "" + default = "docker" + nullable = false +} + +variable "namespace" { + type = string + description = "" + default = "default" + nullable = false +} + +variable "nat_nic_type" { + type = string + description = "" + default = "virtio" + nullable = false + + # todo: validate nat_nic_type +} + +variable "native_ssh" { + type = bool + description = "" + default = true + nullable = false +} + +variable "network" { + type = string + description = "" + default = null + nullable = true +} + +variable "nfs_share" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "nfs_shares_root" { + type = string + description = "" + default = "/nfsshares" + nullable = false +} + +variable "no_kubernetes" { + type = bool + description = "" + default = false + nullable = false +} + +variable "no_vtx_check" { + type = bool + description = "" + default = false + nullable = false +} + +variable "nodes" { + type = number + description = "" + default = 1 + nullable = false +} + +variable "output" { + type = string + description = "" + default = "text" + nullable = false + + # todo: validate output +} + +variable "ports" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "preload" { + type = bool + description = "" + default = true + nullable = false +} + +variable "qemu_firmware_path" { + type = string + description = "" + default = null + nullable = true +} + +variable "registry_mirror" { + type = set(string) + description = "" + default = [] + nullable = false +} + +variable "service_cluster_ip_range" { + type = string + description = "" + default = "10.96.0.0/12" + nullable = false +} + +variable "socket_vmnet_client_path" { + type = string + description = "" + default = "/usr/local/opt/socket_vmnet/bin/socket_vmnet_client" + nullable = false +} + +variable "socket_vmnet_path" { + type = string + description = "" + default = "/usr/local/var/run/socket_vmnet" + nullable = false +} + +variable "ssh_ip_address" { + type = string + description = "" + default = null + nullable = true +} + +variable "ssh_key" { + type = string + description = "" + default = null + nullable = true +} + +variable "ssh_port" { + type = number + description = "" + default = 22 + nullable = false +} + +variable "ssh_user" { + type = string + description = "" + default = "root" + nullable = false +} + +variable "static_ip" { + type = string + description = "" + default = null + nullable = true +} + +variable "subnet" { + type = string + description = "" + default = null + nullable = true +} + +variable "trace" { + type = string + description = "" + default = null + nullable = true +} + +variable "uuid" { + type = string + description = "" + default = null + nullable = true +} + +variable "vm" { + type = bool + description = "" + default = false + nullable = false +} + +variable "wait" { + type = set(string) + description = "" + default = null + nullable = true + + # todo: validate wait +} + +variable "wait_timeout" { + type = number + description = "" + default = 6 + nullable = false +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..22216aa --- /dev/null +++ b/outputs.tf @@ -0,0 +1,10 @@ +# todo: output masked sensitive values to show existence +output "minikube_clusters" { + value = { + for k, v in module.minikube_cluster : k => { + host : v.host, + id : v.id + } + } + description = "A set of minikube clusters" +} diff --git a/providers.tf b/providers.tf new file mode 100644 index 0000000..064fe5b --- /dev/null +++ b/providers.tf @@ -0,0 +1,3 @@ +provider "minikube" { + kubernetes_version = "1.30.0" +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..c8b06df --- /dev/null +++ b/variables.tf @@ -0,0 +1,105 @@ +variable "minikube_clusters" { + type = map(object({ + addons = optional(set(string)) + apiserver_ips = optional(set(string)) + apiserver_name = optional(string) + apiserver_names = optional(set(string)) + apiserver_port = optional(number) + auto_pause_interval = optional(number) + auto_update_drivers = optional(bool) + base_image = optional(string) + binary_mirror = optional(string) + cache_images = optional(bool) + cert_expiration = optional(number) + cluster_name = optional(string) + cni = optional(string) + container_runtime = optional(string) + cpus = optional(number) + cri_socket = optional(string) + delete_on_failure = optional(bool) + disable_driver_mounts = optional(bool) + disable_metrics = optional(bool) + disable_optimizations = optional(bool) + disk_size = optional(string) + dns_domain = optional(string) + dns_proxy = optional(bool) + docker_env = optional(set(string)) + docker_opt = optional(set(string)) + download_only = optional(bool) + driver = optional(string) + dry_run = optional(bool) + embed_certs = optional(bool) + extra_config = optional(set(string)) + extra_disks = optional(number) + feature_gates = optional(string) + force = optional(bool) + force_systemd = optional(bool) + gpus = optional(string) + ha = optional(bool) + host_dns_resolver = optional(bool) + host_only_cidr = optional(string) + host_only_nic_type = optional(string) + hyperkit_vpnkit_sock = optional(string) + hyperkit_vsock_ports = optional(set(string)) + hyperv_external_adapter = optional(string) + hyperv_use_external_switch = optional(bool) + hyperv_virtual_switch = optional(string) + image_mirror_country = optional(string) + image_repository = optional(string) + insecure_registry = optional(set(string)) + install_addons = optional(bool) + interactive = optional(bool) + iso_url = optional(set(string)) + keep_context = optional(bool) + kubernetes_version = optional(string) + kvm_gpu = optional(bool) + kvm_hidden = optional(bool) + kvm_network = optional(string) + kvm_numa_count = optional(number) + kvm_qemu_uri = optional(string) + listen_address = optional(string) + memory = optional(string) + mount = optional(bool) + mount_9p_version = optional(string) + mount_gid = optional(string) + mount_ip = optional(string) + mount_msize = optional(number) + mount_options = optional(set(string)) + mount_port = optional(number) + mount_string = optional(string) + mount_type = optional(string) + mount_uid = optional(string) + namespace = optional(string) + nat_nic_type = optional(string) + native_ssh = optional(bool) + network = optional(string) + nfs_share = optional(set(string)) + nfs_shares_root = optional(string) + no_kubernetes = optional(bool) + no_vtx_check = optional(bool) + nodes = optional(number) + output = optional(string) + ports = optional(set(string)) + preload = optional(bool) + qemu_firmware_path = optional(string) + registry_mirror = optional(set(string)) + service_cluster_ip_range = optional(string) + socket_vmnet_client_path = optional(string) + socket_vmnet_path = optional(string) + ssh_ip_address = optional(string) + ssh_key = optional(string) + ssh_port = optional(number) + ssh_user = optional(string) + static_ip = optional(string) + subnet = optional(string) + trace = optional(string) + uuid = optional(string) + vm = optional(bool) + wait = optional(set(string)) + wait_timeout = optional(number) + }) + ) + description = "Minikube clusters" + default = {} + nullable = false +}