Skip to content

Commit

Permalink
config aggregator terraform changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramya-c4 committed Sep 25, 2024
1 parent 4712cab commit c74f610
Show file tree
Hide file tree
Showing 22 changed files with 1,895 additions and 9 deletions.
128 changes: 128 additions & 0 deletions examples/ibm-configuration-aggregator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Examples for Configuration Aggregator

These examples illustrate how to use the resources and data sources associated with Configuration Aggregator.

The following resources are supported:
* ibm_config_aggregator_settings

The following data sources are supported:
* ibm_config_aggregator_configurations
* ibm_config_aggregator_settings
* ibm_config_aggregator_resource_collection_status

## Usage

To run this example, execute the following commands:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Run `terraform destroy` when you don't need these resources.

## Configuration Aggregator resources

### Resource: ibm_config_aggregator_settings

```hcl
resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance" {
resource_collection_enabled = var.config_aggregator_settings_resource_collection_enabled
trusted_profile_id = var.config_aggregator_settings_trusted_profile_id
regions = var.config_aggregator_settings_regions
additional_scope = var.config_aggregator_settings_additional_scope
}
```

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| ibmcloud\_api\_key | IBM Cloud API key | `string` | true |
| resource_collection_enabled | The field denoting if the resource collection is enabled. | `bool` | false |
| trusted_profile_id | The trusted profile id that provides Reader access to the App Configuration instance to collect resource metadata. | `string` | false |
| regions | The list of regions across which the resource collection is enabled. | `list(string)` | false |
| additional_scope | The additional scope that enables resource collection for Enterprise acccounts. | `list()` | false |

## Configuration Aggregator data sources

### Data source: ibm_config_aggregator_configurations

```hcl
data "ibm_config_aggregator_configurations" "config_aggregator_configurations_instance" {
config_type = var.config_aggregator_configurations_config_type
service_name = var.config_aggregator_configurations_service_name
resource_group_id = var.config_aggregator_configurations_resource_group_id
location = var.config_aggregator_configurations_location
resource_crn = var.config_aggregator_configurations_resource_crn
}
```

#### Inputs

| Name | Description | Type | Required |
|------|-------------|------|---------|
| config_type | The type of resource configuration that are to be retrieved. | `string` | false |
| service_name | The name of the IBM Cloud service for which resources are to be retrieved. | `string` | false |
| resource_group_id | The resource group id of the resources. | `string` | false |
| location | The location or region in which the resources are created. | `string` | false |
| resource_crn | The crn of the resource. | `string` | false |

#### Outputs

| Name | Description |
|------|-------------|
| prev | The reference to the previous page of entries. |
| configs | Array of resource configurations. |

### Data source: ibm_config_aggregator_settings

```hcl
data "ibm_config_aggregator_settings" "config_aggregator_settings_instance" {
}
```

#### Outputs

| Name | Description |
|------|-------------|
| resource_collection_enabled | The field to check if the resource collection is enabled. |
| trusted_profile_id | The trusted profile ID that provides access to App Configuration instance to retrieve resource metadata. |
| last_updated | The last time the settings was last updated. |
| regions | Regions for which the resource collection is enabled. |
| additional_scope | The additional scope that enables resource collection for Enterprise acccounts. |

### Data source: ibm_config_aggregator_resource_collection_status

```hcl
data "ibm_config_aggregator_resource_collection_status" "config_aggregator_resource_collection_status_instance" {
}
```

#### Outputs

| Name | Description |
|------|-------------|
| last_config_refresh_time | The timestamp at which the configuration was last refreshed. |
| status | Status of the resource collection. |

## Assumptions

1. TODO

## Notes

1. TODO

## Requirements

| Name | Version |
|------|---------|
| terraform | ~> 0.12 |

## Providers

| Name | Version |
|------|---------|
| ibm | 1.13.1 |
41 changes: 41 additions & 0 deletions examples/ibm-configuration-aggregator/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

provider "ibm" {
ibmcloud_api_key = "yXtlDkzR8R4oQGizdR3mms-07gEeh9IXLtkO36trhM5B"
}

// Provision config_aggregator_settings resource instance
resource "ibm_config_aggregator_settings" "config_aggregator_settings_instance" {
resource_collection_enabled = var.config_aggregator_settings_resource_collection_enabled
trusted_profile_id = var.config_aggregator_settings_trusted_profile_id
regions = var.config_aggregator_settings_regions
}


