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

[DO NOT MERGE] feat: sample DA for stage first version #708

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ on:

jobs:
call-terraform-ci-pipeline:
uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-terraform-module-ci-v2.yml@v1.22.1
uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-terraform-module-ci-v2.yml@v1.22.3
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ on:

jobs:
call-terraform-release-pipeline:
uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-release.yml@v1.22.1
uses: terraform-ibm-modules/common-pipeline-assets/.github/workflows/common-release.yml@v1.22.3
secrets: inherit
15 changes: 3 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ No permissions are needed to run this module.
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3.0, <1.7.0 |
| <a name="requirement_ibm"></a> [ibm](#requirement\_ibm) | >= 1.58.1, < 2.0.0 |
| <a name="requirement_tls"></a> [tls](#requirement\_tls) | >= 4.0.4, < 5.0.0 |

### Modules

Expand All @@ -63,27 +62,19 @@ No modules.

| Name | Type |
|------|------|
| [ibm_is_ssh_key.ssh_key](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/is_ssh_key) | resource |
| [ibm_is_vpc.vpc](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/is_vpc) | resource |
| [tls_private_key.tls_key](https://registry.terraform.io/providers/hashicorp/tls/latest/docs/resources/private_key) | resource |
| [ibm_resource_group.resource_group](https://registry.terraform.io/providers/ibm-cloud/ibm/latest/docs/resources/resource_group) | resource |

### Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_classic_access"></a> [classic\_access](#input\_classic\_access) | Enable VPC Classic Access. Note: only one VPC per region can have classic access | `bool` | `false` | no |
| <a name="input_name"></a> [name](#input\_name) | Name of the SSH Key. | `string` | n/a | yes |
| <a name="input_resource_group_id"></a> [resource\_group\_id](#input\_resource\_group\_id) | ID of resource group. If not specified, Default resource group used. | `string` | `null` | no |
| <a name="input_tags"></a> [tags](#input\_tags) | List of Tags for the SSH Key. | `list(string)` | `[]` | no |
| <a name="input_resource_group_names"></a> [resource\_group\_names](#input\_resource\_group\_names) | List of resource group names to be created. | `list(string)` | `[]` | no |

### Outputs

| Name | Description |
|------|-------------|
| <a name="output_fingerprint"></a> [fingerprint](#output\_fingerprint) | SSH key Fingerprint info |
| <a name="output_ssh_key_id"></a> [ssh\_key\_id](#output\_ssh\_key\_id) | The ID of the ssh key |
| <a name="output_vpc_crn"></a> [vpc\_crn](#output\_vpc\_crn) | CRN of VPC created |
| <a name="output_vpc_id"></a> [vpc\_id](#output\_vpc\_id) | ID of VPC created |
| <a name="output_resource_group"></a> [resource\_group](#output\_resource\_group) | Resource Group Names |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

<!-- Leave this section as is so that your module has a link to local development environment set up steps for contributors to follow -->
Expand Down
7 changes: 6 additions & 1 deletion examples/basic/catalogValidationValues.json.template
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"ibmcloud_api_key": $VALIDATION_APIKEY, "resource_group": $RG_NAME, "resource_tags": $TAGS, "prefix": $PREFIX}
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"resource_group": $RG_NAME,
"resource_tags": $TAGS,
"prefix": $PREFIX
}
7 changes: 6 additions & 1 deletion examples/complete/catalogValidationValues.json.template
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"ibmcloud_api_key": $VALIDATION_APIKEY, "resource_group": $RG_NAME, "resource_tags": $TAGS, "prefix": $PREFIX}
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"resource_group": $RG_NAME,
"resource_tags": $TAGS,
"prefix": $PREFIX
}
14 changes: 0 additions & 14 deletions ibm_catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,6 @@
}
]
},
"configuration": [
{
"custom_config": {
"config_constraints": {
"generationType": "2"
},
"grouping": "deployment",
"original_grouping": "deployment",
"type": "vpc_region"
},
"key": "region",
"required": true
}
],
"iam_permissions": [
{
"role_crns": [
Expand Down
35 changes: 12 additions & 23 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
# Create RSA key of size 4096 bits
resource "tls_private_key" "tls_key" {
algorithm = "RSA"
rsa_bits = 4096
locals {
rg_map = {
for rg in var.resource_group_names :
"${rg}-rg" => {
name = rg
}
}
tags = var.tags != null ? join(",", var.tags) : "none"
}

# Import SSH key to IBM Cloud
resource "ibm_is_ssh_key" "ssh_key" {
name = var.name
resource_group = var.resource_group_id
public_key = resource.tls_private_key.tls_key.public_key_openssh
tags = var.tags
}

# Create a VPC
resource "ibm_is_vpc" "vpc" {
name = "${var.name}-vpc"
resource_group = var.resource_group_id
classic_access = var.classic_access
default_network_acl_name = "${var.name}-edge-acl"
default_security_group_name = "${var.name}-default-sg"
default_routing_table_name = "${var.name}-default-table"
address_prefix_management = "manual"
tags = var.tags
resource "ibm_resource_group" "resource_group" {
for_each = local.rg_map
name = each.value.name
quota_id = null
}
24 changes: 6 additions & 18 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
output "ssh_key_id" {
description = "The ID of the ssh key"
value = ibm_is_ssh_key.ssh_key.id
}

output "fingerprint" {
description = "SSH key Fingerprint info"
value = ibm_is_ssh_key.ssh_key.fingerprint
}

output "vpc_id" {
description = "ID of VPC created"
value = ibm_is_vpc.vpc.id
}

output "vpc_crn" {
description = "CRN of VPC created"
value = ibm_is_vpc.vpc.crn
output "resource_group" {
description = "Resource Group Names"
value = [
for rg_names in ibm_resource_group.resource_group :
rg_names.id
]
}
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"ibmcloud_api_key": $VALIDATION_APIKEY, "resource_group": $RG_NAME, "resource_tags": $TAGS, "prefix": $PREFIX}
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"resource_group": $RG_NAME,
"resource_tags": $TAGS,
"prefix": $PREFIX
}
2 changes: 1 addition & 1 deletion solutions/mock-da-extension/version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = ">= 1.65.1"
version = ">= 1.66.0"
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"ibmcloud_api_key": $VALIDATION_APIKEY, "resource_group": $RG_NAME, "resource_tags": $TAGS, "prefix": $PREFIX}
{
"ibmcloud_api_key": $VALIDATION_APIKEY,
"resource_group": $RG_NAME,
"resource_tags": $TAGS,
"prefix": $PREFIX
}
2 changes: 1 addition & 1 deletion solutions/mock-da-quickstart/version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = ">= 1.65.1"
version = ">= 1.66.0"
}
}
}
4 changes: 3 additions & 1 deletion solutions/mock-da/catalogValidationValues.json.template
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{"ibmcloud_api_key": $VALIDATION_APIKEY, "resource_group": $RG_NAME, "resource_tags": $TAGS, "prefix": $PREFIX}
{
"ibmcloud_api_key": $VALIDATION_APIKEY
}
29 changes: 4 additions & 25 deletions solutions/mock-da/main.tf
Original file line number Diff line number Diff line change
@@ -1,30 +1,9 @@
##############################################################################
# Resource Group
# (if var.resource_group is null, create a new RG using var.prefix)
##############################################################################

resource "ibm_resource_group" "resource_group" {
count = var.resource_group != null ? 0 : 1
name = "${var.prefix}-rg"
quota_id = null
}

data "ibm_resource_group" "existing_resource_group" {
count = var.resource_group != null ? 1 : 0
name = var.resource_group
}

locals {
resource_group_id = var.resource_group != null ? data.ibm_resource_group.existing_resource_group[0].id : ibm_resource_group.resource_group[0].id
}

#############################################################################
# Call root level module to create SSH key
# Call root level module
#############################################################################

module "mock_module" {
source = "../.."
name = var.prefix
resource_group_id = local.resource_group_id
tags = var.resource_tags
source = "../.."
resource_group_names = var.resource_group_names
tags = var.tags
}
34 changes: 2 additions & 32 deletions solutions/mock-da/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,7 @@
# Outputs
##############################################################################

output "ssh_key_id" {
description = "The ID of the ssh key"
value = module.mock_module.ssh_key_id
}

output "fingerprint" {
description = "SSH key Fingerprint info"
value = module.mock_module.fingerprint
}

output "test" {
description = "test"
value = var.testing
}

output "vpc_id" {
description = "ID of VPC created"
value = module.mock_module.vpc_id
}

output "vpc_crn" {
description = "CRN of VPC created"
value = module.mock_module.vpc_crn
}

output "resource_group" {
description = "Resource Group Name"
value = var.resource_group != null ? var.resource_group : "${var.prefix}-rg"
}

output "resource_group_id" {
description = "Resource Group ID"
value = var.resource_group != null ? data.ibm_resource_group.existing_resource_group[0].id : ibm_resource_group.resource_group[0].id
description = "Resource Group Names"
value = module.mock_module.resource_group
}
22 changes: 5 additions & 17 deletions solutions/mock-da/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,14 @@ variable "region" {
default = "us-south"
}

variable "prefix" {
type = string
description = "Prefix to append to all resources created by this example"
default = "mock"
}

variable "resource_group" {
type = string
description = "An existing resource group name to use for this example, if unset a new resource group will be created"
default = null
variable "resource_group_names" {
type = list(string)
description = "List of resource group names to be created."
default = ["mock1", "mock2"]
}

variable "resource_tags" {
variable "tags" {
type = list(string)
description = "Optional list of tags to be added to created resources"
default = []
}

variable "testing" {
type = list(string)
description = "Test variable to test setting list of strings to null"
default = null
}
2 changes: 1 addition & 1 deletion solutions/mock-da/version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
ibm = {
source = "IBM-Cloud/ibm"
version = ">= 1.65.1"
version = ">= 1.66.0"
}
}
}
4 changes: 2 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.22.3

require (
github.com/stretchr/testify v1.9.0
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.31.8
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.34.1
)

require (
Expand All @@ -16,7 +16,7 @@ require (
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/IBM-Cloud/bluemix-go v0.0.0-20240402122236-5c5b994a3f1a // indirect
github.com/IBM-Cloud/bluemix-go v0.0.0-20240423071914-9e96525baef4 // indirect
github.com/IBM-Cloud/power-go-client v1.6.0 // indirect
github.com/IBM/cloud-databases-go-sdk v0.7.0 // indirect
github.com/IBM/go-sdk-core/v5 v5.17.2 // indirect
Expand Down
8 changes: 4 additions & 4 deletions tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240402122236-5c5b994a3f1a h1:s/KeK5F3xm3xGeqXzCtqMl3nvqQ2my4N5ppxAD+cShY=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240402122236-5c5b994a3f1a/go.mod h1:/7hMjdZA6fEpd/dQAOEABxKEwN0t72P3PlpEDu0Y7bE=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240423071914-9e96525baef4 h1:43l8CU5cW4pOea10+jWtqRJj/4F4Ghfn6Oc82jB9RhM=
github.com/IBM-Cloud/bluemix-go v0.0.0-20240423071914-9e96525baef4/go.mod h1:/7hMjdZA6fEpd/dQAOEABxKEwN0t72P3PlpEDu0Y7bE=
github.com/IBM-Cloud/power-go-client v1.6.0 h1:X+QX+WSF66+aouyaf4r+IeBLXUurAJj9+Bd+vH7G5I0=
github.com/IBM-Cloud/power-go-client v1.6.0/go.mod h1:0ad5Lcq1utoYVJx0uqooMjCpUaYaK0ItP9QJYtY6k0Y=
github.com/IBM/cloud-databases-go-sdk v0.7.0 h1:prvLebKD1kcIk81D6yRhOr/TWp1VQJGLhGAasQr7RtA=
Expand Down Expand Up @@ -606,8 +606,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.31.8 h1:tphVylXH3w/IQ/3BQcMdnOApxpbBiVrXuhP1YQ5DyAY=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.31.8/go.mod h1:6kBsZGhfJEV5L0lOJI+e1jzj8D2E+eltAYZFmYw3Q9s=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.34.1 h1:hw5Pivm1fbjpbloEjRcM68178DdAGguwJCF6ZD8UhWs=
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.34.1/go.mod h1:2fA+HDax1ZxE6o9qR1331MT67nRC/WVYgxpVLyB/ovw=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmccombs/hcl2json v0.5.0 h1:cT2sXStOzKL06c8ZTf9vh+0N8GKGzV7+9RUaY5/iUP8=
github.com/tmccombs/hcl2json v0.5.0/go.mod h1:B0ZpBthAKbQur6yZRKrtaqDmYLCvgnwHOBApE0faCpU=
Expand Down
23 changes: 4 additions & 19 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
variable "name" {
description = "Name of the SSH Key."
type = string
}

variable "resource_group_id" {
description = "ID of resource group. If not specified, Default resource group used."
type = string
default = null
variable "resource_group_names" {
type = list(string)
description = "List of resource group names to be created."
default = []
}

variable "tags" {
description = "List of Tags for the SSH Key."
type = list(string)
default = []
}

#############################################################################
# VPC Variables
##############################################################################

variable "classic_access" {
description = "Enable VPC Classic Access. Note: only one VPC per region can have classic access"
type = bool
default = false
}
4 changes: 0 additions & 4 deletions version.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,5 @@ terraform {
source = "ibm-cloud/ibm"
version = ">= 1.58.1, < 2.0.0"
}
tls = {
source = "hashicorp/tls"
version = ">= 4.0.4, < 5.0.0"
}
}
}