diff --git a/.github/workflows/verify-pr.yaml b/.github/workflows/verify-pr.yaml index 171836a..df97301 100644 --- a/.github/workflows/verify-pr.yaml +++ b/.github/workflows/verify-pr.yaml @@ -14,7 +14,7 @@ jobs: if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }} uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-gitops-module.yaml@v1 with: - testcase: ocp4_latest_gitops_db2wh + testcase: ocp4_latest_gitops_db2 secrets: GIT_ORG: ${{ secrets.GIT_ORG }} AWS_CLUSTER_USERNAME: ${{ secrets.AWS_CLUSTER_USERNAME }} diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 3f3f879..a735267 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -12,7 +12,7 @@ jobs: if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }} uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-gitops-module.yaml@v1 with: - testcase: ocp4_latest_gitops_db2wh + testcase: ocp4_latest_gitops_db2 secrets: GIT_ORG: ${{ secrets.GIT_ORG }} AWS_CLUSTER_USERNAME: ${{ secrets.AWS_CLUSTER_USERNAME }} diff --git a/main.tf b/main.tf index 539c2f1..6de2dfd 100644 --- a/main.tf +++ b/main.tf @@ -1,144 +1,16 @@ -resource "random_string" "db2id" { - numeric = true - special = false - upper = false - lower = false - length = 4 -} - -locals { - name = "cp-db2" - bin_dir = module.setup_clis.bin_dir - yaml_dir = "${path.cwd}/.tmp/${local.name}/chart/${local.name}" - #db2instanceid = timestamp() - db2instanceid = "${local.name}-${random_string.db2id.result}" - dbconnectionhost = "${var.dbconnectionhostprefix}-${local.db2instanceid}-${var.dbconnectionhostsuffix}" - defaultuserpaswrd=var.defaultuserpwd - values_content = { - jobName = "${local.name}-job" - ConfigmapName = "${local.name}-script-configmap" - storageClassName = var.storageClass - namespace = var.namespace - database_name = var.database_name - InstanceSecret = local.defaultuserpaswrd - InstanceType = var.db2instancetype - InstanceVersion = var.db2instanceversion - InstanceId = local.db2instanceid - CPDClusterHost = var.cp4dclusterhost - DatabaseHost = var.db2host - pvcsize = var.pvcsize - operator_namespace = var.cpd_operator_namespace - } - layer = "services" - type = "base" - application_branch = "main" - namespace = var.namespace - layer_config = var.gitops_config[local.layer] -} - -module setup_clis { - source = "github.com/cloud-native-toolkit/terraform-util-clis.git" -} - -resource null_resource create_yaml { - provisioner "local-exec" { - command = "${path.module}/scripts/create-yaml.sh '${local.name}' '${local.yaml_dir}'" - - environment = { - VALUES_CONTENT = yamlencode(local.values_content) - } - } -} - -resource null_resource setup_gitops { - depends_on = [null_resource.create_yaml] - - triggers = { - name = local.name - namespace = var.namespace - yaml_dir = local.yaml_dir - server_name = var.server_name - layer = local.layer - type = local.type - git_credentials = yamlencode(var.git_credentials) - gitops_config = yamlencode(var.gitops_config) - bin_dir = local.bin_dir - } - - provisioner "local-exec" { - command = "${self.triggers.bin_dir}/igc gitops-module '${self.triggers.name}' -n '${self.triggers.namespace}' --contentDir '${self.triggers.yaml_dir}' --serverName '${self.triggers.server_name}' -l '${self.triggers.layer}' --type '${self.triggers.type}'" - - environment = { - GIT_CREDENTIALS = nonsensitive(self.triggers.git_credentials) - GITOPS_CONFIG = self.triggers.gitops_config - } - } - - provisioner "local-exec" { - when = destroy - command = "${self.triggers.bin_dir}/igc gitops-module '${self.triggers.name}' -n '${self.triggers.namespace}' --delete --contentDir '${self.triggers.yaml_dir}' --serverName '${self.triggers.server_name}' -l '${self.triggers.layer}' --type '${self.triggers.type}'" - - environment = { - GIT_CREDENTIALS = nonsensitive(self.triggers.git_credentials) - GITOPS_CONFIG = self.triggers.gitops_config - } - } -} - - - - -module setup_instance_service_account { - source = "github.com/cloud-native-toolkit/terraform-gitops-service-account.git" +module "cp4d_deployer" { + source = "github.com/cloud-native-toolkit/terraform-gitops-cp4d-deployer" gitops_config = var.gitops_config git_credentials = var.git_credentials - namespace = var.namespace - name = "db2wh-instance-sa" server_name = var.server_name - rbac_rules = [{ - apiGroups = ["*"] - resources = ["*"] - verbs = ["*"] - }] - rbac_cluster_scope = true -} - -module setup_instance_cpd_rbac { - source = "github.com/cloud-native-toolkit/terraform-gitops-rbac.git?ref=v1.7.1" - - gitops_config = var.gitops_config - git_credentials = var.git_credentials - service_account_namespace = module.setup_instance_service_account.namespace - service_account_name = module.setup_instance_service_account.name - namespace = module.setup_instance_service_account.namespace - rules = [ - { - apiGroups = ["*"] - resources = ["*"] - verbs = ["*"] - } - ] - server_name = var.server_name - cluster_scope = false -} + namespace = var.namespace + kubeseal_cert = var.kubeseal_cert -module setup_instance_operator_rbac { - source = "github.com/cloud-native-toolkit/terraform-gitops-rbac.git?ref=v1.7.1" - depends_on = [module.setup_instance_cpd_rbac] + entitlement_key = var.entitlement_key + cluster_name = var.cluster_name + cluster_ingress = var.ingress_subdomain + deployer_storage_class = var.storage_class - gitops_config = var.gitops_config - git_credentials = var.git_credentials - service_account_namespace = var.namespace - service_account_name = module.setup_instance_service_account.name - namespace = var.cpd_operator_namespace - rules = [ - { - apiGroups = ["*"] - resources = ["*"] - verbs = ["*"] - } - ] - server_name = var.server_name - cluster_scope = false + install_db2 = true } diff --git a/module.yaml b/module.yaml index ce2bab9..52c817d 100644 --- a/module.yaml +++ b/module.yaml @@ -13,6 +13,9 @@ versions: - ocp3 - ocp4 dependencies: + - id: cluster + interface: github.com/cloud-native-toolkit/automation-modules#cluster + refs: [] - id: gitops refs: - source: github.com/cloud-native-toolkit/terraform-tools-gitops.git @@ -21,10 +24,10 @@ versions: refs: - source: github.com/cloud-native-toolkit/terraform-gitops-namespace.git version: ">= 1.0.0" - - id: gitops-db2u + - id: storage refs: - - source: github.com/cloud-native-toolkit/terraform-gitops-cp-db2wh-service.git - version: ">= 1.0.0" + - source: github.com/cloud-native-toolkit/terraform-util-storage-class-manager.git + version: ">= 1.0.0" variables: - name: gitops_config moduleRef: @@ -46,18 +49,17 @@ versions: moduleRef: id: gitops output: sealed_secrets_cert - - name: storageClass + - name: storage_class moduleRef: - id: gitops-cp-db2 - output: storageClass - important: true - - name: database_name + id: storage + output: rwx_storage_class + - name: ingress_subdomain moduleRef: - id: gitops-cp-db2 - output: database_name - important: true - - name: pvcsize + id: cluster + output: platform.ingress + - name: cluster_name moduleRef: - id: gitops-cp-db2 - output: pvcsize - important: true + id: cluster + output: name + - name: entitlement_key + scope: global diff --git a/test/stages/stage1-cp-catalogs.tf b/test/stages/stage1-cp-catalogs.tf deleted file mode 100644 index 5abe9ae..0000000 --- a/test/stages/stage1-cp-catalogs.tf +++ /dev/null @@ -1,9 +0,0 @@ -#module "cp_catalogs" { - # source = "github.com/cloud-native-toolkit/terraform-gitops-cp-catalogs.git" - - #gitops_config = module.gitops.gitops_config - #git_credentials = module.gitops.git_credentials - #server_name = module.gitops.server_name - #kubeseal_cert = module.gitops.sealed_secrets_cert - #entitlement_key = var.cp_entitlement_key -#} diff --git a/test/stages/stage1-gitops-bootstrap.tf b/test/stages/stage1-gitops-bootstrap.tf index 9c13de7..9c9ad70 100644 --- a/test/stages/stage1-gitops-bootstrap.tf +++ b/test/stages/stage1-gitops-bootstrap.tf @@ -1,14 +1,17 @@ module "gitops-bootstrap" { - source = "github.com/cloud-native-toolkit/terraform-util-gitops-bootstrap.git" + source = "github.com/cloud-native-toolkit/terraform-tools-argocd-bootstrap.git" + cluster_type = module.dev_cluster.platform.type_code cluster_config_file = module.dev_cluster.config_file_path + ingress_subdomain = module.dev_cluster.platform.ingress + olm_namespace = module.dev_software_olm.olm_namespace + operator_namespace = module.dev_software_olm.target_namespace gitops_repo_url = module.gitops.config_repo_url git_username = module.gitops.config_username git_token = module.gitops.config_token bootstrap_path = module.gitops.bootstrap_path sealed_secret_cert = module.cert.cert sealed_secret_private_key = module.cert.private_key - prefix = var.bootstrap_prefix - kubeseal_namespace = var.kubeseal_namespace + bootstrap_prefix = var.bootstrap_prefix create_webhook = true } diff --git a/test/stages/stage1-olm.tf b/test/stages/stage1-olm.tf new file mode 100644 index 0000000..06c78ac --- /dev/null +++ b/test/stages/stage1-olm.tf @@ -0,0 +1,8 @@ +module "dev_software_olm" { + source = "github.com/ibm-garage-cloud/terraform-software-olm.git" + + cluster_config_file = module.dev_cluster.config_file_path + cluster_version = "" + cluster_type = module.dev_cluster.platform.type_code + olm_version = "0.15.1" +} diff --git a/test/stages/stage1-storage-manager.tf b/test/stages/stage1-storage-manager.tf new file mode 100644 index 0000000..a840042 --- /dev/null +++ b/test/stages/stage1-storage-manager.tf @@ -0,0 +1,8 @@ +module "storage_manager" { + source = "github.com/cloud-native-toolkit/terraform-util-storage-class-manager.git" + + rwx_storage_class = "" + rwo_storage_class = "" + file_storage_class = "" + block_storage_class = "ibmc-vpc-block-10iops-tier" +} diff --git a/test/stages/stage2-cp4d-operator.tf b/test/stages/stage2-cp4d-operator.tf deleted file mode 100644 index 4696e54..0000000 --- a/test/stages/stage2-cp4d-operator.tf +++ /dev/null @@ -1,14 +0,0 @@ - -## NOT NEEDED FOR CP4D CLUSTER - -# module "gitops_cp4d_operator" { -# depends_on = [ -# module.gitops_ibm_catalogs -# ] -# source = "github.com/cloud-native-toolkit/terraform-gitops-cp4d-operator" - -# gitops_config = module.gitops.gitops_config -# git_credentials = module.gitops.git_credentials -# server_name = module.gitops.server_name -# kubeseal_cert = module.gitops.sealed_secrets_cert -# } \ No newline at end of file diff --git a/test/stages/stage2-db2wh-service.tf b/test/stages/stage2-db2wh-service.tf deleted file mode 100644 index e8e6f04..0000000 --- a/test/stages/stage2-db2wh-service.tf +++ /dev/null @@ -1,14 +0,0 @@ -module "db2wh" { - source = "github.com/cloud-native-toolkit/terraform-gitops-cp-db2wh-service.git" - - gitops_config = module.gitops.gitops_config - git_credentials = module.gitops.git_credentials - server_name = module.gitops.server_name - namespace = module.gitops_namespace.name - kubeseal_cert = module.gitops.sealed_secrets_cert - - operator_namespace= var.operator_namespace - cpd_namespace = var.cpd_namespace - common_services_namespace = var.common_services_namespace - -} \ No newline at end of file diff --git a/test/stages/stage3-mymodule.tf b/test/stages/stage3-mymodule.tf index bd65395..fd47b31 100644 --- a/test/stages/stage3-mymodule.tf +++ b/test/stages/stage3-mymodule.tf @@ -1,17 +1,14 @@ module "gitops_module" { source = "./module" - depends_on = [module.db2wh] gitops_config = module.gitops.gitops_config git_credentials = module.gitops.git_credentials server_name = module.gitops.server_name - namespace = var.cpd_namespace + namespace = module.gitops_namespace.name kubeseal_cert = module.gitops.sealed_secrets_cert - storageClass = var.storageClass - database_name = var.database_name - pvcsize = var.pvcsize - - db2instancetype = "db2wh" - + storage_class = module.storage_manager.rwx_storage_class + ingress_subdomain = module.dev_cluster.platform.ingress + cluster_name = module.dev_cluster.name + entitlement_key = var.cp_entitlement_key } diff --git a/test/stages/variables.tf b/test/stages/variables.tf index dde8b15..6229304 100644 --- a/test/stages/variables.tf +++ b/test/stages/variables.tf @@ -198,4 +198,6 @@ resource null_resource write_namespace { } } - +variable "cp_entitlement_key" { + type = string +} diff --git a/variables.tf b/variables.tf index 8b12a74..5a808a8 100644 --- a/variables.tf +++ b/variables.tf @@ -80,76 +80,22 @@ variable "server_name" { default = "default" } -variable "storageClass" { +variable "storage_class" { type = string description = "The RWX/RWO Storage Class needed to create db2" } -variable "database_name" { +variable "ingress_subdomain" { type = string - description = "The name of the database to be created" + description = "The ingress subdomain of the cluster" } -variable "db2instancetype" { +variable "cluster_name" { type = string - description = "type of db2 intance to be created - db2oltp of db2wh" - default = "db2oltp" + description = "The name of the cluster where db2 will be installed" } -variable "db2instanceversion" { +variable "entitlement_key" { type = string - description = "version of the DB2 instance" - default = "11.5.7.0-x86_64" + description = "Cloud Pak entitlement key" } - -variable "defaultuserpwd" { - type = string - description = "Password of the default user" - default = "db2password" -} -variable "cp4dclusterhost" { - type = string - description = "The service name for cp4d" - default = "https://ibm-nginx-svc" -} - - -variable "db2host" { - type = string - description = "The https service name for database" - default = "https://database-core-svc:3025" -} - -variable "pvcsize" { - type = string - description = "The size of the pvc that needs to be created for db2" -} - -variable "dbconnectionhostprefix" { - type = string - description = "Prefix of the db2 connection host" - default = "c-db2oltp" -} - -variable "dbconnectionhostsuffix" { - type = string - description = "Suffix of the db2 connection host" - default = "db2u-engn-svc" -} - - -variable "cpd_operator_namespace" { - type = string - description = "Namespace for cpd commmon services" - default = "cpd-operators" -} - - - - - - - - - -