Skip to content

Commit

Permalink
Merge branch 'master' into nestedPolicyConditions
Browse files Browse the repository at this point in the history
  • Loading branch information
swcolley committed Nov 13, 2023
2 parents e91e3a1 + cf3b4e2 commit 356e8ae
Show file tree
Hide file tree
Showing 50 changed files with 4,136 additions and 1,963 deletions.
176 changes: 121 additions & 55 deletions .secrets.baseline

Large diffs are not rendered by default.

58 changes: 38 additions & 20 deletions examples/ibm-project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

This example illustrates how to use the ProjectV1

These types of resources are supported:
The following types of resources are supported:

* Project definition
* project_config
* project

## Usage

To run this example you need to execute:
To run this example, execute the following commands:

```bash
$ terraform init
Expand All @@ -21,25 +22,39 @@ Run `terraform destroy` when you don't need these resources.

## ProjectV1 resources

project_instance resource:
project_config resource:

```hcl
resource "project_instance" "project_instance" {
name = var.project_instance_name
description = var.project_instance_description
configs = var.project_instance_configs
resource_group = var.project_instance_resource_group
location = var.project_instance_location
resource "project_config" "project_config_instance" {
project_id = ibm_project.project_instance.project_id
definition = var.project_config_definition
}
```
project resource:

## ProjectV1 Data sources
```hcl
resource "project" "project_instance" {
location = var.project_location
resource_group = var.project_resource_group
definition = var.project_definition
}
```

## ProjectV1 data sources

project_config data source:

project_event_notification data source:
```hcl
data "project_config" "project_config_instance" {
project_id = ibm_project.project_instance.id
project_config_id = ibm_project_config.project_config_instance.project_config_id
}
```
project data source:

```hcl
data "project_event_notification" "project_event_notification_instance" {
id = var.project_event_notification_id
data "project" "project_instance" {
project_id = ibm_project.project_instance.id
}
```

Expand Down Expand Up @@ -68,16 +83,19 @@ data "project_event_notification" "project_event_notification_instance" {
| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| name | The project name. | `string` | true |
| description | A project's descriptive text. | `string` | false |
| configs | The project configurations. | `list()` | false |
| project_id | The unique project ID. | `string` | true |
| schematics | A schematics workspace associated to a project configuration. | `` | false |
| definition | The type and output of a project configuration. | `` | true |
| location | The IBM Cloud location where a resource is deployed. | `string` | true |
| resource_group | The resource group where the project's data and tools are created. | `string` | true |
| location | The location where the project's data and tools are created. | `string` | true |
| definition | The definition of the project. | `` | true |
| project_id | The unique project ID. | `string` | true |
| project_config_id | The unique config ID. | `string` | true |
| project_id | The unique project ID. | `string` | true |

## Outputs

| Name | Description |
|------|-------------|
| project_instance | project_instance object |
| project_event_notification | project_event_notification object |
| project_config | project_config object |
| project | project object |
43 changes: 28 additions & 15 deletions examples/ibm-project/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ provider "ibm" {
ibmcloud_api_key = var.ibmcloud_api_key
}

// Provision project_instance resource instance
resource "ibm_project_instance" "project_instance" {
name = "My static website"
description = "Sample static website test using the IBM catalog deployable architecture"
configs {
// Provision project_config resource instance
resource "ibm_project_config" "project_config_instance" {
project_id = ibm_project.project_instance.project_id
definition {
name = "static-website-dev"
labels = [ "env:dev", "billing:internal" ]
description = "Website - development"
authorizations {
method = "api_key"
api_key = "<your_apikey_here>"
}
locator_id = "1082e7d2-5e2f-0a11-a3bc-f88a8e1931fc.145be7c1-9ec4-4719-b586-584ee52fbed0-global"
input {
name = "app_repo_name"
Expand All @@ -19,15 +21,26 @@ resource "ibm_project_instance" "project_instance" {
value = "static-website-dev-app-repo"
}
}
resource_group = "Default"
location = "us-south"
}

// Data source is not linked to a resource instance
// Uncomment if an existing data source instance exists
/*
// Create project_event_notification data source
data "ibm_project_event_notification" "project_event_notification_instance" {
project_id = var.project_event_notification_id
// Provision project resource instance
resource "ibm_project" "project_instance" {
location = var.project_location
resource_group = var.project_resource_group
definition {
name = "My static website"
description = "Sample static website test using the IBM catalog deployable architecture"
destroy_on_delete = true
}
}

// Create project_config data source
data "ibm_project_config" "project_config_instance" {
project_id = ibm_project_config.project_config_instance.project_id
project_config_id = ibm_project_config.project_config_instance.project_config_id
}

// Create project data source
data "ibm_project" "project_instance" {
project_id = ibm_project.project_instance.id
}
*/
16 changes: 11 additions & 5 deletions examples/ibm-project/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// This allows project_instance data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
output "ibm_project_instance" {
value = ibm_project_instance.project_instance
description = "project_instance resource instance"
// This output allows project_config data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_project_config" {
value = ibm_project_config.project_config_instance
description = "project_config resource instance"
}
// This output allows project data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "ibm_project" {
value = ibm_project.project_instance
description = "project resource instance"
}
41 changes: 25 additions & 16 deletions examples/ibm-project/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,40 @@ variable "ibmcloud_api_key" {
type = string
}

// Resource arguments for project_instance
variable "project_instance_name" {
description = "The project name."
// Resource arguments for project_config
variable "project_config_project_id" {
description = "The unique project ID."
type = string
default = "project_id"
}

// Resource arguments for project
variable "project_location" {
description = "The IBM Cloud location where a resource is deployed."
type = string
default = "acme-microservice"
default = "us-south"
}
variable "project_instance_description" {
description = "A project's descriptive text."
variable "project_resource_group" {
description = "The resource group where the project's data and tools are created."
type = string
default = "A microservice to deploy on top of ACME infrastructure."
default = "Default"
}
variable "project_instance_resource_group" {
description = "Group name of the customized collection of resources."

// Data source arguments for project_config
variable "project_config_project_id" {
description = "The unique project ID."
type = string
default = "resource_group"
default = "project_id"
}
variable "project_instance_location" {
description = "Data center locations for resource deployment."
variable "project_config_id" {
description = "The unique config ID."
type = string
default = "location"
default = "project_config_id"
}

// Data source arguments for project_event_notification
variable "project_event_notification_id" {
// Data source arguments for project
variable "project_id" {
description = "The unique project ID."
type = string
default = "id"
default = "project_id"
}
2 changes: 1 addition & 1 deletion examples/ibm-project/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
}
}
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/IBM/platform-services-go-sdk v0.52.1 h1:fUCtYMAekzsWO/ylZi31j6BpyJ1xK
github.com/IBM/platform-services-go-sdk v0.52.1/go.mod h1:6LxcUhIaSLP4SuQJXF9oLXBamSQogs5D9BcVwr4hmfU=
github.com/IBM/platform-services-go-sdk v0.53.1 h1:axpK4dzlf+C+KgHQZWXoKSUMoV2t6OrR5kGGumUEXrI=
github.com/IBM/platform-services-go-sdk v0.53.1/go.mod h1:CWSprvsCsXWvujmBzbtoJSmbRZS9FVV3O594b0t/GiM=
github.com/IBM/project-go-sdk v0.0.10 h1:vHSuemwZ4S4c6BEb22tzsEcPTs/5LnZ0yKpP3GG/GL8=
github.com/IBM/project-go-sdk v0.0.10/go.mod h1:lqe0M4cKvABI1iHR1b+KfasVcxQL6nl2VJ8eOyQs8Ig=
github.com/IBM/project-go-sdk v0.0.99 h1:rQU/uQLW83OsAUfP/d8fFSIjp8ooEQIFjalYQD4i4aY=
github.com/IBM/project-go-sdk v0.0.99/go.mod h1:lqe0M4cKvABI1iHR1b+KfasVcxQL6nl2VJ8eOyQs8Ig=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5 h1:NPUhkoOCRuv3OFWt19PmwjXGGTKlvmbuPg9fUrBUNe4=
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5/go.mod h1:b07XHUVh0XYnQE9s2mqgjYST1h9buaQNqN4EcKhOsX0=
github.com/IBM/sarama v1.41.2 h1:ZDBZfGPHAD4uuAtSv4U22fRZBgst0eEwGFzLj0fb85c=
Expand Down
83 changes: 75 additions & 8 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@
package acctest

import (
"context"
"fmt"
"os"
"strconv"
"strings"
"sync"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
terraformsdk "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/provider"
)

const (
ProviderName = "ibm"
ProviderNameAlternate = "ibmalternate"
)

var (
AppIDTenantID string
AppIDTestUserEmail string
Expand Down Expand Up @@ -146,7 +155,6 @@ var (
IksClusterVpcID string
IksClusterSubnetID string
IksClusterResourceGroupID string
IcdDbRegion string
IcdDbDeploymentId string
IcdDbBackupId string
IcdDbTaskId string
Expand Down Expand Up @@ -309,6 +317,9 @@ var (
// for IAM Identity
var IamIdentityAssignmentTargetAccountId string

// Projects
var ProjectsConfigApiKey string

func init() {
testlogger := os.Getenv("TF_LOG")
if testlogger != "" {
Expand All @@ -317,6 +328,11 @@ func init() {

IamIdentityAssignmentTargetAccountId = os.Getenv("IAM_IDENTITY_ASSIGNMENT_TARGET_ACCOUNT")

ProjectsConfigApiKey = os.Getenv("IBM_PROJECTS_CONFIG_APIKEY")
if ProjectsConfigApiKey == "" {
fmt.Println("[WARN] Set the environment variable IBM_PROJECTS_CONFIG_APIKEY for testing IBM Projects Config resources, the tests will fail if this is not set")
}

AppIDTenantID = os.Getenv("IBM_APPID_TENANT_ID")
if AppIDTenantID == "" {
fmt.Println("[WARN] Set the environment variable IBM_APPID_TENANT_ID for testing AppID resources, AppID tests will fail if this is not set")
Expand Down Expand Up @@ -850,12 +866,6 @@ func init() {
fmt.Println("[INFO] Set the environment variable ISSnapshotCRN for ibm_is_snapshot resource else it is set to default value 'crn:v1:bluemix:public:is:ca-tor:a/xxxxxxxx::snapshot:xxxx-xxxxc-xxx-xxxx-xxxx-xxxxxxxxxx'")
}

IcdDbRegion = os.Getenv("ICD_DB_REGION")
if IcdDbRegion == "" {
IcdDbRegion = "eu-gb"
fmt.Println("[INFO] Set the environment variable ICD_DB_REGION for testing ibm_cloud_databases else it is set to default value 'eu-gb'")
}

IcdDbDeploymentId = os.Getenv("ICD_DB_DEPLOYMENT_ID")
if IcdDbDeploymentId == "" {
IcdDbDeploymentId = "crn:v1:bluemix:public:databases-for-redis:au-syd:a/40ddc34a953a8c02f10987b59085b60e:5042afe1-72c2-4231-89cc-c949e5d56251::"
Expand Down Expand Up @@ -1522,10 +1532,18 @@ var (
TestAccProvider *schema.Provider
)

// testAccProviderConfigure ensures Provider is only configured once
//
// The PreCheck(t) function is invoked for every test and this prevents
// extraneous reconfiguration to the same values each time. However, this does
// not prevent reconfiguration that may happen should the address of
// Provider be errantly reused in ProviderFactories.
var testAccProviderConfigure sync.Once

func init() {
TestAccProvider = provider.Provider()
TestAccProviders = map[string]*schema.Provider{
"ibm": TestAccProvider,
ProviderName: TestAccProvider,
}
}

Expand All @@ -1549,6 +1567,13 @@ func TestAccPreCheck(t *testing.T) {
if v := os.Getenv("IAAS_CLASSIC_USERNAME"); v == "" {
t.Fatal("IAAS_CLASSIC_USERNAME must be set for acceptance tests")
}

testAccProviderConfigure.Do(func() {
diags := TestAccProvider.Configure(context.Background(), terraformsdk.NewResourceConfigRaw(nil))
if diags.HasError() {
t.Fatalf("configuring provider: %s", diags[0].Summary)
}
})
}

func TestAccPreCheckEnterprise(t *testing.T) {
Expand Down Expand Up @@ -1688,3 +1713,45 @@ func TestAccPreCheckScc(t *testing.T) {
t.Fatal("IBMCLOUD_SCC_REPORT_ID missing. Set the environment variable IBMCLOUD_SCC_REPORT_ID with a VALID REPORT_ID")
}
}

func TestAccProviderFactories() map[string]func() (*schema.Provider, error) {
return map[string]func() (*schema.Provider, error){
ProviderName: func() (*schema.Provider, error) { return provider.Provider(), nil },
ProviderNameAlternate: func() (*schema.Provider, error) { return provider.Provider(), nil },
}
}

func Region() string {
region, _ := schema.MultiEnvDefaultFunc([]string{"IC_REGION", "IBMCLOUD_REGION", "BM_REGION", "BLUEMIX_REGION"}, "us-south")()

return region.(string)
}

func RegionAlternate() string {
region, _ := schema.MultiEnvDefaultFunc([]string{"IC_REGION_ALTERNATE", "IBMCLOUD_REGION_ALTERNATE"}, "eu-gb")()

return region.(string)
}

func ConfigAlternateRegionProvider() string {
return configNamedRegionalProvider(ProviderNameAlternate, RegionAlternate())
}

// ConfigCompose can be called to concatenate multiple strings to build test configurations
func ConfigCompose(config ...string) string {
var str strings.Builder

for _, conf := range config {
str.WriteString(conf)
}

return str.String()
}

func configNamedRegionalProvider(providerName string, region string) string {
return fmt.Sprintf(`
provider %[1]q {
region = %[2]q
}
`, providerName, region)
}

0 comments on commit 356e8ae

Please sign in to comment.