Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea/
*.iml
34 changes: 6 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
# Starter kit for a Terraform module
# Cloud Pak Platform Navigator

This is a Starter kit to help with the creation of Terraform modules. The basic structure of a Terraform module is fairly
simple and consists of the following basic values:

- README.md - provides a description of the module
- main.tf - defiens the logic for the module
- variables.tf (optional) - defines the input variables for the module
- outputs.tf (optional) - defines the values that are output from the module

Beyond those files, any other content can be added and organized however you see fit. For example, you can add a `scripts/` directory
that contains shell scripts executed by a `local-exec` `null_resource` in the terraform module. The contents will depend on what your
module does and how it does it.

## Instructions for creating a new module

1. Update the title and description in the README to match the module you are creating
2. Fill out the remaining sections in the README template as appropriate
3. Implement your logic in the in the main.tf, variables.tf, and outputs.tf
4. Use releases/tags to manage release versions of your module

## Software dependencies

Expand All @@ -39,21 +22,16 @@ This module makes use of the output from other modules:

- Cluster - github.com/ibm-garage-cloud/terraform-ibm-container-platform.git
- Namespace - github.com/ibm-garage-clout/terraform-cluster-namespace.git
- etc

## Example usage

```hcl-terraform
module "dev_tools_argocd" {
source = "github.com/ibm-garage-cloud/terraform-tools-argocd.git?ref=v1.0.0"
module "platform-navigator" {
source = "github.com/ibm-garage-cloud/terraform-ibm-cp-platform-navigator.git"

catalog_name = module.cp4i.name
cluster_type = module.dev_cluster.type_code
cluster_config_file = module.dev_cluster.config_file_path
cluster_type = module.dev_cluster.type
app_namespace = module.dev_cluster_namespaces.tools_namespace_name
ingress_subdomain = module.dev_cluster.ingress_hostname
olm_namespace = module.dev_software_olm.olm_namespace
operator_namespace = module.dev_software_olm.target_namespace
name = "argocd"
namespace = module.dev_capture_tools_state.namespace
}
```

87 changes: 87 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
locals {
tmp_dir = "${path.cwd}/.tmp"
gitops_dir = var.gitops_dir != "" ? "${var.gitops_dir}/platform-navigator" : "${path.cwd}/gitops/app-connect"
subscription_file = "${local.gitops_dir}/subscription.yaml"
instance_file = "${local.gitops_dir}/instance.yaml"
instance_name = "integration-navigator"
subscription = {
apiVersion = "operators.coreos.com/v1alpha1"
kind = "Subscription"
metadata = {
name = "ibm-integration-platform-navigator"
namespace = "openshift-operators"
}
spec = {
channel = "v4.0"
installPlanApproval = "Automatic"
name = "ibm-integration-platform-navigator"
source = var.catalog_name
sourceNamespace = "openshift-marketplace"
}
}
instance = {
apiVersion = "integration.ibm.com/v1beta1"
kind = "PlatformNavigator"
metadata = {
name = local.instance_name
}
spec = {
license = {
accept = true
}
mqDashboard = true
replicas = 3
version = "2020.3.1"
}
}
}

resource "null_resource" "create_dirs" {
provisioner "local-exec" {
command = "mkdir -p ${local.tmp_dir}"
}

provisioner "local-exec" {
command = "mkdir -p ${local.gitops_dir}"
}
}

resource local_file subscription_yaml {
depends_on = [null_resource.create_dirs]

filename = local.subscription_file

content = yamlencode(local.subscription)
}

resource "null_resource" "create_subscription" {
depends_on = [local_file.subscription_yaml]

provisioner "local-exec" {
command = "kubectl apply -n ${var.namespace} -f ${local.subscription_file} && ${path.module}/scripts/wait-for-csv.sh ${var.namespace} ibm-integration-platform-navigator"

environment = {
KUBECONFIG = var.cluster_config_file
}
}
}

resource local_file instance_yaml {
depends_on = [null_resource.create_dirs]

filename = local.instance_file

content = yamlencode(local.instance)
}

