-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add PDC network and PDC network token resources #1975
base: main
Are you sure you want to change the base?
Conversation
- Add resource lister function that will return a slice of resources
In order to lower resource usage and have a faster runtime, PRs will not run Cloud tests automatically. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good! Thanks a lot for starting it off. I've added some comments around the naming of things for now. We need a more thorough review of the terraform itself, we can get to that soon.
examples/resources/grafana_cloud_private_datasource_connect/resource.tf
Outdated
Show resolved
Hide resolved
examples/resources/grafana_cloud_private_datasource_connect/resource.tf
Outdated
Show resolved
Hide resolved
pdc_network_id = grafana_cloud_private_datasource_connect.test.network_id | ||
region = "us" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we pass the whole network resource as input? Then we could get the region from the network schema, and we wouldn't need to repeat the region
input in the token schema. This would feel more natural to me, since a token MUST be in the same region as its Access Policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is straightforward. I've updated the example to use the region from the previously created network.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I'll leave this comment open in case someone with some TF experience has input.
internal/resources/cloud/resource_private_datasource_connect.go
Outdated
Show resolved
Hide resolved
internal/resources/cloud/resource_private_datasource_connect.go
Outdated
Show resolved
Hide resolved
- Tidy up property names
Updated based on your suggestions @dafydd-t. I've also added a data source to allow retrieval of networks that may not be managed by TF. |
docs/data-sources/data_source.md
Outdated
@@ -59,6 +59,7 @@ data "grafana_data_source" "from_uid" { | |||
- `id` (String) The ID of this resource. | |||
- `is_default` (Boolean) Whether to set the data source as default. This should only be `true` to a single data source. | |||
- `json_data_encoded` (String) Serialized JSON string containing the json data. This attribute can be used to pass configuration options to the data source. To figure out what options a datasource has available, see its docs or inspect the network data when saving it from the Grafana UI. Note that keys in this map are usually camelCased. | |||
- `private_datasource_connect_network_id` (String) (Can only be used with data sources in Grafana Cloud) The ID of the private data source network to use with this data source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `private_datasource_connect_network_id` (String) (Can only be used with data sources in Grafana Cloud) The ID of the private data source network to use with this data source. | |
- `private_datasource_connect_network_id` (String) (Can only be used with data sources in Grafana Cloud) The ID of the Private Data source Connect network to use with this data source. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
page_title: "grafana_cloud_private_data_source_connect_networks Data Source - terraform-provider-grafana" | ||
subcategory: "Cloud" | ||
description: |- | ||
Fetches Private data source connect networks from Grafana Cloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetches Private data source connect networks from Grafana Cloud. | |
Fetches Private Data source Connect networks from Grafana Cloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doh i see this is generated, but please update in the source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in source
|
||
# grafana_cloud_private_data_source_connect_networks (Data Source) | ||
|
||
Fetches Private data source connect networks from Grafana Cloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetches Private data source connect networks from Grafana Cloud. | |
Fetches Private Data source Connect networks from Grafana Cloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
) | ||
} | ||
|
||
type PrivateDatasourceConnectNetworksDataSource struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we be consistent about typing on Datasource
please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be OK to use PDC in the type names too - up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to using PDC
@aangelisc do you have an example terraform plan that you used to run this locally? I'd love to give it a go |
Hey @dafydd-t, I've pushed some more updates 😊 You should be able to test this with the following tf: terraform {
required_providers {
grafana = {
source = "grafana/grafana"
}
}
}
provider "grafana" {
alias = "cloud"
cloud_access_policy_token = "<token>"
}
data "grafana_cloud_stack" "stack" {
provider = grafana.cloud
slug = "stack"
}
resource "grafana_cloud_stack_service_account" "cloud_sa" {
provider = grafana.cloud
stack_slug = data.grafana_cloud_stack.stack.slug
name = "pdc-test-sa"
role = "Admin"
is_disabled = false
}
resource "grafana_cloud_stack_service_account_token" "cloud_sa" {
provider = grafana.cloud
stack_slug = data.grafana_cloud_stack.stack.slug
name = "terraform serviceaccount key"
service_account_id = grafana_cloud_stack_service_account.cloud_sa.id
}
provider "grafana" {
alias = "stack"
url = data.grafana_cloud_stack.stack.url
auth = grafana_cloud_stack_service_account_token.cloud_sa.key
cloud_access_policy_token = "<token>"
}
resource "grafana_cloud_private_data_source_connect_network" "test" {
provider = grafana.stack
region = data.grafana_cloud_stack.stack.region_slug
name = "test-pdc"
display_name = "Test PDC"
stack_identifier = data.grafana_cloud_stack.stack.id
}
resource "grafana_cloud_private_data_source_connect_network_token" "test" {
provider = grafana.stack
pdc_network_id = grafana_cloud_private_data_source_connect_network.test.pdc_network_id
region = grafana_cloud_private_data_source_connect_network.test.region
name = "my-pdc-token"
display_name = "My PDC Token"
}
resource "grafana_data_source" "influxdb" {
provider = grafana.stack
type = "influxdb"
name = "pdc-test-influx"
url = "http://influxdb.example.net:8086/"
basic_auth_enabled = true
basic_auth_username = "username"
database_name = "dbname" // Example: influxdb_database.metrics.name
json_data_encoded = jsonencode({
authType = "default"
basicAuthPassword = "mypassword"
})
private_data_source_connect_network_id = grafana_cloud_private_data_source_connect_network.test.pdc_network_id
}
|
Feedback welcome here (my first time creating some TF resources), this is essentially a duplicate of the access policy and token resources with some minor changes that are specific to PDC.
Fixes #1222
Fixes #1638