Skip to content

Commit

Permalink
added in preliminary changes for v2 atracker (IBM-Cloud#3724)
Browse files Browse the repository at this point in the history
* added in preliminary changes for v2 atracker

* allow redacted key saves

* formatted

* fixes acceptance tests

* removed debugging log

* allow secret

* another fake secret

* added review corrections

* removed required flag

* fixes routes not being returned during migration

* additional fixes for routes usage in v1

* added example for logdna target

* fix for settings acting like put instead of patch

* fixes crn constantly showing up as a change as well as region

* fix for route always showing recieve global event change

* fix route flag being used

* added review comments

* Only add region if provided

* Documentation update

* take it from the response instead; Gave better error when ENV are missing

* adjusted setting region

* defaults empty strings in arrays

* env update here as well

* fixed comment changes as well as route workflow

* Fix route apply

* clean up

* force new instead of applyonce

* forces new target on region change

* doc update and update fix for routes

* Final clean up additions from acceptance tests

* prevent null api numver

Co-authored-by: Van Chau Bui <van.bui@ibm.com>
  • Loading branch information
2 people authored and SunithaGudisagarIBM1 committed Sep 14, 2022
1 parent 572ff98 commit f3b76e1
Show file tree
Hide file tree
Showing 26 changed files with 1,597 additions and 375 deletions.
13 changes: 13 additions & 0 deletions examples/ibm-atracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ These types of resources are supported:

* Activity Tracker Target
* Activity Tracker Route
* Activity Tracker Settings

## Usage

Expand Down Expand Up @@ -41,6 +42,17 @@ resource "atracker_route" "atracker_route_instance" {
}
```

atracker_settings resource:

```hcl
resource "atracker_settings" "atracker_settings_instance" {
metadata_region_primary = var.atracker_settings_metadata_region_primary
private_api_endpoint_only = var.atracker_settings_private_api_endpoint_only
default_targets = var.atracker_settings_default_targets
permitted_target_regions = var.atracker_settings_permitted_target_regions
}
```

## AtrackerV1 Data sources

atracker_targets data source:
Expand Down Expand Up @@ -107,3 +119,4 @@ data "atracker_endpoints" "atracker_endpoints_instance" {
| atracker_targets | atracker_targets object |
| atracker_routes | atracker_routes object |
| atracker_endpoints | atracker_endpoints object |
| atracker_settings | atracker_settings object |
22 changes: 21 additions & 1 deletion examples/ibm-atracker/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ resource "ibm_atracker_target" "atracker_target_instance" {
bucket = "my-atracker-bucket"
api_key = "xxxxxxxxxxxxxx"
}
region = var.atracker_target_region
}

// Provision atracker_target resource instance for logdna
resource "ibm_atracker_target" "atracker_target_logdna_instance" {
name = var.atracker_target_name
target_type = "logdna"
logdna_endpoint {
target_crn = "crn:v1:bluemix:public:logdna:us-south:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"
ingestion_key = "xxxxxxxxxxxxxx"
}
region = var.atracker_target_region
}

// Provision atracker_route resource instance
Expand All @@ -21,6 +33,14 @@ resource "ibm_atracker_route" "atracker_route_instance" {
rules = var.atracker_route_rules
}

// Provision atracker_settings resource instance
resource "ibm_atracker_settings" "atracker_settings_instance" {
metadata_region_primary = var.atracker_settings_metadata_region_primary
private_api_endpoint_only = var.atracker_settings_private_api_endpoint_only
default_targets = var.atracker_settings_default_targets
permitted_target_regions = var.atracker_settings_permitted_target_regions
}

// Create atracker_targets data source
data "ibm_atracker_targets" "atracker_targets_instance" {
name = var.atracker_targets_name
Expand All @@ -31,6 +51,6 @@ data "ibm_atracker_routes" "atracker_routes_instance" {
name = var.atracker_routes_name
}

// Create atracker_endpoints data source
// Create atracker_endpoints data source (DEPRECATED)
data "ibm_atracker_endpoints" "atracker_endpoints_instance" {
}
7 changes: 7 additions & 0 deletions examples/ibm-atracker/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ output "ibm_atracker_route" {
value = ibm_atracker_route.atracker_route_instance
description = "atracker_route resource instance"
}

// This allows atracker_settings data to be referenced by other resources and the terraform CLI
// Modify this if only certain data should be exposed
output "ibm_atracker_settings" {
value = ibm_atracker_settings.atracker_settings_instance
description = "atracker_settings resource instance"
}
21 changes: 21 additions & 0 deletions examples/ibm-atracker/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,26 @@ variable "atracker_routes_name" {
type = string
default = "my-route"
}
// Resource arguments for atracker_settings
variable "atracker_settings_metadata_region_primary" {
description = "To store all your meta data in a single region."
type = string
default = "us-south"
}
variable "atracker_settings_private_api_endpoint_only" {
description = "If you set this true then you cannot access api through public network."
type = bool
default = false
}
variable "atracker_settings_default_targets" {
description = "The target ID List. In the event that no routing rule causes the event to be sent to a target, these targets will receive the event."
type = list(string)
default = [ "c3af557f-fb0e-4476-85c3-0889e7fe7bc4" ]
}
variable "atracker_settings_permitted_target_regions" {
description = "If present then only these regions may be used to define a target."
type = list(string)
default = [ "us-south" ]
}

// Data source arguments for atracker_endpoints
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ require (
github.com/IBM/container-registry-go-sdk v0.0.15
github.com/IBM/event-notifications-go-admin-sdk v0.1.0
github.com/IBM/eventstreams-go-sdk v1.2.0
github.com/IBM/go-sdk-core/v5 v5.9.2
github.com/IBM/go-sdk-core/v5 v5.9.5
github.com/IBM/ibm-cos-sdk-go v1.8.0
github.com/IBM/ibm-cos-sdk-go-config v1.2.0
github.com/IBM/ibm-hpcs-tke-sdk v0.0.0-20211109141421-a4b61b05f7d1
github.com/IBM/keyprotect-go-client v0.7.0
github.com/IBM/networking-go-sdk v0.28.0
github.com/IBM/platform-services-go-sdk v0.22.6
github.com/IBM/platform-services-go-sdk v0.25.1
github.com/IBM/push-notifications-go-sdk v0.0.0-20210310100607-5790b96c47f5
github.com/IBM/scc-go-sdk v1.3.4
github.com/IBM/scc-go-sdk/v3 v3.1.6
Expand Down Expand Up @@ -52,7 +52,6 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/softlayer/softlayer-go v1.0.3
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/sys v0.0.0-20220330033206-e17cdc41300f // indirect
golang.org/x/tools v0.1.10 // indirect
google.golang.org/api v0.34.0 // indirect
gotest.tools v2.2.0+incompatible
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ github.com/IBM/go-sdk-core/v5 v5.6.3/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3bt
github.com/IBM/go-sdk-core/v5 v5.6.5/go.mod h1:tt/B9rxLkRtglE7pvqLuYikgCXaZFL3btdruJaoUeek=
github.com/IBM/go-sdk-core/v5 v5.7.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc=
github.com/IBM/go-sdk-core/v5 v5.8.0/go.mod h1:+YbdhrjCHC84ls4MeBp+Hj4NZCni+tDAc0XQUqRO9Jc=
github.com/IBM/go-sdk-core/v5 v5.8.2/go.mod h1:axE2JrRq79gIJTjKPBwV6gWHswvVptBjbcvvCPIxARM=
github.com/IBM/go-sdk-core/v5 v5.9.1/go.mod h1:axE2JrRq79gIJTjKPBwV6gWHswvVptBjbcvvCPIxARM=
github.com/IBM/go-sdk-core/v5 v5.9.2 h1:QKB5JwhlZfRvFHqcOwMeu/Dis/Q7qCBxrQLhx04onMc=
github.com/IBM/go-sdk-core/v5 v5.9.2/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/go-sdk-core/v5 v5.9.5 h1:+uMyHpOyBlFFd/I0PB+7JqqXOPY2DzRR0tbBjTc4d/g=
github.com/IBM/go-sdk-core/v5 v5.9.5/go.mod h1:YlOwV9LeuclmT/qi/LAK2AsobbAP42veV0j68/rlZsE=
github.com/IBM/ibm-cos-sdk-go v1.3.1/go.mod h1:YLBAYobEA8bD27P7xpMwSQeNQu6W3DNBtBComXrRzRY=
github.com/IBM/ibm-cos-sdk-go v1.8.0 h1:6d3BY+jo71JvQoyUwdtv4pemEfbnK/XSKQCKOEuWmks=
github.com/IBM/ibm-cos-sdk-go v1.8.0/go.mod h1:Oi8AC5WNDhmUJgbo1GL2FtBdo0nRgbzE/1HmCL1SERU=
Expand All @@ -88,8 +88,8 @@ github.com/IBM/keyprotect-go-client v0.7.0 h1:JstSHD14Lp6ihwQseyPuGcs1AjOBjAmcis
github.com/IBM/keyprotect-go-client v0.7.0/go.mod h1:SVr2ylV/fhSQPDiUjWirN9fsyWFCNNbt8GIT8hPJVjE=
github.com/IBM/networking-go-sdk v0.28.0 h1:kdZnHb9SaVd/NgYFpOlXfXSA8Q/mASBGaiAECxVI2i4=
github.com/IBM/networking-go-sdk v0.28.0/go.mod h1:tVxXclpQs8nQJYPTr9ZPNC1voaPNQLy8iy/72oVfFtM=
github.com/IBM/platform-services-go-sdk v0.22.6 h1:6op+tMkQk8Poqz6jY8AMA38TlXX/8j2xSi0Q04U7+r0=
github.com/IBM/platform-services-go-sdk v0.22.6/go.mod h1:0moTvGSCdWiSKPmXejOpblpfya/VgDSeG+x9Tjxy+qI=
github.com/IBM/platform-services-go-sdk v0.25.1 h1:hF4EvJNe8KRGiytN0mVJvJaZV4UJHsrJi1xIRgIaa5w=
github.com/IBM/platform-services-go-sdk v0.25.1/go.mod h1:9/v5qTMXaEBOpFe2marMukgCqv83W8PcjPWr91m2Ids=
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/scc-go-sdk v1.3.4 h1:nvSsyA2GfwjX3Aloty/LStkrY0e2rV2r+CM+YYg3zR4=
Expand Down
40 changes: 40 additions & 0 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import (
cisdomainsettingsv1 "github.com/IBM/networking-go-sdk/zonessettingsv1"
ciszonesv1 "github.com/IBM/networking-go-sdk/zonesv1"
"github.com/IBM/platform-services-go-sdk/atrackerv1"
"github.com/IBM/platform-services-go-sdk/atrackerv2"
"github.com/IBM/platform-services-go-sdk/catalogmanagementv1"
"github.com/IBM/platform-services-go-sdk/contextbasedrestrictionsv1"
"github.com/IBM/platform-services-go-sdk/enterprisemanagementv1"
Expand Down Expand Up @@ -275,6 +276,7 @@ type ClientSession interface {
CisFiltersSession() (*cisfiltersv1.FiltersV1, error)
CisFirewallRulesSession() (*cisfirewallrulesv1.FirewallRulesV1, error)
AtrackerV1() (*atrackerv1.AtrackerV1, error)
AtrackerV2() (*atrackerv2.AtrackerV2, error)
ESschemaRegistrySession() (*schemaregistryv1.SchemaregistryV1, error)
FindingsV1() (*findingsv1.FindingsV1, error)
AdminServiceApiV1() (*adminserviceapiv1.AdminServiceApiV1, error)
Expand Down Expand Up @@ -547,6 +549,9 @@ type clientSession struct {
atrackerClient *atrackerv1.AtrackerV1
atrackerClientErr error

atrackerClientV2 *atrackerv2.AtrackerV2
atrackerClientV2Err error

//Satellite link service
satelliteLinkClient *satellitelinkv1.SatelliteLinkV1
satelliteLinkClientErr error
Expand Down Expand Up @@ -1060,6 +1065,10 @@ func (session clientSession) AtrackerV1() (*atrackerv1.AtrackerV1, error) {
return session.atrackerClient, session.atrackerClientErr
}

func (session clientSession) AtrackerV2() (*atrackerv2.AtrackerV2, error) {
return session.atrackerClientV2, session.atrackerClientV2Err
}

func (session clientSession) ESschemaRegistrySession() (*schemaregistryv1.SchemaregistryV1, error) {
return session.esSchemaRegistryClient, session.esSchemaRegistryErr
}
Expand Down Expand Up @@ -1524,6 +1533,37 @@ func (c *Config) ClientSession() (interface{}, error) {
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})
}
// Version 2 Atracker
var atrackerClientV2URL string
if c.Visibility == "private" || c.Visibility == "public-and-private" {
atrackerClientV2URL, err = atrackerv2.GetServiceURLForRegion("private." + c.Region)
if err != nil && c.Visibility == "public-and-private" {
atrackerClientV2URL, err = atrackerv2.GetServiceURLForRegion(c.Region)
}
} else {
atrackerClientV2URL, err = atrackerv2.GetServiceURLForRegion(c.Region)
}
if err != nil {
atrackerClientV2URL = atrackerv2.DefaultServiceURL
}
if fileMap != nil && c.Visibility != "public-and-private" {
atrackerClientV2URL = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_ATRACKER_API_ENDPOINT", c.Region, atrackerClientV2URL)
}
atrackerClientV2Options := &atrackerv2.AtrackerV2Options{
Authenticator: authenticator,
URL: EnvFallBack([]string{"IBMCLOUD_ATRACKER_API_ENDPOINT"}, atrackerClientV2URL),
}
session.atrackerClientV2, err = atrackerv2.NewAtrackerV2(atrackerClientV2Options)
if err == nil {
// Enable retries for API calls
session.atrackerClientV2.Service.EnableRetries(c.RetryCount, c.RetryDelay)
// Add custom header for analytics
session.atrackerClientV2.SetDefaultHeaders(gohttp.Header{
"X-Original-User-Agent": {fmt.Sprintf("terraform-provider-ibm/%s", version.Version)},
})
} else {
session.atrackerClientV2Err = fmt.Errorf("Error occurred while configuring Activity Tracker API Version 2 service: %q", err)
}

// SCC FINDINGS Service
var findingsClientURL string
Expand Down
6 changes: 4 additions & 2 deletions ibm/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,9 @@ func Provider() *schema.Provider {
"ibm_resource_tag": globaltagging.ResourceIBMResourceTag(),

// // Atracker
"ibm_atracker_target": atracker.ResourceIBMAtrackerTarget(),
"ibm_atracker_route": atracker.ResourceIBMAtrackerRoute(),
"ibm_atracker_target": atracker.ResourceIBMAtrackerTarget(),
"ibm_atracker_route": atracker.ResourceIBMAtrackerRoute(),
"ibm_atracker_settings": atracker.ResourceIBMAtrackerSettings(),

// //Security and Compliance Center
"ibm_scc_si_note": scc.ResourceIBMSccSiNote(),
Expand Down Expand Up @@ -1114,6 +1115,7 @@ func Validator() validate.ValidatorDict {
"ibm_pi_volume": power.ResourceIBMPIVolumeValidator(),
"ibm_atracker_target": atracker.ResourceIBMAtrackerTargetValidator(),
"ibm_atracker_route": atracker.ResourceIBMAtrackerRouteValidator(),
"ibm_atracker_settings": atracker.ResourceIBMAtrackerSettingsValidator(),
"ibm_satellite_endpoint": satellite.ResourceIBMSatelliteEndpointValidator(),
"ibm_scc_si_note": scc.ResourceIBMSccSiNoteValidator(),
"ibm_scc_account_settings": scc.ResourceIBMSccAccountSettingsValidator(),
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/atracker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ This area is primarily for IBM provider contributors and maintainers. For inform
* IBM Provider Docs: [Home](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs)
* IBM Provider Docs: [One of the Activity Tracker resources](https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/atracker_route)
* IBM API Docs: [IBM API Docs for Activity Tracker](https://cloud.ibm.com/apidocs/atracker)
* IBM Activity Tracker SDK: [IBM SDK for Activity Tracker](https://github.com/IBM/platform-services-go-sdk/tree/main/atrackerv1)
* IBM Activity Tracker SDK: [IBM SDK for Activity Tracker](https://github.com/IBM/platform-services-go-sdk/tree/main/atrackerv2)
30 changes: 30 additions & 0 deletions ibm/service/atracker/atracker_utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package atracker

import (
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM/platform-services-go-sdk/atrackerv1"
"github.com/IBM/platform-services-go-sdk/atrackerv2"
)

const (
REDACTED_TEXT = "REDACTED"
)

func getAtrackerClients(meta interface{}) (
atrackerClientv1 *atrackerv1.AtrackerV1, atrackerClientv2 *atrackerv2.AtrackerV2, err error) {
atrackerClientv1, err = meta.(conns.ClientSession).AtrackerV1()
if err != nil {
return
}
atrackerClientv2, err = meta.(conns.ClientSession).AtrackerV2()
if err != nil {
return
}

_, err = meta.(conns.ClientSession).BluemixSession()
if err != nil {
return
}

return atrackerClientv1, atrackerClientv2, nil
}
7 changes: 3 additions & 4 deletions ibm/service/atracker/data_source_ibm_atracker_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"log"
"time"

"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand All @@ -18,8 +17,8 @@ import (

func DataSourceIBMAtrackerEndpoints() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceIBMAtrackerEndpointsRead,

ReadContext: dataSourceIBMAtrackerEndpointsRead,
DeprecationMessage: "use Settings instead",
Schema: map[string]*schema.Schema{
"api_endpoint": {
Type: schema.TypeList,
Expand Down Expand Up @@ -55,7 +54,7 @@ func DataSourceIBMAtrackerEndpoints() *schema.Resource {
}

func dataSourceIBMAtrackerEndpointsRead(context context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
atrackerClient, err := meta.(conns.ClientSession).AtrackerV1()
atrackerClient, _, err := getAtrackerClients(meta)
if err != nil {
return diag.FromErr(err)
}
Expand Down
Loading

0 comments on commit f3b76e1

Please sign in to comment.