// Data source is not linked to a resource instance
// Uncomment if an existing data source instance exists
/*
// Create config_aggregator_configurations data source
data "ibm_config_aggregator_configurations" "config_aggregator_configurations_instance" {
config_type = var.config_aggregator_configurations_config_type
service_name = var.config_aggregator_configurations_service_name
resource_group_id = var.config_aggregator_configurations_resource_group_id
location = var.config_aggregator_configurations_location
resource_crn = var.config_aggregator_configurations_resource_crn
}
*/

// Data source is not linked to a resource instance
// Uncomment if an existing data source instance exists
/*
// Create config_aggregator_settings data source
data "ibm_config_aggregator_settings" "config_aggregator_settings_instance" {
}
*/

// Data source is not linked to a resource instance
// Uncomment if an existing data source instance exists
/*
// Create config_aggregator_resource_collection_status data source
data "ibm_config_aggregator_resource_collection_status" "config_aggregator_resource_collection_status_instance" {
}
*/
10 changes: 10 additions & 0 deletions examples/ibm-configuration-aggregator/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This output allows config_aggregator_settings data to be referenced by other resources and the terraform CLI
// Modify this output if only certain data should be exposed
output "config_aggregator_settings" {
value = {
additional_scope = []
regions = ["all"]
resource_collection_enabled = ibm_config_aggregator_settings.config_aggregator_settings_instance.resource_collection_enabled
trusted_profile_id = ibm_config_aggregator_settings.config_aggregator_settings_instance.trusted_profile_id
}
}
51 changes: 51 additions & 0 deletions examples/ibm-configuration-aggregator/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
variable "ibmcloud_api_key" {
description = "IBM Cloud API key"
type = string
default="yXtlDkzR8R4oQGizdR3mms-07gEeh9IXLtkO36trhM5B"
}

// Resource arguments for config_aggregator_settings
variable "config_aggregator_settings_resource_collection_enabled" {
description = "The field denoting if the resource collection is enabled."
type = bool
default = true
}
variable "config_aggregator_settings_trusted_profile_id" {
description = "The trusted profile id that provides Reader access to the App Configuration instance to collect resource metadata."
type = string
default = "Profile-7d935dbb-7ee5-44e1-9e85-38e65d722398"
}
variable "config_aggregator_settings_regions" {
description = "The list of regions across which the resource collection is enabled."
type = list(string)
default = ["all"]
}

// Data source arguments for config_aggregator_configurations
variable "config_aggregator_configurations_config_type" {
description = "The type of resource configuration that are to be retrieved."
type = string
default = "placeholder"
}
variable "config_aggregator_configurations_service_name" {
description = "The name of the IBM Cloud service for which resources are to be retrieved."
type = string
default = "placeholder"
}
variable "config_aggregator_configurations_resource_group_id" {
description = "The resource group id of the resources."
type = string
default = "placeholder"
}
variable "config_aggregator_configurations_location" {
description = "The location or region in which the resources are created."
type = string
default = "placeholder"
}
variable "config_aggregator_configurations_resource_crn" {
description = "The crn of the resource."
type = string
default = "placeholder"
}


