diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..16751aa --- /dev/null +++ b/.editorconfig @@ -0,0 +1,22 @@ +# 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 = 120 +trim_trailing_whitespace = true + +[*.{tf,tfvars}] +indent_size = 2 +indent_style = space + +[*.md] +trim_trailing_whitespace = false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a76c423 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,20 @@ +--- +repos: + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.72.2 + hooks: + - id: terraform_fmt + - id: terraform_tflint + - repo: https://github.com/terraform-docs/terraform-docs + rev: "v0.16.0" + hooks: + - id: terraform-docs-system + args: [./] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: check-added-large-files + - id: check-yaml + args: [--allow-multiple-documents] + - id: detect-private-key diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 0000000..a793bb9 --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,18 @@ +--- +# .terraform-docs.yml +formatter: markdown table + +output: + file: README.md + mode: inject + template: |- + + {{ .Content }} + + +content: |- + {{ .Header }} + + {{ .Inputs }} + + {{ .Outputs }} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..369857a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 E. Breuninger GmbH & Co. + +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 new file mode 100644 index 0000000..3dd2595 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ + + + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [olm\_version](#input\_olm\_version) | Version of the operator lifecycle manager. | `string` | `"v0.18.3"` | no | + +## Outputs + +No outputs. + diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..bbec6de --- /dev/null +++ b/main.tf @@ -0,0 +1,77 @@ +terraform { + required_version = "~>1.2" + required_providers { + http = { + source = "hashicorp/http" + version = "~> 3.2" + } + kubectl = { + source = "gavinbunney/kubectl" + version = "~> 1.14" + } + } +} + +variable "olm_version" { + type = string + description = "Version of the operator lifecycle manager." + default = "v0.18.3" +} + +locals { + olm_base_url = format( + "https://raw.githubusercontent.com/operator-framework/operator-lifecycle-manager/%s", + var.olm_version + ) + # Make sure dependencies are resolved correctly, this is important in context of terraform destroy to make sure the + # controller is not being deleted before the apiservice resource, otherwise some finalizers will never finalize. + olm_deployment_manifests = toset([ + "/api/v1/namespaces/olm", + "/api/v1/namespaces/operators", + "/api/v1/namespaces/olm/serviceaccounts/olm-operator-serviceaccount", + "/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/olm-operator-binding-olm", + "/apis/rbac.authorization.k8s.io/v1/clusterroles/system:controller:operator-lifecycle-manager", + "/apis/apps/v1/namespaces/olm/deployments/olm-operator" + ]) + olm_manifests = setsubtract(keys(data.kubectl_file_documents.olm.manifests), local.olm_deployment_manifests) +} + +data "http" "olm_crds" { + url = format("%s/deploy/upstream/quickstart/crds.yaml", local.olm_base_url) +} + +data "http" "olm" { + url = format("%s/deploy/upstream/quickstart/olm.yaml", local.olm_base_url) +} + +data "kubectl_file_documents" "olm_crds" { + content = data.http.olm_crds.response_body +} + +data "kubectl_file_documents" "olm" { + content = data.http.olm.response_body +} + +resource "kubectl_manifest" "olm_crds" { + for_each = data.kubectl_file_documents.olm_crds.manifests + yaml_body = each.value + wait = true +} + +resource "kubectl_manifest" "olm_deployment" { + for_each = local.olm_deployment_manifests + yaml_body = data.kubectl_file_documents.olm.manifests[each.value] + depends_on = [ + kubectl_manifest.olm_crds + ] + wait = true +} + +resource "kubectl_manifest" "olm" { + for_each = local.olm_manifests + yaml_body = data.kubectl_file_documents.olm.manifests[each.value] + depends_on = [ + kubectl_manifest.olm_deployment + ] + wait = true +}