From 91894b0f96e11c3128e300bf5266d86152379edf Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 9 Oct 2024 11:44:41 -0700 Subject: [PATCH 1/3] Add automation --- .ci-mgmt.yaml | 1 + Makefile | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.ci-mgmt.yaml b/.ci-mgmt.yaml index 749440b7..66ede22e 100644 --- a/.ci-mgmt.yaml +++ b/.ci-mgmt.yaml @@ -16,3 +16,4 @@ plugins: version: "5.0.0" team: ecosystem pulumiConvert: 1 +registryDocs: true diff --git a/Makefile b/Makefile index 0ac041ec..58ef860c 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ development: install_plugins provider build_sdks install_sdks build: install_plugins provider build_sdks install_sdks -build_sdks: build_nodejs build_python build_dotnet build_go build_java +build_sdks: build_nodejs build_python build_dotnet build_go build_java build_registry_docs install_go_sdk: @@ -96,6 +96,10 @@ build_python: upstream cd ./bin && \ ../venv/bin/python -m build . +# Run the bridge's registry-docs command to generated the content of the installation docs/ folder at provider repo root +build_registry_docs: + $(WORKING_DIR)/bin/$(TFGEN) registry-docs --out $(WORKING_DIR)/docs + clean: rm -rf sdk/{dotnet,nodejs,go,python} From 814c270334e15add1529ef29447dfc66f0f2abd6 Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 9 Oct 2024 11:45:23 -0700 Subject: [PATCH 2/3] Add replacement rules to fix up examples and pulumi flag --- docs/_index.md | 703 ++++++++++++++++++ .../installation-replaces/example-desired.md | 52 ++ .../installation-replaces/example-input.md | 61 ++ provider/resources.go | 45 ++ 4 files changed, 861 insertions(+) create mode 100644 docs/_index.md create mode 100644 provider/installation-replaces/example-desired.md create mode 100644 provider/installation-replaces/example-input.md diff --git a/docs/_index.md b/docs/_index.md new file mode 100644 index 00000000..7a48c297 --- /dev/null +++ b/docs/_index.md @@ -0,0 +1,703 @@ +--- +title: Sumologic Provider +meta_desc: Provides an overview on how to configure the Pulumi Sumologic provider. +layout: package +--- +## Installation + +The sumologic provider is available as a package in all Pulumi languages: + +* JavaScript/TypeScript: [`@pulumi/sumologic`](https://www.npmjs.com/package/@pulumi/sumologic) +* Python: [`pulumi-sumologic`](https://pypi.org/project/pulumi-sumologic/) +* Go: [`github.com/pulumi/pulumi-sumologic/sdk/go/sumologic`](https://github.com/pulumi/pulumi-sumologic) +* .NET: [`Pulumi.Sumologic`](https://www.nuget.org/packages/Pulumi.Sumologic) +* Java: [`com.pulumi/sumologic`](https://central.sonatype.com/artifact/com.pulumi/sumologic) +## Overview + +This provider is used to manage resources supported by Sumo Logic. The provider needs to be configured with the proper credentials before it can be used. +## Example Usage +### Configure the Sumo Logic Provider +{{< chooser language "typescript,python,go,csharp,java,yaml" >}} +{{% choosable language typescript %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: nodejs +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as sumologic from "@pulumi/sumologic"; + +const config = new pulumi.Config(); +// Sumo Logic Access ID +const sumologicAccessId = config.require("sumologicAccessId"); +// Sumo Logic Access Key +const sumologicAccessKey = config.require("sumologicAccessKey"); +// Create a collector +const collector = new sumologic.Collector("collector", {name: "MyCollector"}); +// Create a HTTP source +const httpSource = new sumologic.HttpSource("http_source", { + name: "http-source", + category: "my/source/category", + collectorId: collector.id, +}); +``` +{{% /choosable %}} +{{% choosable language python %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: python +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```python +import pulumi +import pulumi_sumologic as sumologic + +config = pulumi.Config() +# Sumo Logic Access ID +sumologic_access_id = config.require("sumologicAccessId") +# Sumo Logic Access Key +sumologic_access_key = config.require("sumologicAccessKey") +# Create a collector +collector = sumologic.Collector("collector", name="MyCollector") +# Create a HTTP source +http_source = sumologic.HttpSource("http_source", + name="http-source", + category="my/source/category", + collector_id=collector.id) +``` +{{% /choosable %}} +{{% choosable language csharp %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: dotnet +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using SumoLogic = Pulumi.SumoLogic; + +return await Deployment.RunAsync(() => +{ + var config = new Config(); + // Sumo Logic Access ID + var sumologicAccessId = config.Require("sumologicAccessId"); + // Sumo Logic Access Key + var sumologicAccessKey = config.Require("sumologicAccessKey"); + // Create a collector + var collector = new SumoLogic.Collector("collector", new() + { + Name = "MyCollector", + }); + + // Create a HTTP source + var httpSource = new SumoLogic.HttpSource("http_source", new() + { + Name = "http-source", + Category = "my/source/category", + CollectorId = collector.Id, + }); + +}); + +``` +{{% /choosable %}} +{{% choosable language go %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: go +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```go +package main + +import ( + "github.com/pulumi/pulumi-sumologic/sdk/go/sumologic" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + cfg := config.New(ctx, "") + // Sumo Logic Access ID + sumologicAccessId := cfg.Require("sumologicAccessId") + // Sumo Logic Access Key + sumologicAccessKey := cfg.Require("sumologicAccessKey") + // Create a collector + collector, err := sumologic.NewCollector(ctx, "collector", &sumologic.CollectorArgs{ + Name: pulumi.String("MyCollector"), + }) + if err != nil { + return err + } + // Create a HTTP source + _, err = sumologic.NewHttpSource(ctx, "http_source", &sumologic.HttpSourceArgs{ + Name: pulumi.String("http-source"), + Category: pulumi.String("my/source/category"), + CollectorId: collector.ID(), + }) + if err != nil { + return err + } + return nil + }) +} +``` +{{% /choosable %}} +{{% choosable language yaml %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: yaml +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```yaml +configuration: + # Setup authentication variables. See "Authentication" section for more details. + sumologicAccessId: + type: string + sumologicAccessKey: + type: string +resources: + # Create a collector + collector: + type: sumologic:Collector + properties: + name: MyCollector + # Create a HTTP source + httpSource: + type: sumologic:HttpSource + name: http_source + properties: + name: http-source + category: my/source/category + collectorId: ${collector.id} +``` +{{% /choosable %}} +{{% choosable language java %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: java +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:environment: + value: us2 + +``` +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.sumologic.Collector; +import com.pulumi.sumologic.CollectorArgs; +import com.pulumi.sumologic.HttpSource; +import com.pulumi.sumologic.HttpSourceArgs; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class App { + public static void main(String[] args) { + Pulumi.run(App::stack); + } + + public static void stack(Context ctx) { + final var config = ctx.config(); + final var sumologicAccessId = config.get("sumologicAccessId"); + final var sumologicAccessKey = config.get("sumologicAccessKey"); + // Create a collector + var collector = new Collector("collector", CollectorArgs.builder() + .name("MyCollector") + .build()); + + // Create a HTTP source + var httpSource = new HttpSource("httpSource", HttpSourceArgs.builder() + .name("http-source") + .category("my/source/category") + .collectorId(collector.id()) + .build()); + + } +} +``` +{{% /choosable %}} +{{< /chooser >}} +### Configure the Sumo Logic Provider in Admin Mode +{{< chooser language "typescript,python,go,csharp,java,yaml" >}} +{{% choosable language typescript %}} +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as sumologic from "@pulumi/sumologic"; + +// Look up the Admin Recommended Folder +const folder = sumologic.getAdminRecommendedFolder({}); +// Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) +const test = new sumologic.Folder("test", { + name: "test", + description: "A test folder", + parentId: folder.then(folder => folder.id), +}); +``` +{{% /choosable %}} +{{% choosable language python %}} +```python +import pulumi +import pulumi_sumologic as sumologic + +# Look up the Admin Recommended Folder +folder = sumologic.get_admin_recommended_folder() +# Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) +test = sumologic.Folder("test", + name="test", + description="A test folder", + parent_id=folder.id) +``` +{{% /choosable %}} +{{% choosable language csharp %}} +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using SumoLogic = Pulumi.SumoLogic; + +return await Deployment.RunAsync(() => +{ + // Look up the Admin Recommended Folder + var folder = SumoLogic.GetAdminRecommendedFolder.Invoke(); + + // Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) + var test = new SumoLogic.Folder("test", new() + { + Name = "test", + Description = "A test folder", + ParentId = folder.Apply(getAdminRecommendedFolderResult => getAdminRecommendedFolderResult.Id), + }); + +}); + +``` +{{% /choosable %}} +{{% choosable language go %}} +```go +package main + +import ( + "github.com/pulumi/pulumi-sumologic/sdk/go/sumologic" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + // Look up the Admin Recommended Folder + folder, err := sumologic.GetAdminRecommendedFolder(ctx, nil, nil) + if err != nil { + return err + } + // Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) + _, err = sumologic.NewFolder(ctx, "test", &sumologic.FolderArgs{ + Name: pulumi.String("test"), + Description: pulumi.String("A test folder"), + ParentId: pulumi.String(folder.Id), + }) + if err != nil { + return err + } + return nil + }) +} +``` +{{% /choosable %}} +{{% choosable language yaml %}} +```yaml +resources: + # Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) + test: + type: sumologic:Folder + properties: + name: test + description: A test folder + parentId: ${folder.id} +variables: + # Look up the Admin Recommended Folder + folder: + fn::invoke: + Function: sumologic:getAdminRecommendedFolder + Arguments: {} +``` +{{% /choosable %}} +{{% choosable language java %}} +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.sumologic.SumologicFunctions; +import com.pulumi.sumologic.inputs.GetAdminRecommendedFolderArgs; +import com.pulumi.sumologic.Folder; +import com.pulumi.sumologic.FolderArgs; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class App { + public static void main(String[] args) { + Pulumi.run(App::stack); + } + + public static void stack(Context ctx) { + // Look up the Admin Recommended Folder + final var folder = SumologicFunctions.getAdminRecommendedFolder(); + + // Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) + var test = new Folder("test", FolderArgs.builder() + .name("test") + .description("A test folder") + .parentId(folder.applyValue(getAdminRecommendedFolderResult -> getAdminRecommendedFolderResult.id())) + .build()); + + } +} +``` +{{% /choosable %}} +{{< /chooser >}} +## Authentication +The Sumo Logic Provider offers a flexible means of providing credentials for authentication. The following methods are supported and explained below: + +- Static credentials +- Environment variables +### Static credentials +Static credentials can be provided by adding an `accessId` and `accessKey` in-line in the Sumo Logic provider configuration: + +Usage: +{{< chooser language "typescript,python,go,csharp,java,yaml" >}} +{{% choosable language typescript %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: nodejs +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{% choosable language python %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: python +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{% choosable language csharp %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: dotnet +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{% choosable language go %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: go +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{% choosable language yaml %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: yaml +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{% choosable language java %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: java +config: + sumologic:accessId: + value: your-access-id + sumologic:accessKey: + value: your-access-key + sumologic:environment: + value: us2 + +``` + +{{% /choosable %}} +{{< /chooser >}} +### Environment variables +You can provide your credentials via the `SUMOLOGIC_ACCESSID` and `SUMOLOGIC_ACCESSKEY` environment variables, representing your Sumo Logic Access ID and Sumo Logic Access Key, respectively. + +Usage: +{{< chooser language "typescript,python,go,csharp,java,yaml" >}} +{{% choosable language typescript %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: nodejs + +``` + +{{% /choosable %}} +{{% choosable language python %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: python + +``` + +{{% /choosable %}} +{{% choosable language csharp %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: dotnet + +``` + +{{% /choosable %}} +{{% choosable language go %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: go + +``` + +{{% /choosable %}} +{{% choosable language yaml %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: yaml + +``` + +{{% /choosable %}} +{{% choosable language java %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: java + +``` + +{{% /choosable %}} +{{< /chooser >}} + +```bash +$ export SUMOLOGIC_ACCESSID="your-access-id" +$ export SUMOLOGIC_ACCESSKEY="your-access-key" +$ export SUMOLOGIC_ENVIRONMENT=us2 +$ pulumi preview +``` +## Configuration Reference +- `accessId` - (Required) This is the Sumo Logic Access ID. It must be provided, but it can also be source from the SUMOLOGIC_ACCESSID environment variable. +- `accessKey` - (Required) This is the Sumo Logic Access Key. It must be provided, but it can also be sourced from the SUMOLOGIC_ACCESSKEY variable. +- `environment` - (Required) This is the API endpoint to use. See the [Sumo Logic documentation](https://help.sumologic.com/APIs/General_API_Information/Sumo_Logic_Endpoints_and_Firewall_Security) for details on which environment you should use. It must be provided, but it can be sourced from the SUMOLOGIC_ENVIRONMENT variable. +## Common Source Properties + +The following properties are common to ALL sources and can be used to configure each source. + +- `collectorId` - (Required) The ID of the collector to attach this source to. +- `name` - (Required) The name of the source. This is required, and has to be unique in the scope of the collector. Changing this will force recreation the source. +- `description` - (Optional) Description of the source. +- `category` - (Optional) The source category this source logs to. +- `hostName` - (Optional) The source host this source logs to. +- `timezone` - (Optional) The timezone assigned to the source. The value follows the [tzdata](https://en.wikipedia.org/wiki/Tz_database) naming convention. +- `automaticDateParsing` - (Optional) Determines if timestamp information is parsed or not. Type true to enable automatic parsing of dates (the default setting); type false to disable. If disabled, no timestamp information is parsed at all. +- `multilineProcessingEnabled` - (Optional) Type true to enable; type false to disable. The default setting is true. Consider setting to false to avoid unnecessary processing if you are collecting single message per line files (for example, Linux system.log). If you're working with multiline messages (for example, log4J or exception stack traces), keep this setting enabled. +- `useAutolineMatching` - (Optional) Type true to enable if you'd like message boundaries to be inferred automatically; type false to prevent message boundaries from being automatically inferred (equivalent to the Infer Boundaries option in the UI). The default setting is true. +- `manualPrefixRegexp` - (Optional) When using useAutolineMatching=false, type a regular expression that matches the first line of the message to manually create the boundary. Note that any special characters in the regex, such as backslashes or double quotes, must be escaped. +- `forceTimezone` - (Optional) Type true to force the source to use a specific time zone, otherwise type false to use the time zone found in the logs. The default setting is false. +- `defaultDateFormats` - (Optional) Define the format for the timestamps present in your log messages. You can specify a locator regex to identify where timestamps appear in log lines. Requires 'automatic_date_parsing' set to True. + + `format` - (Required) The timestamp format supplied as a Java SimpleDateFormat, or "epoch" if the timestamp is in epoch format. + + `locator` - (Optional) Regular expression to locate the timestamp within the messages. + + Usage: + {{< chooser language "typescript,python,go,csharp,java,yaml" >}} + {{% choosable language typescript %}} + +{{% /choosable %}} +{{% choosable language python %}} + +{{% /choosable %}} +{{% choosable language csharp %}} + +{{% /choosable %}} +{{% choosable language go %}} + +{{% /choosable %}} +{{% choosable language yaml %}} + +{{% /choosable %}} +{{% choosable language java %}} + +{{% /choosable %}} +{{< /chooser >}} + +- `filters` - (Optional) If you'd like to add a filter to the source. + + `filterType` - (Required) The type of filter to apply. (Exclude, Include, Mask, or Hash) + + `name` - (Required) The Name for the filter. + + `regexp` - (Required) Regular expression to match within the messages. When used with Incude/Exclude the expression must match the entire message. When used with Mask/Hash rules the expression must contain an unnamed capture group to hash/mask. + + `mask` - (Optional) When applying a Mask rule, replaces the detected expression with this string. + + Usage: + {{< chooser language "typescript,python,go,csharp,java,yaml" >}} + {{% choosable language typescript %}} + +{{% /choosable %}} +{{% choosable language python %}} + +{{% /choosable %}} +{{% choosable language csharp %}} + +{{% /choosable %}} +{{% choosable language go %}} + +{{% /choosable %}} +{{% choosable language yaml %}} + +{{% /choosable %}} +{{% choosable language java %}} + +{{% /choosable %}} +{{< /chooser >}} + +- `hashAlgorithm` - (Optional) Define the hash algorithm used for Hash type filters. Available values are "MD5" and "SHA-256". The default value will be "MD5". +- `cutoffTimestamp` - (Optional) Only collect data more recent than this timestamp, specified as milliseconds since epoch (13 digit). This maps to the `Collection should begin` field on the UI. Example: using `1663786159000` will set the cutoff timestamp to `Wednesday, September 21, 2022 6:49:19 PM GMT` +- `cutoffRelativeTime` - (Optional) Can be specified instead of cutoffTimestamp to provide a relative offset with respect to the current time.This maps to the `Collection should begin` field on the UI. Example: use -1h, -1d, or -1w to collect data that's less than one hour, one day, or one week old, respectively. +- `fields` - (Optional) Map containing key/value pairs. + + Usage: + {{< chooser language "typescript,python,go,csharp,java,yaml" >}} + {{% choosable language typescript %}} + +{{% /choosable %}} +{{% choosable language python %}} + +{{% /choosable %}} +{{% choosable language csharp %}} + +{{% /choosable %}} +{{% choosable language go %}} + +{{% /choosable %}} +{{% choosable language yaml %}} + +{{% /choosable %}} +{{% choosable language java %}} + +{{% /choosable %}} +{{< /chooser >}} +## Configuring SNS Subscription +This is supported in the following resources. +- `sumologic.CloudfrontSource` +- `sumologic.CloudtrailSource` +- `sumologic.ElbSource` +- `sumologic.S3AuditSource` +- `sumologic.S3Source` + +Steps to configure SNS subscription and sync the state in terrform: +- Step 1: Create the source via pulumi. +- Step 2: Setup [SNS subscription](https://help.sumologic.com/03Send-Data/Sources/02Sources-for-Hosted-Collectors/Amazon-Web-Services/AWS_Sources#set-up-sns-in-aws-highly-recommended) outside of pulumi on Sumologic UI. +- Step 3: Run `pulumi preview --refresh` to review the changes and verify the state with the SNS subscription information. Make sure only `snsTopicOrSubscriptionArn` is updated. If SNS has been successfully configured and has received a subscription confirmation request `isSuccess` parameter will be true. +- Step 4: Apply the changes with `pulumi up --refresh`. \ No newline at end of file diff --git a/provider/installation-replaces/example-desired.md b/provider/installation-replaces/example-desired.md new file mode 100644 index 00000000..299e88c9 --- /dev/null +++ b/provider/installation-replaces/example-desired.md @@ -0,0 +1,52 @@ +### Configure the Sumo Logic Provider +```hcl +# Setup authentication variables. See "Authentication" section for more details. +variable "sumologic_access_id" { + type = string + description = "Sumo Logic Access ID" +} +variable "sumologic_access_key" { + type = string + description = "Sumo Logic Access Key" + sensitive = true +} + +provider "sumologic" { + access_id = "${var.sumologic_access_id}" + access_key = "${var.sumologic_access_key}" + environment = "us2" +} + +# Create a collector +resource "sumologic_collector" "collector" { + name = "MyCollector" +} + +# Create a HTTP source +resource "sumologic_http_source" "http_source" { + name = "http-source" + category = "my/source/category" + collector_id = "${sumologic_collector.collector.id}" +} +``` +### Configure the Sumo Logic Provider in Admin Mode +```hcl +provider "sumologic" { + access_id = "${var.sumologic_access_id}" + access_key = "${var.sumologic_access_key}" + environment = "us2" + admin_mode = true + alias = "admin" +} + +# Look up the Admin Recommended Folder +data "sumologic_admin_recommended_folder" "folder" {} + +# Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) +resource "sumologic_folder" "test" { + provider = sumologic.admin + name = "test" + description = "A test folder" + parent_id = data.sumologic_admin_recommended_folder.folder.id +} +``` \ No newline at end of file diff --git a/provider/installation-replaces/example-input.md b/provider/installation-replaces/example-input.md new file mode 100644 index 00000000..b169f94d --- /dev/null +++ b/provider/installation-replaces/example-input.md @@ -0,0 +1,61 @@ +```hcl +terraform { + required_providers { + sumologic = { + source = "sumologic/sumologic" + version = "" # set the Sumo Logic Terraform Provider version + } + } + required_version = ">= 0.13" +} + +# Setup authentication variables. See "Authentication" section for more details. +variable "sumologic_access_id" { + type = string + description = "Sumo Logic Access ID" +} +variable "sumologic_access_key" { + type = string + description = "Sumo Logic Access Key" + sensitive = true +} + +# Configure the Sumo Logic Provider +provider "sumologic" { + access_id = "${var.sumologic_access_id}" + access_key = "${var.sumologic_access_key}" + environment = "us2" +} + +# Create a collector +resource "sumologic_collector" "collector" { + name = "MyCollector" +} + +# Create a HTTP source +resource "sumologic_http_source" "http_source" { + name = "http-source" + category = "my/source/category" + collector_id = "${sumologic_collector.collector.id}" +} + +# Configure the Sumo Logic Provider in Admin Mode +provider "sumologic" { + access_id = "${var.sumologic_access_id}" + access_key = "${var.sumologic_access_key}" + environment = "us2" + admin_mode = true + alias = "admin" +} + +# Look up the Admin Recommended Folder +data "sumologic_admin_recommended_folder" "folder" {} + +# Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) +resource "sumologic_folder" "test" { + provider = sumologic.admin + name = "test" + description = "A test folder" + parent_id = data.sumologic_admin_recommended_folder.folder.id +} +``` \ No newline at end of file diff --git a/provider/resources.go b/provider/resources.go index 5b7ebf86..519f08ce 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -15,7 +15,9 @@ package sumologic import ( + "bytes" "fmt" + "os" "path" _ "embed" // embed package blank import @@ -62,6 +64,7 @@ func Provider() tfbridge.ProviderInfo { UpstreamRepoPath: "./upstream", Version: version.Version, MetadataInfo: tfbridge.NewProviderMetadata(metadata), + DocRules: &tfbridge.DocRuleInfo{EditRules: editRules}, Config: map[string]*tfbridge.SchemaInfo{ "environment": { Default: &tfbridge.DefaultInfo{ @@ -150,3 +153,45 @@ func Provider() tfbridge.ProviderInfo { return prov } + +func editRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit { + return append( + defaults, + replaceRefresh, + fixInstallationExample, + ) +} + +// Fix up TF command to Pulumi equivalent +var replaceRefresh = tfbridge.DocsEdit{ + Path: "index.html.markdown", + Edit: func(_ string, content []byte) ([]byte, error) { + b := bytes.ReplaceAll( + content, + []byte("-refresh-only"), + []byte("--refresh"), + ) + return b, nil + }, +} + +// In the upstream example, two providers are defined in the same code block. +// Pulumi Convert is not set up to handle this case, so this edit breaks the example up into two separate code blocks. +var fixInstallationExample = tfbridge.DocsEdit{ + Path: "index.html.markdown", + Edit: func(_ string, content []byte) ([]byte, error) { + input, err := os.ReadFile("provider/installation-replaces/example-input.md") + if err != nil { + return nil, err + } + replace, err := os.ReadFile("provider/installation-replaces/example-desired.md") + if err != nil { + return nil, err + } + b := bytes.ReplaceAll( + content, + input, + replace) + return b, nil + }, +} From 7e03d7d982fcefe02ea9b31359955896cb99afb2 Mon Sep 17 00:00:00 2001 From: guineveresaenger Date: Wed, 9 Oct 2024 12:35:22 -0700 Subject: [PATCH 3/3] Remove untranslateable snippets --- docs/_index.md | 185 +++++++++++------- .../installation-replaces/example-desired.md | 11 +- .../installation-replaces/usage1-input.md | 7 + .../installation-replaces/usage2-input.md | 14 ++ .../installation-replaces/usage3-input.md | 7 + provider/resources.go | 23 +++ 6 files changed, 179 insertions(+), 68 deletions(-) create mode 100644 provider/installation-replaces/usage1-input.md create mode 100644 provider/installation-replaces/usage2-input.md create mode 100644 provider/installation-replaces/usage3-input.md diff --git a/docs/_index.md b/docs/_index.md index 7a48c297..a0aa6cc4 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -276,10 +276,30 @@ public class App { ### Configure the Sumo Logic Provider in Admin Mode {{< chooser language "typescript,python,go,csharp,java,yaml" >}} {{% choosable language typescript %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: nodejs +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` ```typescript import * as pulumi from "@pulumi/pulumi"; import * as sumologic from "@pulumi/sumologic"; +const config = new pulumi.Config(); +// Sumo Logic Access ID +const sumologicAccessId = config.require("sumologicAccessId"); +// Sumo Logic Access Key +const sumologicAccessKey = config.require("sumologicAccessKey"); // Look up the Admin Recommended Folder const folder = sumologic.getAdminRecommendedFolder({}); // Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) @@ -291,10 +311,30 @@ const test = new sumologic.Folder("test", { ``` {{% /choosable %}} {{% choosable language python %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: python +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` ```python import pulumi import pulumi_sumologic as sumologic +config = pulumi.Config() +# Sumo Logic Access ID +sumologic_access_id = config.require("sumologicAccessId") +# Sumo Logic Access Key +sumologic_access_key = config.require("sumologicAccessKey") # Look up the Admin Recommended Folder folder = sumologic.get_admin_recommended_folder() # Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) @@ -305,6 +345,21 @@ test = sumologic.Folder("test", ``` {{% /choosable %}} {{% choosable language csharp %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: dotnet +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` ```csharp using System.Collections.Generic; using System.Linq; @@ -313,6 +368,11 @@ using SumoLogic = Pulumi.SumoLogic; return await Deployment.RunAsync(() => { + var config = new Config(); + // Sumo Logic Access ID + var sumologicAccessId = config.Require("sumologicAccessId"); + // Sumo Logic Access Key + var sumologicAccessKey = config.Require("sumologicAccessKey"); // Look up the Admin Recommended Folder var folder = SumoLogic.GetAdminRecommendedFolder.Invoke(); @@ -329,16 +389,37 @@ return await Deployment.RunAsync(() => ``` {{% /choosable %}} {{% choosable language go %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: go +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` ```go package main import ( "github.com/pulumi/pulumi-sumologic/sdk/go/sumologic" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config" ) func main() { pulumi.Run(func(ctx *pulumi.Context) error { + cfg := config.New(ctx, "") + // Sumo Logic Access ID + sumologicAccessId := cfg.Require("sumologicAccessId") + // Sumo Logic Access Key + sumologicAccessKey := cfg.Require("sumologicAccessKey") // Look up the Admin Recommended Folder folder, err := sumologic.GetAdminRecommendedFolder(ctx, nil, nil) if err != nil { @@ -360,6 +441,26 @@ func main() { {{% /choosable %}} {{% choosable language yaml %}} ```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: yaml +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` +```yaml +configuration: + sumologicAccessId: + type: string + sumologicAccessKey: + type: string resources: # Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) test: @@ -377,6 +478,21 @@ variables: ``` {{% /choosable %}} {{% choosable language java %}} +```yaml +# Pulumi.yaml provider configuration file +name: configuration-example +runtime: java +config: + sumologic:accessId: + value: 'TODO: "${var.sumologic_access_id}"' + sumologic:accessKey: + value: 'TODO: "${var.sumologic_access_key}"' + sumologic:adminMode: + value: true + sumologic:environment: + value: us2 + +``` ```java package generated_program; @@ -400,6 +516,9 @@ public class App { } public static void stack(Context ctx) { + final var config = ctx.config(); + final var sumologicAccessId = config.get("sumologicAccessId"); + final var sumologicAccessKey = config.get("sumologicAccessKey"); // Look up the Admin Recommended Folder final var folder = SumologicFunctions.getAdminRecommendedFolder(); @@ -612,82 +731,16 @@ The following properties are common to ALL sources and can be used to configure + `format` - (Required) The timestamp format supplied as a Java SimpleDateFormat, or "epoch" if the timestamp is in epoch format. + `locator` - (Optional) Regular expression to locate the timestamp within the messages. - Usage: - {{< chooser language "typescript,python,go,csharp,java,yaml" >}} - {{% choosable language typescript %}} - -{{% /choosable %}} -{{% choosable language python %}} - -{{% /choosable %}} -{{% choosable language csharp %}} - -{{% /choosable %}} -{{% choosable language go %}} - -{{% /choosable %}} -{{% choosable language yaml %}} - -{{% /choosable %}} -{{% choosable language java %}} - -{{% /choosable %}} -{{< /chooser >}} - - `filters` - (Optional) If you'd like to add a filter to the source. + `filterType` - (Required) The type of filter to apply. (Exclude, Include, Mask, or Hash) + `name` - (Required) The Name for the filter. + `regexp` - (Required) Regular expression to match within the messages. When used with Incude/Exclude the expression must match the entire message. When used with Mask/Hash rules the expression must contain an unnamed capture group to hash/mask. + `mask` - (Optional) When applying a Mask rule, replaces the detected expression with this string. - Usage: - {{< chooser language "typescript,python,go,csharp,java,yaml" >}} - {{% choosable language typescript %}} - -{{% /choosable %}} -{{% choosable language python %}} - -{{% /choosable %}} -{{% choosable language csharp %}} - -{{% /choosable %}} -{{% choosable language go %}} - -{{% /choosable %}} -{{% choosable language yaml %}} - -{{% /choosable %}} -{{% choosable language java %}} - -{{% /choosable %}} -{{< /chooser >}} - - `hashAlgorithm` - (Optional) Define the hash algorithm used for Hash type filters. Available values are "MD5" and "SHA-256". The default value will be "MD5". - `cutoffTimestamp` - (Optional) Only collect data more recent than this timestamp, specified as milliseconds since epoch (13 digit). This maps to the `Collection should begin` field on the UI. Example: using `1663786159000` will set the cutoff timestamp to `Wednesday, September 21, 2022 6:49:19 PM GMT` - `cutoffRelativeTime` - (Optional) Can be specified instead of cutoffTimestamp to provide a relative offset with respect to the current time.This maps to the `Collection should begin` field on the UI. Example: use -1h, -1d, or -1w to collect data that's less than one hour, one day, or one week old, respectively. - `fields` - (Optional) Map containing key/value pairs. - - Usage: - {{< chooser language "typescript,python,go,csharp,java,yaml" >}} - {{% choosable language typescript %}} - -{{% /choosable %}} -{{% choosable language python %}} - -{{% /choosable %}} -{{% choosable language csharp %}} - -{{% /choosable %}} -{{% choosable language go %}} - -{{% /choosable %}} -{{% choosable language yaml %}} - -{{% /choosable %}} -{{% choosable language java %}} - -{{% /choosable %}} -{{< /chooser >}} ## Configuring SNS Subscription This is supported in the following resources. - `sumologic.CloudfrontSource` diff --git a/provider/installation-replaces/example-desired.md b/provider/installation-replaces/example-desired.md index 299e88c9..df5bd97e 100644 --- a/provider/installation-replaces/example-desired.md +++ b/provider/installation-replaces/example-desired.md @@ -31,12 +31,20 @@ resource "sumologic_http_source" "http_source" { ``` ### Configure the Sumo Logic Provider in Admin Mode ```hcl +variable "sumologic_access_id" { + type = string + description = "Sumo Logic Access ID" +} +variable "sumologic_access_key" { + type = string + description = "Sumo Logic Access Key" + sensitive = true +} provider "sumologic" { access_id = "${var.sumologic_access_id}" access_key = "${var.sumologic_access_key}" environment = "us2" admin_mode = true - alias = "admin" } # Look up the Admin Recommended Folder @@ -44,7 +52,6 @@ data "sumologic_admin_recommended_folder" "folder" {} # Create a folder underneath the Admin Recommended Folder (which requires Admin Mode) resource "sumologic_folder" "test" { - provider = sumologic.admin name = "test" description = "A test folder" parent_id = data.sumologic_admin_recommended_folder.folder.id diff --git a/provider/installation-replaces/usage1-input.md b/provider/installation-replaces/usage1-input.md new file mode 100644 index 00000000..26538375 --- /dev/null +++ b/provider/installation-replaces/usage1-input.md @@ -0,0 +1,7 @@ +Usage: + ```hcl + default_date_formats { + format = "MM-dd-yyyy HH:mm:ss" + locator = "timestamp:(.*)\\s" + } + ``` \ No newline at end of file diff --git a/provider/installation-replaces/usage2-input.md b/provider/installation-replaces/usage2-input.md new file mode 100644 index 00000000..0c79a7d2 --- /dev/null +++ b/provider/installation-replaces/usage2-input.md @@ -0,0 +1,14 @@ +Usage: + ```hcl + filters { + filter_type = "Include" + name = "Sample Include" + regexp = ".*\\d{16}.*" + } + filters { + filter_type = "Mask" + name = "Sample Mask" + regexp = "(\\d{16})" + mask = "MaskedID" + } + ``` \ No newline at end of file diff --git a/provider/installation-replaces/usage3-input.md b/provider/installation-replaces/usage3-input.md new file mode 100644 index 00000000..94da9ac7 --- /dev/null +++ b/provider/installation-replaces/usage3-input.md @@ -0,0 +1,7 @@ +Usage: + ```hcl + fields = { + environment = "production" + service = "apache" + } + ``` \ No newline at end of file diff --git a/provider/resources.go b/provider/resources.go index 519f08ce..0d387bed 100644 --- a/provider/resources.go +++ b/provider/resources.go @@ -159,6 +159,7 @@ func editRules(defaults []tfbridge.DocsEdit) []tfbridge.DocsEdit { defaults, replaceRefresh, fixInstallationExample, + fixInstallationUsages, ) } @@ -195,3 +196,25 @@ var fixInstallationExample = tfbridge.DocsEdit{ return b, nil }, } +var fixInstallationUsages = tfbridge.DocsEdit{ + Path: "index.html.markdown", + Edit: func(_ string, content []byte) ([]byte, error) { + files := []string{ + "usage1", + "usage2", + "usage3", + } + for _, file := range files { + input, err := os.ReadFile("provider/installation-replaces/" + file + "-input.md") + if err != nil { + return nil, err + } + content = bytes.ReplaceAll( + content, + input, + nil) + + } + return content, nil + }, +}