From 4cd6596cab432812654392762b3aff6c8083b89b Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Thu, 7 Mar 2024 10:43:51 +0000 Subject: [PATCH 01/14] feat: init SKIP UPGRADE TEST: init module --- .github/CODEOWNERS | 2 +- README.md | 29 +++++++++-- examples/basic/README.md | 11 ----- examples/basic/main.tf | 24 --------- examples/basic/outputs.tf | 18 ------- examples/basic/provider.tf | 8 --- examples/basic/variables.tf | 33 ------------- examples/basic/version.tf | 12 ----- examples/complete/README.md | 8 ++- examples/complete/main.tf | 81 +++++++++++++++++++++++++++++- examples/complete/outputs.tf | 31 ++++++------ examples/complete/variables.tf | 8 ++- examples/complete/version.tf | 5 +- main.tf | 27 ++++++++-- outputs.tf | 25 +++++++--- tests/other_test.go | 18 ------- tests/pr_test.go | 10 +++- variables.tf | 90 ++++++++++++++++++++++++++++++---- version.tf | 15 +++--- 19 files changed, 273 insertions(+), 182 deletions(-) delete mode 100644 examples/basic/README.md delete mode 100644 examples/basic/main.tf delete mode 100644 examples/basic/outputs.tf delete mode 100644 examples/basic/provider.tf delete mode 100644 examples/basic/variables.tf delete mode 100644 examples/basic/version.tf delete mode 100644 tests/other_test.go diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1f65b1e..0c8b6e2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # Primary owner should be listed first in list of global owners, followed by any secondary owners -* @SirSpidey @ocofaigh +* @rajatagarwal-ibm @ocofaigh diff --git a/README.md b/README.md index c38da4e..f7a8e54 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,6 @@ TODO: Replace me with description of the module(s) in this repo ## Overview * [terraform-ibm-schematics-agent](#terraform-ibm-schematics-agent) * [Examples](./examples) - * [Basic example](./examples/basic) * [Complete example](./examples/complete) * [Contributing](#contributing) @@ -89,6 +88,7 @@ statement instead the previous block. | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.3.0, <1.7.0 | +| [ibm](#requirement\_ibm) | >= 1.49.0, < 2.0.0 | ### Modules @@ -96,15 +96,36 @@ No modules. ### Resources -No resources. +| Name | Type | +|------|------| +| [ibm_schematics_agent.schematics_agent_instance](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/schematics_agent) | resource | +| [ibm_schematics_agent_deploy.schematics_agent_deploy](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/schematics_agent_deploy) | resource | ### Inputs -No inputs. +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [agent\_description](#input\_agent\_description) | The schematics agent description. | `string` | `null` | no | +| [agent\_location](#input\_agent\_location) | The location where the schematics agent is deployed in the user environment. | `string` | `"us-south"` | no | +| [agent\_name](#input\_agent\_name) | The schematics agent name. | `string` | n/a | yes | +| [agent\_resource\_group\_id](#input\_agent\_resource\_group\_id) | The resource group ID of the schematics resource group. | `string` | n/a | yes | +| [agent\_version](#input\_agent\_version) | The schematics agent version. | `string` | `"1.0.1-beta"` | no | +| [cluster\_id](#input\_cluster\_id) | ID of the target cluster where the schematics agent will be installed. | `string` | n/a | yes | +| [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | Resource group ID of the target cluster where the schematics agent will be installed. | `string` | n/a | yes | +| [cos\_bucket\_name](#input\_cos\_bucket\_name) | The COS bucket name to store the schematics agent logs. | `string` | n/a | yes | +| [cos\_bucket\_region](#input\_cos\_bucket\_region) | The COS bucket region. | `string` | n/a | yes | +| [cos\_instance\_name](#input\_cos\_instance\_name) | The COS instance name where the bucket is created for the schematics agent logs. | `string` | n/a | yes | +| [infra\_type](#input\_infra\_type) | Type of target agent infrastructure. Allowed values: `ibm_kubernetes`, `ibm_openshift` and `ibm_satellite`. | `string` | `"ibm_kubernetes"` | no | +| [schematics\_location](#input\_schematics\_location) | List of locations supported by IBM Cloud Schematics service. Allowed values are `us-south`, `us-east`, `eu-gb`, `eu-de`. | `string` | `"us-south"` | no | ### Outputs -No outputs. +| Name | Description | +|------|-------------| +| [agent\_id](#output\_agent\_id) | Schematics agent ID. | +| [log\_url](#output\_log\_url) | URL to the full schematics agent deployment job logs. | +| [status\_code](#output\_status\_code) | Final result of the schematics agent deployment job. | +| [status\_message](#output\_status\_message) | The outcome of the schematics agent deployment job, in a formatted log string. | diff --git a/examples/basic/README.md b/examples/basic/README.md deleted file mode 100644 index 86eab8e..0000000 --- a/examples/basic/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Basic example - - - -An end-to-end basic example that will provision the following: -- A new resource group if one is not passed in. -- A new Cloud Object Storage instance. diff --git a/examples/basic/main.tf b/examples/basic/main.tf deleted file mode 100644 index 7d3404a..0000000 --- a/examples/basic/main.tf +++ /dev/null @@ -1,24 +0,0 @@ -######################################################################################################################## -# Resource group -######################################################################################################################## - -module "resource_group" { - source = "terraform-ibm-modules/resource-group/ibm" - version = "1.1.5" - # if an existing resource group is not set (null) create a new one using prefix - resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null - existing_resource_group_name = var.resource_group -} - -######################################################################################################################## -# COS instance -######################################################################################################################## - -resource "ibm_resource_instance" "cos_instance" { - name = "${var.prefix}-cos" - resource_group_id = module.resource_group.resource_group_id - service = "cloud-object-storage" - plan = "standard" - location = "global" - tags = var.resource_tags -} diff --git a/examples/basic/outputs.tf b/examples/basic/outputs.tf deleted file mode 100644 index 04b196e..0000000 --- a/examples/basic/outputs.tf +++ /dev/null @@ -1,18 +0,0 @@ -######################################################################################################################## -# Outputs -######################################################################################################################## - -output "cos_instance_id" { - description = "COS instance id" - value = ibm_resource_instance.cos_instance.id -} - -output "resource_group_name" { - description = "Resource group name" - value = module.resource_group.resource_group_name -} - -output "resource_group_id" { - description = "Resource group ID" - value = module.resource_group.resource_group_id -} diff --git a/examples/basic/provider.tf b/examples/basic/provider.tf deleted file mode 100644 index 84b6985..0000000 --- a/examples/basic/provider.tf +++ /dev/null @@ -1,8 +0,0 @@ -######################################################################################################################## -# Provider config -######################################################################################################################## - -provider "ibm" { - ibmcloud_api_key = var.ibmcloud_api_key - region = var.region -} diff --git a/examples/basic/variables.tf b/examples/basic/variables.tf deleted file mode 100644 index dd0d0af..0000000 --- a/examples/basic/variables.tf +++ /dev/null @@ -1,33 +0,0 @@ -######################################################################################################################## -# Input variables -######################################################################################################################## - -variable "ibmcloud_api_key" { - type = string - description = "The IBM Cloud API Key" - sensitive = true -} - -variable "region" { - type = string - description = "Region to provision all resources created by this example" - default = "us-south" -} - -variable "prefix" { - type = string - description = "Prefix to append to all resources created by this example" - default = "basic" -} - -variable "resource_group" { - type = string - description = "The name of an existing resource group to provision resources in to. If not set a new resource group will be created using the prefix variable" - default = null -} - -variable "resource_tags" { - type = list(string) - description = "Optional list of tags to be added to created resources" - default = [] -} diff --git a/examples/basic/version.tf b/examples/basic/version.tf deleted file mode 100644 index a557e04..0000000 --- a/examples/basic/version.tf +++ /dev/null @@ -1,12 +0,0 @@ -terraform { - required_version = ">= 1.3.0, <1.7.0" - - # Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main - # module's version.tf (usually a basic example), and 1 example that will always use the latest provider version. - required_providers { - ibm = { - source = "IBM-Cloud/ibm" - version = "1.49.0" - } - } -} diff --git a/examples/complete/README.md b/examples/complete/README.md index 139f8dd..355d243 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -1,4 +1,8 @@ # Complete example - - +An end-to-end example that will provision the following: +* A new resource group if one is not passed in. +* A COS instance and a bucket. +* A new VPC with 1 subnet. +* An IBM VPC Gen2 Kubernetes cluster with 3 worker nodes and flavor "bx2.4x16". +* Creates and deploy the Schematics' agent on the Kubernetes cluster. diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 558c210..0c5655d 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,3 +1,82 @@ +######################################################################################################################## +# Resource Group +######################################################################################################################## + +module "resource_group" { + source = "terraform-ibm-modules/resource-group/ibm" + version = "1.1.4" + # if an existing resource group is not set (null) create a new one using prefix + resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null + existing_resource_group_name = var.resource_group +} + ############################################################################## -# Complete example +# Create Cloud Object Storage instance and a bucket ############################################################################## + +module "cos" { + source = "terraform-ibm-modules/cos/ibm" + version = "7.4.3" + resource_group_id = module.resource_group.resource_group_id + region = "us-south" + cos_instance_name = "${var.prefix}-cos" + cos_tags = var.resource_tags + bucket_name = "${var.prefix}-bucket" + retention_enabled = false # disable retention for test environments - enable for stage/prod + kms_encryption_enabled = false +} + +############################################################################## +# VPC +############################################################################## + +resource "ibm_is_vpc" "vpc" { + name = "${var.prefix}-vpc" + resource_group = module.resource_group.resource_group_id + tags = var.resource_tags +} + +resource "ibm_is_subnet" "subnet" { + name = "${var.prefix}-subnet" + vpc = ibm_is_vpc.vpc.id + zone = "${var.region}-1" + total_ipv4_address_count = 256 + resource_group = module.resource_group.resource_group_id +} + +############################################################################## +# Create a Kubernetes cluster with 3 worker nodes +############################################################################## + +resource "ibm_container_vpc_cluster" "cluster" { + name = "${var.prefix}-cluster" + vpc_id = ibm_is_vpc.vpc.id + kube_version = "1.28.7" + flavor = "bx2.4x16" + resource_group_id = module.resource_group.resource_group_id + worker_count = 3 + zones { + subnet_id = ibm_is_subnet.subnet.id + name = "${var.region}-1" + } +} + +############################################################################## +# Create and deploy the Schematics agent +############################################################################## + +module "schematics_agent" { + source = "../../" + infra_type = "ibm_kubernetes" + cluster_id = ibm_container_vpc_cluster.cluster.id + cluster_resource_group_id = module.resource_group.resource_group_id + cos_instance_name = module.cos.cos_instance_name + cos_bucket_name = module.cos.bucket_name + cos_bucket_region = module.cos.bucket_region + agent_location = var.region + agent_description = "${var.prefix}-agent-description" + agent_name = "${var.prefix}-agent" + agent_resource_group_id = module.resource_group.resource_group_name + schematics_location = var.region # Allowed values are `us-south`, `us-east`, `eu-gb`, `eu-de`. + agent_version = var.agent_version +} diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf index addadea..560488f 100644 --- a/examples/complete/outputs.tf +++ b/examples/complete/outputs.tf @@ -1,23 +1,24 @@ -############################################################################## -# Outputs -############################################################################## +output "cluster_id" { + description = "Kubernetes cluster ID." + value = ibm_container_vpc_cluster.cluster.id +} -output "region" { - description = "The region all resources were provisioned in" - value = var.region +output "schematics_agent_id" { + description = "Schematics agent ID." + value = module.schematics_agent.agent_id } -output "prefix" { - description = "The prefix used to name all provisioned resources" - value = var.prefix +output "schematics_agent_job_log_url" { + description = "URL to the full schematics agent deployment job logs." + value = module.schematics_agent.log_url } -output "resource_group_name" { - description = "The name of the resource group used" - value = var.resource_group +output "schematics_agent_status_code" { + description = "Final result of the schematics agent deployment job." + value = module.schematics_agent.status_code } -output "resource_tags" { - description = "List of resource tags" - value = var.resource_tags +output "schematics_agent_status_message" { + description = "The outcome of the schematics agent deployment job, in a formatted log string." + value = module.schematics_agent.status_message } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 170a5ab..54dda83 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -13,7 +13,7 @@ variable "region" { variable "prefix" { type = string description = "Prefix to append to all resources created by this example" - default = "complete" + default = "rajat-com" } variable "resource_group" { @@ -27,3 +27,9 @@ variable "resource_tags" { description = "Optional list of tags to be added to created resources" default = [] } + +variable "agent_version" { + type = string + description = "The schematics agent version." + default = "1.0.1-beta" +} diff --git a/examples/complete/version.tf b/examples/complete/version.tf index d70a9d2..eae5139 100644 --- a/examples/complete/version.tf +++ b/examples/complete/version.tf @@ -1,12 +1,9 @@ terraform { required_version = ">= 1.3.0, <1.7.0" - - # Ensure that there is always 1 example locked into the lowest provider version of the range defined in the main - # module's version.tf (usually a basic example), and 1 example that will always use the latest provider version. required_providers { ibm = { source = "IBM-Cloud/ibm" - version = ">= 1.49.0, < 2.0.0" + version = ">= 1.59.0" } } } diff --git a/main.tf b/main.tf index 0b919ea..e0254bc 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,24 @@ -/******************************************************************** -This file is used to implement the ROOT module. -*********************************************************************/ +resource "ibm_schematics_agent" "schematics_agent_instance" { + agent_infrastructure { + infra_type = var.infra_type + cluster_id = var.cluster_id + cluster_resource_group = var.cluster_resource_group_id + cos_instance_name = var.cos_instance_name + cos_bucket_name = var.cos_bucket_name + cos_bucket_region = var.cos_bucket_region + } + agent_location = var.agent_location + description = var.agent_description + name = var.agent_name + resource_group = var.agent_resource_group_id + schematics_location = var.schematics_location + version = var.agent_version +} + +locals { + agent_id = join(".", slice(split(":", ibm_schematics_agent.schematics_agent_instance.agent_crn), 9, 10)) +} + +resource "ibm_schematics_agent_deploy" "schematics_agent_deploy" { + agent_id = local.agent_id +} diff --git a/outputs.tf b/outputs.tf index bb6ea66..ce8db3e 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,8 +1,19 @@ -######################################################################################################################## -# Outputs -######################################################################################################################## +output "agent_id" { + description = "Schematics agent ID." + value = local.agent_id +} -#output "myoutput" { -# description = "Description of my output" -# value = "value" -#} +output "log_url" { + description = "URL to the full schematics agent deployment job logs." + value = ibm_schematics_agent_deploy.schematics_agent_deploy.log_url +} + +output "status_code" { + description = "Final result of the schematics agent deployment job." + value = ibm_schematics_agent_deploy.schematics_agent_deploy.status_code +} + +output "status_message" { + description = "The outcome of the schematics agent deployment job, in a formatted log string." + value = ibm_schematics_agent_deploy.schematics_agent_deploy.status_message +} diff --git a/tests/other_test.go b/tests/other_test.go deleted file mode 100644 index d03784f..0000000 --- a/tests/other_test.go +++ /dev/null @@ -1,18 +0,0 @@ -// Tests in this file are NOT run in the PR pipeline. They are run in the continuous testing pipeline along with the ones in pr_test.go -package test - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestRunBasicExample(t *testing.T) { - t.Parallel() - - options := setupOptions(t, "mod-template-basic", "examples/basic") - - output, err := options.RunTestConsistency() - assert.Nil(t, err, "This should not have errored") - assert.NotNil(t, output, "Expected some output") -} diff --git a/tests/pr_test.go b/tests/pr_test.go index 896d726..0fb0103 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -2,6 +2,7 @@ package test import ( + "github.com/gruntwork-io/terratest/modules/terraform" "testing" "github.com/stretchr/testify/assert" @@ -25,17 +26,22 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio func TestRunCompleteExample(t *testing.T) { t.Parallel() - options := setupOptions(t, "mod-template", completeExampleDir) + options := setupOptions(t, "sa-com", completeExampleDir) output, err := options.RunTestConsistency() assert.Nil(t, err, "This should not have errored") assert.NotNil(t, output, "Expected some output") + + outputs := terraform.OutputAll(options.Testing, options.TerraformOptions) + + // Pass test only for "success" status code. Fail for "pending", "in-progress" & "failed" status. + assert.Equal(t, outputs["status_code"].(string), "job_success") } func TestRunUpgradeExample(t *testing.T) { t.Parallel() - options := setupOptions(t, "mod-template-upg", completeExampleDir) + options := setupOptions(t, "sa-com-upg", completeExampleDir) output, err := options.RunTestUpgrade() if !options.UpgradeTestSkipped { diff --git a/variables.tf b/variables.tf index df60434..e512a49 100644 --- a/variables.tf +++ b/variables.tf @@ -1,9 +1,81 @@ -######################################################################################################################## -# Input Variables -######################################################################################################################## - -#variable "my_variable" { -# type = string -# description = "A description of my variable" -# default = "default_value" -#} +variable "infra_type" { + type = string + description = "Type of target agent infrastructure. Allowed values: `ibm_kubernetes`, `ibm_openshift` and `ibm_satellite`." + default = "ibm_kubernetes" + validation { + condition = contains(["ibm_kubernetes", "ibm_openshift", "ibm_satellite"], var.infra_type) + error_message = "Allowed values for `infra_type` are \"ibm_kubernetes\", \"ibm_openshift\" and \"ibm_satellite\"." + } +} + +variable "cluster_id" { + type = string + description = "ID of the target cluster where the schematics agent will be installed." + nullable = false +} + +variable "cluster_resource_group_id" { + type = string + description = "Resource group ID of the target cluster where the schematics agent will be installed." + nullable = false +} + +variable "cos_instance_name" { + type = string + description = "The COS instance name where the bucket is created for the schematics agent logs." + nullable = false +} + +variable "cos_bucket_name" { + type = string + description = "The COS bucket name to store the schematics agent logs." + nullable = false +} + +variable "cos_bucket_region" { + type = string + description = "The COS bucket region." + nullable = false +} + +variable "agent_location" { + type = string + description = "The location where the schematics agent is deployed in the user environment." + default = "us-south" + nullable = false +} + +variable "agent_description" { + type = string + description = "The schematics agent description." + default = null +} + +variable "agent_name" { + type = string + description = "The schematics agent name." + nullable = false +} + +variable "agent_resource_group_id" { + type = string + description = "The resource group ID of the schematics resource group." + nullable = false +} + +variable "schematics_location" { + type = string + description = "List of locations supported by IBM Cloud Schematics service. Allowed values are `us-south`, `us-east`, `eu-gb`, `eu-de`." + default = "us-south" + validation { + condition = contains(["us-south", "us-east", "eu-gb", "eu-de"], var.schematics_location) + error_message = "Allowed values for `schematics_location` are \"us-south\", \"us-east\", \"eu-gb\" or \"eu-de\"." + } +} + +variable "agent_version" { + type = string + description = "The schematics agent version." + nullable = false + default = "1.0.1-beta" +} diff --git a/version.tf b/version.tf index d5cac67..9336894 100644 --- a/version.tf +++ b/version.tf @@ -1,12 +1,9 @@ terraform { required_version = ">= 1.3.0, <1.7.0" - # If your module requires any terraform providers, uncomment the "required_providers" section below and add all required providers. - # Each required provider's version should be a flexible range to future proof the module's usage with upcoming minor and patch versions. - - # required_providers { - # ibm = { - # source = "IBM-Cloud/ibm" - # version = ">= 1.49.0, < 2.0.0" - # } - # } + required_providers { + ibm = { + source = "IBM-Cloud/ibm" + version = ">= 1.49.0, < 2.0.0" + } + } } From 046466f0e621761d544b891e95fa159371debe2c Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Thu, 7 Mar 2024 10:45:17 +0000 Subject: [PATCH 02/14] feat: init SKIP UPGRADE TEST: init module --- .github/settings.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/settings.yml b/.github/settings.yml index 7b03ead..143346b 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -15,14 +15,14 @@ repository: # By changing this field, you rename the repository. # Uncomment this name property and set the name to the current repo name. - # name: "" + name: "terraform-ibm-schematics-agent" # The description is displayed under the repository name on the # organization page and in the 'About' section of the repository. # Uncomment this description property # and update the description to the current repo description. - # description: "" + description: "Creates a Schematics Agent and deploys it on the existing cluster." # Use a comma-separated list of topics to set on the repo (ensure not to use any caps in the topic string). - topics: terraform, ibm-cloud, terraform-module + topics: terraform, ibm-cloud, terraform-module, core-team From 697bc94d59fd2c041e3232437190559eb012a305 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Thu, 7 Mar 2024 11:05:12 +0000 Subject: [PATCH 03/14] feat: init SKIP UPGRADE TEST: init module --- cra-tf-validate-ignore-rules.json | 15 ++++++++++++++- examples/complete/main.tf | 8 ++++---- examples/complete/variables.tf | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cra-tf-validate-ignore-rules.json b/cra-tf-validate-ignore-rules.json index adbff6e..2c2ff9d 100644 --- a/cra-tf-validate-ignore-rules.json +++ b/cra-tf-validate-ignore-rules.json @@ -1,3 +1,16 @@ { - "scc_rules": [] + "scc_rules": [ + { + "scc_rule_id": "rule-8cbd597c-7471-42bd-9c88-36b2696456e9", + "description:": "Check whether Cloud Object Storage network access is restricted to a specific IP range", + "ignore_reason": "This module does not create any Cloud object storage and it is used in an example for testing purpose.", + "is_valid": false + }, + { + "scc_rule_id": "rule-c97259ee-336d-4c5f-b436-1868107a9558", + "description:": "Check whether Cloud Object Storage is enabled with customer-managed encryption and Keep Your Own Key (KYOK)", + "ignore_reason": "This module does not create any Cloud object storage and it is used in an example for testing purpose.", + "is_valid": false + } + ] } diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 0c5655d..446378f 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -1,6 +1,6 @@ -######################################################################################################################## +############################################################################ # Resource Group -######################################################################################################################## +############################################################################ module "resource_group" { source = "terraform-ibm-modules/resource-group/ibm" @@ -69,14 +69,14 @@ module "schematics_agent" { source = "../../" infra_type = "ibm_kubernetes" cluster_id = ibm_container_vpc_cluster.cluster.id - cluster_resource_group_id = module.resource_group.resource_group_id + cluster_resource_group_id = module.resource_group.resource_group_name cos_instance_name = module.cos.cos_instance_name cos_bucket_name = module.cos.bucket_name cos_bucket_region = module.cos.bucket_region agent_location = var.region agent_description = "${var.prefix}-agent-description" agent_name = "${var.prefix}-agent" - agent_resource_group_id = module.resource_group.resource_group_name + agent_resource_group_id = module.resource_group.resource_group_id schematics_location = var.region # Allowed values are `us-south`, `us-east`, `eu-gb`, `eu-de`. agent_version = var.agent_version } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 54dda83..c527949 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -13,7 +13,7 @@ variable "region" { variable "prefix" { type = string description = "Prefix to append to all resources created by this example" - default = "rajat-com" + default = "sa-com" } variable "resource_group" { From 34fef36d90cbb7a80d7c65f9b44d3cda0b4b2396 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Thu, 7 Mar 2024 11:23:53 +0000 Subject: [PATCH 04/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/pr_test.go b/tests/pr_test.go index 0fb0103..c8f08a5 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -12,6 +12,7 @@ import ( // Use existing resource group const resourceGroup = "geretain-test-resources" const completeExampleDir = "examples/complete" +const region = "us-south" func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptions { options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ @@ -19,6 +20,7 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio TerraformDir: dir, Prefix: prefix, ResourceGroup: resourceGroup, + Region: region, }) return options } From 772e93866393692d17014d7bda6e063640a50d03 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Thu, 7 Mar 2024 13:12:40 +0000 Subject: [PATCH 05/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index c8f08a5..5aceaaa 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -36,8 +36,7 @@ func TestRunCompleteExample(t *testing.T) { outputs := terraform.OutputAll(options.Testing, options.TerraformOptions) - // Pass test only for "success" status code. Fail for "pending", "in-progress" & "failed" status. - assert.Equal(t, outputs["status_code"].(string), "job_success") + assert.Equal(t, outputs["status_code"].(string), "job_finished") } func TestRunUpgradeExample(t *testing.T) { From 26ae28cc1ea5c51d5a3d9193542f1ce1b066f3fe Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 8 Mar 2024 08:52:17 +0000 Subject: [PATCH 06/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/pr_test.go b/tests/pr_test.go index 5aceaaa..3644a06 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -14,6 +14,11 @@ const resourceGroup = "geretain-test-resources" const completeExampleDir = "examples/complete" const region = "us-south" +// temporarily ignore destroy for schematics_agent_deploy as its currently in beta. +var ignoreDestroys = []string{ + "module.schematics_agent.ibm_schematics_agent_deploy.schematics_agent_deploy", +} + func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptions { options := testhelper.TestOptionsDefaultWithVars(&testhelper.TestOptions{ Testing: t, @@ -21,6 +26,9 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio Prefix: prefix, ResourceGroup: resourceGroup, Region: region, + IgnoreDestroys: testhelper.Exemptions{ + List: ignoreDestroys, + }, }) return options } From 9caadd945ea0f0d65aa86492977f514fdab60713 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 8 Mar 2024 10:39:17 +0000 Subject: [PATCH 07/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/pr_test.go b/tests/pr_test.go index 3644a06..6de8890 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -16,6 +16,7 @@ const region = "us-south" // temporarily ignore destroy for schematics_agent_deploy as its currently in beta. var ignoreDestroys = []string{ + "module.schematics_agent.ibm_schematics_agent.schematics_agent_instance", "module.schematics_agent.ibm_schematics_agent_deploy.schematics_agent_deploy", } From 4b3ddde6e497560344fd3765674cfa139faf3acb Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 8 Mar 2024 12:22:41 +0000 Subject: [PATCH 08/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index 6de8890..dc41df0 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -2,7 +2,6 @@ package test import ( - "github.com/gruntwork-io/terratest/modules/terraform" "testing" "github.com/stretchr/testify/assert" @@ -43,9 +42,12 @@ func TestRunCompleteExample(t *testing.T) { assert.Nil(t, err, "This should not have errored") assert.NotNil(t, output, "Expected some output") - outputs := terraform.OutputAll(options.Testing, options.TerraformOptions) - - assert.Equal(t, outputs["status_code"].(string), "job_finished") + outputs := options.LastTestTerraformOutputs + expectedOutputs := []string{"status_code"} + _, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...) + if assert.NoErrorf(t, outputErr, "Some outputs not found or nil.") { + assert.Equal(t, outputs["status_code"].(string), "job_finished") + } } func TestRunUpgradeExample(t *testing.T) { From 8c75dab66ebea03e8fd1308b51e36d0cd917f054 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 8 Mar 2024 13:34:29 +0000 Subject: [PATCH 09/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index dc41df0..7b06112 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -46,7 +46,7 @@ func TestRunCompleteExample(t *testing.T) { expectedOutputs := []string{"status_code"} _, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...) if assert.NoErrorf(t, outputErr, "Some outputs not found or nil.") { - assert.Equal(t, outputs["status_code"].(string), "job_finished") + assert.Equal(t, outputs["schematics_agent_status_code"].(string), "job_finished") } } From 2178fc96035346e2908d46b20b64fabc6a6f0d34 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 8 Mar 2024 14:50:42 +0000 Subject: [PATCH 10/14] feat: init SKIP UPGRADE TEST: init module --- tests/pr_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pr_test.go b/tests/pr_test.go index 7b06112..6840db2 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -43,7 +43,7 @@ func TestRunCompleteExample(t *testing.T) { assert.NotNil(t, output, "Expected some output") outputs := options.LastTestTerraformOutputs - expectedOutputs := []string{"status_code"} + expectedOutputs := []string{"schematics_agent_status_code"} _, outputErr := testhelper.ValidateTerraformOutputs(outputs, expectedOutputs...) if assert.NoErrorf(t, outputErr, "Some outputs not found or nil.") { assert.Equal(t, outputs["schematics_agent_status_code"].(string), "job_finished") From 9dce992e9e730092ba757fbc14989934856d7ff6 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Tue, 12 Mar 2024 21:38:27 +0000 Subject: [PATCH 11/14] feat: init SKIP UPGRADE TEST: init module --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f7a8e54..c96876a 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,21 @@ -# Terraform Modules Template Project +# Terraform Schematics Agent Module -[![Incubating (Not yet consumable)](https://img.shields.io/badge/status-Incubating%20(Not%20yet%20consumable)-red)](https://terraform-ibm-modules.github.io/documentation/#/badge-status) +[![Implemented (No quality checks)](https://img.shields.io/badge/Status-Implemented%20(No%20quality%20checks)-yellowgreen)](https://terraform-ibm-modules.github.io/documentation/#/badge-status) [![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-module-template?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/releases/latest) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) -TODO: Replace me with description of the module(s) in this repo +Creates an IBM Schematics Agent. + +More information about the IBM Schematics Agent can be found [here](https://cloud.ibm.com/docs/schematics?topic=schematics-deploy-agent-overview&interface=ui) From 6560e687eaa109948dc03ffc79e952301bd637d9 Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Fri, 15 Mar 2024 20:02:52 +0000 Subject: [PATCH 12/14] feat: init SKIP UPGRADE TEST: init module --- .github/CODEOWNERS | 2 +- examples/complete/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 0c8b6e2..7044d92 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # Primary owner should be listed first in list of global owners, followed by any secondary owners -* @rajatagarwal-ibm @ocofaigh +* @rajatagarwal-ibm @toddgiguere diff --git a/examples/complete/main.tf b/examples/complete/main.tf index 446378f..4d6666d 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -18,7 +18,7 @@ module "cos" { source = "terraform-ibm-modules/cos/ibm" version = "7.4.3" resource_group_id = module.resource_group.resource_group_id - region = "us-south" + region = var.region cos_instance_name = "${var.prefix}-cos" cos_tags = var.resource_tags bucket_name = "${var.prefix}-bucket" From 9ff9f9d63ae759027fc79964112bad3a3b66076f Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Tue, 19 Mar 2024 21:33:01 +0000 Subject: [PATCH 13/14] feat: init SKIP UPGRADE TEST: init module --- .github/settings.yml | 2 +- .secrets.baseline | 15 ++++++++-- README.md | 28 +++++++++++++++++-- examples/{complete => kubernetes}/README.md | 2 +- examples/{complete => kubernetes}/main.tf | 0 examples/{complete => kubernetes}/outputs.tf | 5 ++++ examples/{complete => kubernetes}/provider.tf | 0 .../{complete => kubernetes}/variables.tf | 0 examples/{complete => kubernetes}/version.tf | 0 main.tf | 6 +--- outputs.tf | 7 ++++- tests/pr_test.go | 8 +++--- 12 files changed, 56 insertions(+), 17 deletions(-) rename examples/{complete => kubernetes}/README.md (93%) rename examples/{complete => kubernetes}/main.tf (100%) rename examples/{complete => kubernetes}/outputs.tf (85%) rename examples/{complete => kubernetes}/provider.tf (100%) rename examples/{complete => kubernetes}/variables.tf (100%) rename examples/{complete => kubernetes}/version.tf (100%) diff --git a/.github/settings.yml b/.github/settings.yml index 143346b..1a389fc 100644 --- a/.github/settings.yml +++ b/.github/settings.yml @@ -25,4 +25,4 @@ repository: description: "Creates a Schematics Agent and deploys it on the existing cluster." # Use a comma-separated list of topics to set on the repo (ensure not to use any caps in the topic string). - topics: terraform, ibm-cloud, terraform-module, core-team + topics: terraform, ibm-cloud, terraform-module, core-team, supported, stable diff --git a/.secrets.baseline b/.secrets.baseline index 83c2fe0..1395f13 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.sum|^.secrets.baseline$", "lines": null }, - "generated_at": "2023-12-09T06:39:44Z", + "generated_at": "2024-03-19T21:31:43Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -76,7 +76,18 @@ "name": "TwilioKeyDetector" } ], - "results": {}, + "results": { + "README.md": [ + { + "hashed_secret": "ff9ee043d85595eb255c05dfe32ece02a53efbb2", + "is_secret": false, + "is_verified": false, + "line_number": 55, + "type": "Secret Keyword", + "verified_result": null + } + ] + }, "version": "0.13.1+ibm.62.dss", "word_list": { "file": null, diff --git a/README.md b/README.md index c96876a..f350ea2 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ Update status and "latest release" badges: 1. For the status options, see https://terraform-ibm-modules.github.io/documentation/#/badge-status 2. Update the "latest release" badge to point to the correct module's repo. Replace "terraform-ibm-module-template" in two places. --> -[![Implemented (No quality checks)](https://img.shields.io/badge/Status-Implemented%20(No%20quality%20checks)-yellowgreen)](https://terraform-ibm-modules.github.io/documentation/#/badge-status) -[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-module-template?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-module-template/releases/latest) +[![Stable (With quality checks)](https://img.shields.io/badge/Status-Stable%20(With%20quality%20checks)-green)](https://terraform-ibm-modules.github.io/documentation/#/badge-status) +[![latest release](https://img.shields.io/github/v/release/terraform-ibm-modules/terraform-ibm-schematics-agent?logo=GitHub&sort=semver)](https://github.com/terraform-ibm-modules/terraform-ibm-schematics-agent/releases/latest) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) @@ -23,7 +23,7 @@ More information about the IBM Schematics Agent can be found [here](https://clou ## Overview * [terraform-ibm-schematics-agent](#terraform-ibm-schematics-agent) * [Examples](./examples) - * [Complete example](./examples/complete) + * [Kubernetes example](./examples/kubernetes) * [Contributing](#contributing) @@ -51,6 +51,27 @@ unless real values don't help users know what to change. ```hcl +provider "ibm" { + ibmcloud_api_key = "XXXXXXXXXX" + region = "us-south" +} +module "schematics_agent" { + source = "terraform-ibm-modules/schematics-agent/ibm" + version = "latest" # Replace "latest" with a release version to lock into a specific release + infra_type = "ibm_kubernetes" # ibm_kubernetes, ibm_openshift, ibm_satellite. + cluster_id = "" + cluster_resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX" + cos_instance_name = "" + cos_bucket_name = "" + cos_bucket_region = "" + agent_location = "us-south" + agent_description = "schematics agent description" + agent_name = "k8s-schematics-agent" + agent_resource_group_id = "xxXXxxXXxXxXXXXxxXxxxXXXXxXXXXX" + schematics_location = "us-south" # Allowed values are `us-south`, `us-east`, `eu-gb`, `eu-de`. + agent_version = "" +} + ``` ### Required IAM access policies @@ -124,6 +145,7 @@ No modules. | Name | Description | |------|-------------| +| [agent\_crn](#output\_agent\_crn) | Schematics agent CRN. | | [agent\_id](#output\_agent\_id) | Schematics agent ID. | | [log\_url](#output\_log\_url) | URL to the full schematics agent deployment job logs. | | [status\_code](#output\_status\_code) | Final result of the schematics agent deployment job. | diff --git a/examples/complete/README.md b/examples/kubernetes/README.md similarity index 93% rename from examples/complete/README.md rename to examples/kubernetes/README.md index 355d243..2dfef90 100644 --- a/examples/complete/README.md +++ b/examples/kubernetes/README.md @@ -1,4 +1,4 @@ -# Complete example +# Kubernetes example An end-to-end example that will provision the following: * A new resource group if one is not passed in. diff --git a/examples/complete/main.tf b/examples/kubernetes/main.tf similarity index 100% rename from examples/complete/main.tf rename to examples/kubernetes/main.tf diff --git a/examples/complete/outputs.tf b/examples/kubernetes/outputs.tf similarity index 85% rename from examples/complete/outputs.tf rename to examples/kubernetes/outputs.tf index 560488f..0f79ffe 100644 --- a/examples/complete/outputs.tf +++ b/examples/kubernetes/outputs.tf @@ -8,6 +8,11 @@ output "schematics_agent_id" { value = module.schematics_agent.agent_id } +output "schematics_agent_crn" { + description = "Schematics agent CRN." + value = module.schematics_agent.agent_crn +} + output "schematics_agent_job_log_url" { description = "URL to the full schematics agent deployment job logs." value = module.schematics_agent.log_url diff --git a/examples/complete/provider.tf b/examples/kubernetes/provider.tf similarity index 100% rename from examples/complete/provider.tf rename to examples/kubernetes/provider.tf diff --git a/examples/complete/variables.tf b/examples/kubernetes/variables.tf similarity index 100% rename from examples/complete/variables.tf rename to examples/kubernetes/variables.tf diff --git a/examples/complete/version.tf b/examples/kubernetes/version.tf similarity index 100% rename from examples/complete/version.tf rename to examples/kubernetes/version.tf diff --git a/main.tf b/main.tf index e0254bc..981a882 100644 --- a/main.tf +++ b/main.tf @@ -15,10 +15,6 @@ resource "ibm_schematics_agent" "schematics_agent_instance" { version = var.agent_version } -locals { - agent_id = join(".", slice(split(":", ibm_schematics_agent.schematics_agent_instance.agent_crn), 9, 10)) -} - resource "ibm_schematics_agent_deploy" "schematics_agent_deploy" { - agent_id = local.agent_id + agent_id = ibm_schematics_agent.schematics_agent_instance.id } diff --git a/outputs.tf b/outputs.tf index ce8db3e..a8949a8 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,6 +1,11 @@ output "agent_id" { description = "Schematics agent ID." - value = local.agent_id + value = ibm_schematics_agent.schematics_agent_instance.id +} + +output "agent_crn" { + description = "Schematics agent CRN." + value = ibm_schematics_agent.schematics_agent_instance.agent_crn } output "log_url" { diff --git a/tests/pr_test.go b/tests/pr_test.go index 6840db2..e2da3a8 100644 --- a/tests/pr_test.go +++ b/tests/pr_test.go @@ -10,7 +10,7 @@ import ( // Use existing resource group const resourceGroup = "geretain-test-resources" -const completeExampleDir = "examples/complete" +const kubernetesExampleDir = "examples/kubernetes" const region = "us-south" // temporarily ignore destroy for schematics_agent_deploy as its currently in beta. @@ -33,10 +33,10 @@ func setupOptions(t *testing.T, prefix string, dir string) *testhelper.TestOptio return options } -func TestRunCompleteExample(t *testing.T) { +func TestRunKubernetesExample(t *testing.T) { t.Parallel() - options := setupOptions(t, "sa-com", completeExampleDir) + options := setupOptions(t, "sa-k8s", kubernetesExampleDir) output, err := options.RunTestConsistency() assert.Nil(t, err, "This should not have errored") @@ -53,7 +53,7 @@ func TestRunCompleteExample(t *testing.T) { func TestRunUpgradeExample(t *testing.T) { t.Parallel() - options := setupOptions(t, "sa-com-upg", completeExampleDir) + options := setupOptions(t, "sa-k8s-upg", kubernetesExampleDir) output, err := options.RunTestUpgrade() if !options.UpgradeTestSkipped { From 337ab315e98c981063f172fd691efe699648c90c Mon Sep 17 00:00:00 2001 From: Rajat Agrawal Date: Wed, 20 Mar 2024 09:49:53 +0000 Subject: [PATCH 14/14] feat: init SKIP UPGRADE TEST: init module --- cra-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cra-config.yaml b/cra-config.yaml index 9f49af9..42dd519 100644 --- a/cra-config.yaml +++ b/cra-config.yaml @@ -1,7 +1,7 @@ # More info about this file at https://github.com/terraform-ibm-modules/common-pipeline-assets/blob/main/.github/workflows/terraform-test-pipeline.md#cra-config-yaml version: "v1" CRA_TARGETS: - - CRA_TARGET: "examples/complete" # Target directory for CRA scan. If not provided, the CRA Scan will not be run. + - CRA_TARGET: "examples/kubernetes" # Target directory for CRA scan. If not provided, the CRA Scan will not be run. CRA_IGNORE_RULES_FILE: "cra-tf-validate-ignore-rules.json" # CRA Ignore file to use. If not provided, it checks the repo root directory for `cra-tf-validate-ignore-rules.json` PROFILE_ID: "0e6e7b5a-817d-4344-ab6f-e5d7a9c49520" # SCC profile ID (currently set to the FSCloud 1.4.0 profile). # SCC_INSTANCE_ID: "" # The SCC instance ID to use to download profile for CRA scan. If not provided, a default global value will be used.