resource "null_resource" "create_instance" {
depends_on = [null_resource.create_subscription, local_file.instance_yaml]

provisioner "local-exec" {
command = "kubectl apply -n ${var.namespace} -f ${local.instance_file} && ${path.module}/scripts/wait-for-deployment.sh ${var.namespace} integration-navigator"

environment = {
KUBECONFIG = var.cluster_config_file
}
}
}
82 changes: 37 additions & 45 deletions module.yaml
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
name: ""
name: ibm-cp-platform-navigator
type: terraform
description: ""
description: Module to install the Cloud Pak Platform Navigator
tags:
- tools
- devops
versions:
- platforms:
- kubernetes
- ocp3
- ocp4
dependencies: []
# - id: cluster
# refs:
# - source: github.com/ibm-garage-cloud/terraform-ibm-container-platform
# version: ">= 1.7.0"
# - source: github.com/ibm-garage-cloud/terraform-k8s-ocp-cluster
# version: ">= 2.0.0"
# - id: namespace
# refs:
# - source: github.com/ibm-garage-cloud/terraform-k8s-namespace
# version: ">= 2.1.0"
# - id: dashboard
# refs:
# - source: github.com/ibm-garage-cloud/terraform-k8s-dashboard
# version: ">= 1.6.0"
variables: []
# - name: cluster_type
# moduleRef:
# id: cluster
# output: type_code
# - name: cluster_ingress_hostname
# moduleRef:
# id: cluster
# output: ingress_hostname
# - name: cluster_config_file
# moduleRef:
# id: cluster
# output: config_file_path
# - name: tls_secret_name
# moduleRef:
# id: cluster
# output: tls_secret_name
# - name: releases_namespace
# moduleRef:
# id: namespace
# output: name
# discriminator: tools
# - name: icon_url
# moduleRef:
# id: dashboard
# output: base_icon_url
dependencies:
- id: cluster
refs:
- source: github.com/ibm-garage-cloud/terraform-ibm-container-platform
version: ">= 1.7.0"
- source: github.com/ibm-garage-cloud/terraform-k8s-ocp-cluster
version: ">= 2.0.0"
- id: namespace
refs:
- source: github.com/ibm-garage-cloud/terraform-k8s-namespace
version: ">= 2.1.0"
- id: cp-catalog
refs:
- source: github.com/ibm-garage-cloud/terraform-ibm-cp-catalog
version: ">= 1.0.0"
variables:
- name: cluster_type
moduleRef:
id: cluster
output: type_code
- name: cluster_config_file
moduleRef:
id: cluster
output: config_file_path
- name: namespace
moduleRef:
id: namespace
output: name
discriminator: cloud-pak
- name: catalog_name
moduleRef:
id: cp-catalog
output: name
- name: gitops_dir
scope: global
16 changes: 11 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#output "myoutput" {
# description = "Description of my output"
# value = "value"
# depends_on = [<some resource>]
#}
output "name" {
description = "Platform navigator instance name"
value = local.instance_name
depends_on = [null_resource.create_instance]
}

output "namespace" {
description = "Platform navigator instance namespace"
value = var.namespace
depends_on = [null_resource.create_instance]
}
17 changes: 17 additions & 0 deletions scripts/wait-for-csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

NAMESPACE="$1"
NAME="$2"

retries=10
while [[ $(kubectl get csv -n "${NAMESPACE}" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -c "${NAME}") -eq 0 ]] && \
[[ "${retries}" -gt 0 ]]; do
echo "Waiting for ${NAME} csv to be created"
retries=$(( retries - 1))
sleep 30
done

if [[ $(kubectl get csv -n "${NAMESPACE}" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep -c "${NAME}") -eq 0 ]]; then
echo "Timed out waiting for ${NAME} csv to be created"
exit 1
fi
13 changes: 13 additions & 0 deletions scripts/wait-for-deployment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

NAMESPACE="$1"
NAME="$2"

DEPLOYMENT_NAME=$(kubectl get deployment -n "${NAMESPACE}" -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | grep "${NAME}" | head -1)

if [[ -z "${DEPLOYMENT_NAME}" ]]; then
echo "Unable to find deployment: ${NAME}"
exit 1
fi

kubectl rollout status "deployment/${DEPLOYMENT_NAME}" -w
7 changes: 7 additions & 0 deletions test/stages/stage2-cp4i.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "cp4i" {
source = "github.com/ibm-garage-cloud/terraform-ibm-cp-catalog"

cluster_config_file = module.dev_cluster.config_file_path
release_namespace = module.dev_capture_tools_state.namespace
entitlement_key = var.entitlement_key
}
3 changes: 0 additions & 3 deletions test/stages/stage2-mymodule.tf

This file was deleted.

8 changes: 8 additions & 0 deletions test/stages/stage2-platform-navigator.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module "platform-navigator" {
source = "./module"

catalog_name = module.cp4i.name
cluster_type = module.dev_cluster.type_code
cluster_config_file = module.dev_cluster.config_file_path
namespace = module.dev_capture_tools_state.namespace
}
6 changes: 6 additions & 0 deletions test/stages/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,9 @@ variable "vpc_cluster" {
description = "Flag indicating that this is a vpc cluster"
default = false
}

variable "entitlement_key" {
type = string
description = "The entitlement key used to access the CP4I images in the container registry. Visit https://myibm.ibm.com/products-services/containerlibrary to get the key"
default = ""
}
32 changes: 27 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#variable "myvariable" {
# type = string
# description = "A description of my variable"
# default = ""
#}
variable "catalog_name" {
type = string
description = "The name of the Cloud Pak catalog"
default = "ibm-operator-catalog"
}

variable "cluster_type" {
type = string
description = "The type of cluster"
default = "ocp4"
}

variable "cluster_config_file" {
type = string
description = "The location of the kube config"
}

variable "namespace" {
type = string
description = "The namespace where the platform navigator should be installed"
default = "cp4i"
}

variable "gitops_dir" {
type = string
description = "The directory where the gitops configuration should be stored"
default = ""
}