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

feat(cloud-integrations): Add GCP and AWS cloud integrations #2669

Draft
wants to merge 6 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
1 change: 1 addition & 0 deletions examples/modules/cloud-integrations/gcp/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ resource "newrelic_cloud_gcp_integrations" "gcp_integrations" {
storage {}
virtual_machines {}
vpc_access {}
ai_platform {}
}
55 changes: 55 additions & 0 deletions newrelic/resource_newrelic_cloud_gcp_integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func resourceNewrelicCloudGcpIntegrations() *schema.Resource {
Required: true,
ForceNew: true,
},
"ai_platform": {
Type: schema.TypeList,
Description: "GCP Vertex AI service",
Optional: true,
Elem: cloudGcpIntegrationsAiplatformSchemaElem(),
MaxItems: 1,
},
"alloy_db": {
Type: schema.TypeList,
Description: "GCP alloy DB integration",
Expand Down Expand Up @@ -229,6 +236,14 @@ func cloudGcpIntegrationSchemaBase() map[string]*schema.Schema {
}
}

// function to add schema for gcp ai_platform
func cloudGcpIntegrationsAiplatformSchemaElem() *schema.Resource {
s := cloudGcpIntegrationSchemaBase()
return &schema.Resource{
Schema: s,
}
}

// function to add schema for gcp AppEngine
func cloudGcpIntegrationsAlloyDBSchemaElem() *schema.Resource {
s := cloudGcpIntegrationSchemaBase()
Expand Down Expand Up @@ -492,6 +507,13 @@ func expandCloudGcpIntegrationsinputs(d *schema.ResourceData) (cloud.CloudIntegr
if lid, ok := d.GetOk("linked_account_id"); ok {
linkedAccountID = lid.(int)
}

if v, ok := d.GetOk("ai_platform"); ok {
gcpCloudIntegrations.GcpAiplatform = expandCloudGcpAiplatformIntegrationsinputs(v.([]interface{}), linkedAccountID)
} else if o, n := d.GetChange("ai_platform"); len(n.([]interface{})) < len(o.([]interface{})) {
gcpDisableIntegrations.GcpSpanner = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}

if v, ok := d.GetOk("alloy_db"); ok {
gcpCloudIntegrations.GcpAlloydb = expandCloudGcpAlloyDBIntegrationsInputs(v.([]interface{}), linkedAccountID)
} else if o, n := d.GetChange("alloy_db"); len(n.([]interface{})) < len(o.([]interface{})) {
Expand Down Expand Up @@ -656,6 +678,26 @@ func expandCloudGcpIntegrationsinputs(d *schema.ResourceData) (cloud.CloudIntegr
return configureInput, disableInput
}

// expand function to extract inputs from gcp ai platform schema
func expandCloudGcpAiplatformIntegrationsinputs(b []interface{}, linkedAccountID int) []cloud.CloudGcpAiplatformIntegrationInput {
expanded := make([]cloud.CloudGcpAiplatformIntegrationInput, len(b))
for i, expand := range b {
var input cloud.CloudGcpAiplatformIntegrationInput
if expand == nil {
input.LinkedAccountId = linkedAccountID
expanded[i] = input
return expanded
}
in := expand.(map[string]interface{})
input.LinkedAccountId = linkedAccountID
if m, ok := in["metrics_polling_interval"]; ok {
input.MetricsPollingInterval = m.(int)
}
expanded[i] = input
}
return expanded
}

// expand function to extract inputs from gcp app engine schema
func expandCloudGcpAppEngineIntegrationsinputs(b []interface{}, linkedAccountID int) []cloud.CloudGcpAppengineIntegrationInput {
expanded := make([]cloud.CloudGcpAppengineIntegrationInput, len(b))
Expand Down Expand Up @@ -1217,6 +1259,8 @@ func flattenCloudGcpLinkedAccount(d *schema.ResourceData, linkedAccount *cloud.C
_ = d.Set("linked_account_id", linkedAccount.ID)
for _, i := range linkedAccount.Integrations {
switch t := i.(type) {
case *cloud.CloudGcpAiplatformIntegration:
_ = d.Set("ai_platform", flattenCloudGcpAiplatformIntegration(t))
case *cloud.CloudGcpAlloydbIntegration:
_ = d.Set("alloy_db", flattenCloudGcpAlloyDBIntegration(t))
case *cloud.CloudGcpAppengineIntegration:
Expand Down Expand Up @@ -1273,6 +1317,14 @@ func flattenCloudGcpLinkedAccount(d *schema.ResourceData, linkedAccount *cloud.C
}
}

func flattenCloudGcpAiplatformIntegration(in *cloud.CloudGcpAiplatformIntegration) []interface{} {
flattened := make([]interface{}, 1)
out := make(map[string]interface{})
out["metrics_polling_interval"] = in.MetricsPollingInterval
flattened[0] = out
return flattened
}

// flatten function to set(store) outputs from the terraform apply
func flattenCloudGcpAppEngineIntegration(in *cloud.CloudGcpAppengineIntegration) []interface{} {
flattened := make([]interface{}, 1)
Expand Down Expand Up @@ -1585,6 +1637,9 @@ func expandCloudGcpDisableinputs(d *schema.ResourceData) cloud.CloudDisableInteg
if l, ok := d.GetOk("linked_account_id"); ok {
linkedAccountID = l.(int)
}
if _, ok := d.GetOk("ai_platform"); ok {
cloudGcpDisableInput.GcpAiplatform = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}
if _, ok := d.GetOk("alloy_db"); ok {
cloudGcpDisableInput.GcpAlloydb = []cloud.CloudDisableAccountIntegrationInput{{LinkedAccountId: linkedAccountID}}
}
Expand Down
6 changes: 6 additions & 0 deletions newrelic/resource_newrelic_cloud_gcp_integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ resource "newrelic_cloud_gcp_integrations" "foo1" {
provider = newrelic.cloud-integration-provider
account_id = "` + GCPIntegrationTestConfig["account_id"] + `"
linked_account_id = newrelic_cloud_gcp_link_account.foo.id
ai_platform {
metrics_polling_interval = 400
}
alloy_db {
metrics_polling_interval = 400
}
Expand Down Expand Up @@ -238,6 +241,9 @@ func testAccNewRelicCloudGcpIntegrationsConfigUpdated(GCPIntegrationTestConfig m
provider = newrelic.cloud-integration-provider
account_id = "` + GCPIntegrationTestConfig["account_id"] + `"
linked_account_id = newrelic_cloud_gcp_link_account.foo.id
ai_platform {
metrics_polling_interval = 1400
}
app_engine {
metrics_polling_interval = 1400
}
Expand Down
1 change: 0 additions & 1 deletion website/docs/r/cloud_aws_integrations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ The following arguments/integration blocks are intended to be used with a minimu
* `sns` - (Optional) AWS SNS. See [Integration blocks](#integration-blocks) below for details.
* `sqs` - (Optional) AWS SQS. See [Integration blocks](#integration-blocks) below for details.
* `x_ray` - (Optional) AWS X-Ray. See [Integration blocks](#integration-blocks) below for details.
x

The following arguments/integration blocks are intended to be used with a minimum `metrics_polling_interval` of 900 seconds.

Expand Down
11 changes: 8 additions & 3 deletions website/docs/r/cloud_gcp_integrations.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ resource "newrelic_cloud_gcp_link_account" "foo" {

resource "newrelic_cloud_gcp_integrations" "foo1" {
linked_account_id = newrelic_cloud_gcp_link_account.foo.id
ai_platform {
metrics_polling_interval = 300
}
app_engine {
metrics_polling_interval = 300
}
Expand Down Expand Up @@ -109,15 +112,17 @@ resource "newrelic_cloud_gcp_integrations" "foo1" {
}
}
```

## Argument Reference

-> **WARNING:** Starting with [v3.27.2](https://registry.terraform.io/providers/newrelic/newrelic/3.27.2) of the New Relic Terraform Provider, updating the `linked_account_id` of a `newrelic_cloud_gcp_integrations` resource that has been applied would **force a replacement** of the resource (destruction of the resource, followed by the creation of a new resource). When such an update is performed, please carefully review the output of `terraform plan`, which would clearly indicate a replacement of this resource, before performing a `terraform apply`.

* `account_id` - (Optional) The New Relic account ID to operate on. This allows the user to override the `account_id` attribute set on the provider. Defaults to the environment variable `NEW_RELIC_ACCOUNT_ID`.
* `linked_account_id` - (Required) The ID of the linked GCP account in New Relic.
- `account_id` - (Optional) The New Relic account ID to operate on. This allows the user to override the `account_id` attribute set on the provider. Defaults to the environment variable `NEW_RELIC_ACCOUNT_ID`.
- `linked_account_id` - (Required) The ID of the linked GCP account in New Relic.

The following arguments/integration blocks are intended to be used with a minimum `metrics_polling_interval` of 300 seconds.

* `ai_platform` - (Optional) Vertex AI integration. See [Integration blocks](#integration-blocks) below for details.
* `alloy_db` - (Optional) Alloy DB integration. See [Integration blocks](#integration-blocks) below for details.
* `app_engine` - (Optional) App Engine integration. See [Integration blocks](#integration-blocks) below for details.
* `big_query` - (Optional) Biq Query integration. See [Integration blocks](#integration-blocks) below for details.
Expand Down Expand Up @@ -159,7 +164,7 @@ Other integration supports an additional argument:
* `pub_sub`
* `spanner`
* `storage`
* `fetch_tags` - (Optional) Specify if labels and the extended inventory should be collected. May affect total data collection time and contribute to the Cloud provider API rate limit.
* `fetch_tags` - (Optional) Specify if labels and the extended inventory should be collected. May affect total data collection time and contribute to the Cloud provider API rate limit.

## Attributes Reference

Expand Down
Loading