8 changes: 8 additions & 0 deletions examples/ibm-configuration-aggregator/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
ibm = {
source = "terraform.local/ibm-cloud/ibm"
version = "0.0.1"
}
}
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/IBM/cloud-databases-go-sdk v0.7.0
github.com/IBM/cloudant-go-sdk v0.8.0
github.com/IBM/code-engine-go-sdk v0.0.0-20240126185534-a6e054aa01ed
github.com/IBM/configuration-aggregator-go-sdk v0.0.1
github.com/IBM/container-registry-go-sdk v1.1.0
github.com/IBM/continuous-delivery-go-sdk v1.6.0
github.com/IBM/event-notifications-go-admin-sdk v0.8.0
Expand Down Expand Up @@ -51,7 +52,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/go-version v1.7.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/jinzhu/copier v0.3.2
github.com/minsikl/netscaler-nitro-go v0.0.0-20170827154432-5b14ce3643e3
Expand Down Expand Up @@ -176,6 +177,8 @@ require (
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/gox v1.0.1 // indirect
github.com/mitchellh/iochan v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/moby/spdystream v0.2.0 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -947,10 +947,11 @@ github.com/hashicorp/go-uuid v1.0.2-0.20191001231223-f32f5fe8d6a8/go.mod h1:6SBZ
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down Expand Up @@ -1257,7 +1258,10 @@ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
Expand Down
37 changes: 37 additions & 0 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ import (
jwt "github.com/golang-jwt/jwt"
slsession "github.com/softlayer/softlayer-go/session"

"github.com/IBM/configuration-aggregator-go-sdk/configurationaggregatorv1"

bluemix "github.com/IBM-Cloud/bluemix-go"
"github.com/IBM-Cloud/bluemix-go/api/account/accountv1"
"github.com/IBM-Cloud/bluemix-go/api/account/accountv2"
Expand Down Expand Up @@ -220,6 +222,7 @@ type ClientSession interface {
ContainerAPI() (containerv1.ContainerServiceAPI, error)
VpcContainerAPI() (containerv2.ContainerServiceAPI, error)
ContainerRegistryV1() (*containerregistryv1.ContainerRegistryV1, error)
ConfigurationAggregatorV1() (*configurationaggregatorv1.ConfigurationAggregatorV1, error)
FunctionClient() (*whisk.Client, error)
GlobalSearchAPI() (globalsearchv2.GlobalSearchServiceAPI, error)
GlobalTaggingAPI() (globaltaggingv3.GlobalTaggingServiceAPI, error)
Expand Down Expand Up @@ -327,6 +330,9 @@ type clientSession struct {
accountV1ConfigErr error
bmxAccountv1ServiceAPI accountv1.AccountServiceAPI

configurationAggregatorClient *configurationaggregatorv1.ConfigurationAggregatorV1
configurationAggregatorClientErr error

bmxUserDetails *UserConfig
bmxUserFetchErr error

Expand Down Expand Up @@ -667,6 +673,11 @@ func (session clientSession) PartnerCenterSellV1() (*partnercentersellv1.Partner
return session.partnerCenterSellClient, session.partnerCenterSellClientErr
}

// Configuration Aggregator
func (session clientSession) ConfigurationAggregatorV1() (*configurationaggregatorv1.ConfigurationAggregatorV1, error) {
return session.configurationAggregatorClient, session.configurationAggregatorClientErr
}

// AppIDAPI provides AppID Service APIs ...
func (session clientSession) AppIDAPI() (*appid.AppIDManagementV4, error) {
return session.appidAPI, session.appidErr
Expand Down Expand Up @@ -2381,6 +2392,32 @@ func (c *Config) ClientSession() (interface{}, error) {
// })
}

// Construct an instance of the 'Configuration Aggregator' service.
if session.configurationAggregatorClientErr == nil {
// Construct the service options.
authenticator := &core.IamAuthenticator{
ApiKey: "yXtlDkzR8R4oQGizdR3mms-07gEeh9IXLtkO36trhM5B",
URL: "https://iam.test.cloud.ibm.com",
}
configurationAggregatorClientOptions := &configurationaggregatorv1.ConfigurationAggregatorV1Options{
URL: "https://apprapp-dev-37b89de8caeb649450a9af91731f3589-0005.us-south.containers.appdomain.cloud/apprapp/config_aggregator/v1/instances/43f65e31-fd51-4fe1-8801-7a40b226df7f",
Authenticator: authenticator,
}

// Construct the service client.
session.configurationAggregatorClient, err = configurationaggregatorv1.NewConfigurationAggregatorV1(configurationAggregatorClientOptions)
if err == nil {
// Enable retries for API calls
session.configurationAggregatorClient.Service.EnableRetries(c.RetryCount, c.RetryDelay)
// Add custom header for analytics
session.configurationAggregatorClient.SetDefaultHeaders(gohttp.Header{
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})
} else {
session.configurationAggregatorClientErr = fmt.Errorf("Error occurred while constructing 'Configuration Aggregator' service client: %q", err)
}
}

// CIS Service instances starts here.
cisURL := ContructEndpoint("api.cis", cloudEndpoint)
if c.Visibility == "private" {
Expand Down
Loading

0 comments on commit c74f610

Please sign in to comment.