Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
torvitas committed Nov 3, 2022
0 parents commit ddfc00a
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# .terraform-docs.yml
formatter: markdown table

output:
file: README.md
mode: inject
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS -->
content: |-
{{ .Header }}
{{ .Inputs }}
{{ .Outputs }}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- BEGIN_TF_DOCS -->


## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_olm_version"></a> [olm\_version](#input\_olm\_version) | Version of the operator lifecycle manager. | `string` | `"v0.18.3"` | no |

## Outputs

No outputs.
<!-- END_TF_DOCS -->
77 changes: 77 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ddfc00a

Please sign in to comment.