From 44cdd08f1d1beb33b44bfa4221ef060adda2dda8 Mon Sep 17 00:00:00 2001 From: Andrzej Ressel Date: Sun, 1 Dec 2024 22:51:13 +0100 Subject: [PATCH] Show warning next to rust docs --- .../src/function/get_plugin.rs | 20 ++- .../src/resource/container.rs | 42 ++--- .../src/resource/network.rs | 21 +-- .../src/resource/secret.rs | 7 +- .../src/resource/service.rs | 70 ++++---- .../src/resource/service_config.rs | 25 ++- .../src/dockerfixes/container/1_fixed.md | 159 +++++++++++++++++ .../src/dockerfixes/container/1_original.md | 165 ++++++++++++++++++ .../src/dockerfixes/getPlugin/1_fixed.md | 20 +++ .../src/dockerfixes/getPlugin/1_original.md | 14 ++ .../src/dockerfixes/network/1_fixed.md | 112 ++++++++++++ .../src/dockerfixes/network/1_original.md | 112 ++++++++++++ .../src/dockerfixes/secret/1_fixed.md | 7 + .../src/dockerfixes/secret/1_original.md | 8 + .../src/dockerfixes/service/1_fixed.md | 44 +++++ .../src/dockerfixes/service/1_original.md | 59 +++++++ .../src/dockerfixes/serviceConfig/1_fixed.md | 35 ++++ .../dockerfixes/serviceConfig/1_original.md | 36 ++++ .../output/rust/source_code_function_code.rs | 8 +- .../output/rust/source_code_resource_code.rs | 8 +- .../src/output/rust/source_code_types_code.rs | 1 + pulumi_wasm_generator_lib/src/utils.rs | 84 ++++++++- 22 files changed, 965 insertions(+), 92 deletions(-) create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/container/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/container/1_original.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_original.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/network/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/network/1_original.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/secret/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/secret/1_original.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/service/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/service/1_original.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_fixed.md create mode 100644 pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_original.md diff --git a/providers/pulumi_wasm_provider_docker_rust/src/function/get_plugin.rs b/providers/pulumi_wasm_provider_docker_rust/src/function/get_plugin.rs index 9d72a91a0..5b61ddf2e 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/function/get_plugin.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/function/get_plugin.rs @@ -3,15 +3,21 @@ //! ## Example Usage //! //! ### With alias -//! data "docker.Plugin" "by_alias" { -//! alias = "sample-volume-plugin:latest" -//! } +//! ```yaml +//! variables: +//! byAlias: +//! fn::docker:getPlugin: +//! alias: "sample-volume-plugin:latest" +//! ``` //! //! ### With ID -//! data "docker.Plugin" "by_id" { -//! id = "e9a9db917b3bfd6706b5d3a66d4bceb9f" -//! } -//! ```sh +//! ```yaml +//! variables: +//! byId: +//! fn::docker:getPlugin: +//! id: "e9a9db917b3bfd6706b5d3a66d4bceb9f" +//! ``` +//! #[derive(bon::Builder)] #[builder(finish_fn = build_struct)] diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/container.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/container.rs index 993e7299a..ad03df8bb 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/container.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/container.rs @@ -27,38 +27,40 @@ //! //! Assuming you created a `container` as follows //! -//! #!/bin/bash -//! +//! ```sh //! docker run --name foo -p8080:80 -d nginx +//! ``` //! //! prints the container ID //! +//! ```text //! 9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd +//! ``` //! //! you provide the definition for the resource as follows //! -//! terraform -//! -//! resource "docker_container" "foo" { -//! -//! name = "foo" -//! -//! image = "nginx" -//! -//! ports { -//! -//! internal = "80" -//! -//! external = "8080" -//! -//! } -//! +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let foo = container::create( +//! "foo", +//! ContainerArgs::builder() +//! .image("nginx") +//! .name("foo") +//! .ports( +//! vec![ +//! ContainerPort::builder().external(8080).internal(80).build_struct(), +//! ], +//! ) +//! .build_struct(), +//! ); //! } +//! ``` //! //! then the import command is as follows //! -//! #!/bin/bash -//! //! ```sh //! $ pulumi import docker:index/container:Container foo 9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd //! ``` diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/network.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/network.rs index 295411649..5418ffca4 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/network.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/network.rs @@ -23,28 +23,29 @@ //! //! Assuming you created a `network` as follows //! -//! #!/bin/bash -//! +//! ```sh //! docker network create foo +//! ```` //! //! prints the long ID //! +//! ```text //! 87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 +//! ``` //! //! you provide the definition for the resource as follows //! -//! terraform -//! -//! resource "docker_network" "foo" { -//! -//! name = "foo" -//! +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let foo = network::create("foo", NetworkArgs::builder().name("foo").build_struct()); //! } +//! ``` //! //! then the import command is as follows //! -//! #!/bin/bash -//! //! ```sh //! $ pulumi import docker:index/network:Network foo 87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 //! ``` diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/secret.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/secret.rs index ed574e91e..6da96c6bc 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/secret.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/secret.rs @@ -2,10 +2,9 @@ //! //! ## Import //! -//! #!/bin/bash -//! -//! Docker secret cannot be imported as the secret data, once set, is never exposed again. -//! +//! ```sh +//! # Docker secret cannot be imported as the secret data, once set, is never exposed again. +//! ``` #[derive(bon::Builder)] #[builder(finish_fn = build_struct)] diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/service.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/service.rs index b20936ea4..aa93197c5 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/service.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/service.rs @@ -1,6 +1,6 @@ //! //! This resource manages the lifecycle of a Docker service. By default, the creation, update and delete of services are detached. -//! With the Converge Config Name of the service +//! With the Converge Config Name of the service //! - `task_spec` (Block List, Min: 1, Max: 1) User modifiable task configuration (see below for nested schema) //! //! ## Import @@ -9,50 +9,52 @@ //! //! Assuming you created a `service` as follows //! -//! #!/bin/bash -//! +//! ```sh //! docker service create --name foo -p 8080:80 nginx +//! ``` //! -//! prints th ID +//! prints this ID //! +//! ```text //! 4pcphbxkfn2rffhbhe6czytgi +//! ``` //! //! you provide the definition for the resource as follows //! -//! terraform -//! -//! resource "docker_service" "foo" { -//! -//! name = "foo" -//! -//! task_spec { -//! -//! container_spec { -//! -//! image = "nginx" -//! -//! } -//! -//! } -//! -//! endpoint_spec { -//! -//! ports { -//! -//! target_port = "80" -//! -//! published_port = "8080" -//! -//! } -//! -//! } -//! +//! ```ignore +//! use pulumi_wasm_rust::Output; +//! use pulumi_wasm_rust::{add_export, pulumi_main}; +//! #[pulumi_main] +//! fn test_main() -> Result<(), Error> { +//! let foo = service::create( +//! "foo", +//! ServiceArgs::builder() +//! .endpoint_spec( +//! ServiceEndpointSpec::builder() +//! .ports( +//! vec![ +//! ServiceEndpointSpecPort::builder().publishedPort(8080) +//! .targetPort(80).build_struct(), +//! ], +//! ) +//! .build_struct(), +//! ) +//! .task_spec( +//! ServiceTaskSpec::builder() +//! .containerSpec( +//! ServiceTaskSpecContainerSpec::builder() +//! .image("nginx") +//! .build_struct(), +//! ) +//! .build_struct(), +//! ) +//! .build_struct(), +//! ); //! } +//! ``` //! //! then the import command is as follows //! -//! #!/bin/bash -//! //! ```sh //! $ pulumi import docker:index/service:Service foo 4pcphbxkfn2rffhbhe6czytgi //! ``` diff --git a/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs b/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs index 8b42ca62d..956e0ece2 100644 --- a/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs +++ b/providers/pulumi_wasm_provider_docker_rust/src/resource/service_config.rs @@ -6,30 +6,29 @@ //! //! Assuming you created a `config` as follows //! -//! #!/bin/bash -//! +//! ```sh //! printf '{"a":"b"}' | docker config create foo - +//! ``` //! //! prints the id //! +//! ```text //! 08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d +//! ``` //! //! you provide the definition for the resource as follows //! -//! terraform -//! -//! resource "docker_config" "foo" { -//! -//! name = "foo" -//! -//! data = base64encode("{\"a\": \"b\"}") -//! -//! } +//! ```yaml +//! resources: +//! foo: +//! type: docker:ServiceConfig +//! name: foo +//! properties: +//! data: 'base64encode("{\"a\": \"b\"}")' +//! ``` //! //! then the import command is as follows //! -//! #!/bin/bash -//! //! ```sh //! $ pulumi import docker:index/serviceConfig:ServiceConfig foo 08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d //! ``` diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/container/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/container/1_fixed.md new file mode 100644 index 000000000..024ac1328 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/container/1_fixed.md @@ -0,0 +1,159 @@ + +Manages the lifecycle of a Docker container. + +## Example Usage + + +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as docker from "@pulumi/docker"; + +// Find the latest Ubuntu precise image. +const ubuntuRemoteImage = new docker.RemoteImage("ubuntuRemoteImage", {name: "ubuntu:precise"}); +// Start a container +const ubuntuContainer = new docker.Container("ubuntuContainer", {image: ubuntuRemoteImage.imageId}); +``` +```python +import pulumi +import pulumi_docker as docker + +# Find the latest Ubuntu precise image. +ubuntu_remote_image = docker.RemoteImage("ubuntuRemoteImage", name="ubuntu:precise") +# Start a container +ubuntu_container = docker.Container("ubuntuContainer", image=ubuntu_remote_image.image_id) +``` +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using Docker = Pulumi.Docker; + +return await Deployment.RunAsync(() => +{ + // Find the latest Ubuntu precise image. + var ubuntuRemoteImage = new Docker.RemoteImage("ubuntuRemoteImage", new() + { + Name = "ubuntu:precise", + }); + + // Start a container + var ubuntuContainer = new Docker.Container("ubuntuContainer", new() + { + Image = ubuntuRemoteImage.ImageId, + }); + +}); +``` +```go +package main + +import ( + "github.com/pulumi/pulumi-docker/sdk/v4/go/docker" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + // Find the latest Ubuntu precise image. + ubuntuRemoteImage, err := docker.NewRemoteImage(ctx, "ubuntuRemoteImage", &docker.RemoteImageArgs{ + Name: pulumi.String("ubuntu:precise"), + }) + if err != nil { + return err + } + // Start a container + _, err = docker.NewContainer(ctx, "ubuntuContainer", &docker.ContainerArgs{ + Image: ubuntuRemoteImage.ImageId, + }) + if err != nil { + return err + } + return nil + }) +} +``` +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.docker.RemoteImage; +import com.pulumi.docker.RemoteImageArgs; +import com.pulumi.docker.Container; +import com.pulumi.docker.ContainerArgs; +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) { + var ubuntuRemoteImage = new RemoteImage("ubuntuRemoteImage", RemoteImageArgs.builder() + .name("ubuntu:precise") + .build()); + + var ubuntuContainer = new Container("ubuntuContainer", ContainerArgs.builder() + .image(ubuntuRemoteImage.imageId()) + .build()); + + } +} +``` +```yaml +resources: + # Start a container + ubuntuContainer: + type: docker:Container + properties: + image: ${ubuntuRemoteImage.imageId} + # Find the latest Ubuntu precise image. + ubuntuRemoteImage: + type: docker:RemoteImage + properties: + name: ubuntu:precise +``` + + +## Import + +### Example + +Assuming you created a `container` as follows + +```sh +docker run --name foo -p8080:80 -d nginx +``` + +prints the container ID + +```text +9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd +``` + +you provide the definition for the resource as follows + +```yaml +resources: + foo: + type: docker:Container + properties: + name: "foo" + image: "nginx" + ports: + - internal: 80 + external: 8080 +``` + +then the import command is as follows + +```sh +$ pulumi import docker:index/container:Container foo 9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/container/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/container/1_original.md new file mode 100644 index 000000000..fc578b186 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/container/1_original.md @@ -0,0 +1,165 @@ + +Manages the lifecycle of a Docker container. + +## Example Usage + + +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as docker from "@pulumi/docker"; + +// Find the latest Ubuntu precise image. +const ubuntuRemoteImage = new docker.RemoteImage("ubuntuRemoteImage", {name: "ubuntu:precise"}); +// Start a container +const ubuntuContainer = new docker.Container("ubuntuContainer", {image: ubuntuRemoteImage.imageId}); +``` +```python +import pulumi +import pulumi_docker as docker + +# Find the latest Ubuntu precise image. +ubuntu_remote_image = docker.RemoteImage("ubuntuRemoteImage", name="ubuntu:precise") +# Start a container +ubuntu_container = docker.Container("ubuntuContainer", image=ubuntu_remote_image.image_id) +``` +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using Docker = Pulumi.Docker; + +return await Deployment.RunAsync(() => +{ + // Find the latest Ubuntu precise image. + var ubuntuRemoteImage = new Docker.RemoteImage("ubuntuRemoteImage", new() + { + Name = "ubuntu:precise", + }); + + // Start a container + var ubuntuContainer = new Docker.Container("ubuntuContainer", new() + { + Image = ubuntuRemoteImage.ImageId, + }); + +}); +``` +```go +package main + +import ( + "github.com/pulumi/pulumi-docker/sdk/v4/go/docker" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + // Find the latest Ubuntu precise image. + ubuntuRemoteImage, err := docker.NewRemoteImage(ctx, "ubuntuRemoteImage", &docker.RemoteImageArgs{ + Name: pulumi.String("ubuntu:precise"), + }) + if err != nil { + return err + } + // Start a container + _, err = docker.NewContainer(ctx, "ubuntuContainer", &docker.ContainerArgs{ + Image: ubuntuRemoteImage.ImageId, + }) + if err != nil { + return err + } + return nil + }) +} +``` +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.docker.RemoteImage; +import com.pulumi.docker.RemoteImageArgs; +import com.pulumi.docker.Container; +import com.pulumi.docker.ContainerArgs; +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) { + var ubuntuRemoteImage = new RemoteImage("ubuntuRemoteImage", RemoteImageArgs.builder() + .name("ubuntu:precise") + .build()); + + var ubuntuContainer = new Container("ubuntuContainer", ContainerArgs.builder() + .image(ubuntuRemoteImage.imageId()) + .build()); + + } +} +``` +```yaml +resources: + # Start a container + ubuntuContainer: + type: docker:Container + properties: + image: ${ubuntuRemoteImage.imageId} + # Find the latest Ubuntu precise image. + ubuntuRemoteImage: + type: docker:RemoteImage + properties: + name: ubuntu:precise +``` + + +## Import + +### Example + +Assuming you created a `container` as follows + +#!/bin/bash + +docker run --name foo -p8080:80 -d nginx + +prints the container ID + +9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd + +you provide the definition for the resource as follows + +terraform + +resource "docker_container" "foo" { + + name = "foo" + + image = "nginx" + + ports { + + internal = "80" + + external = "8080" + + } + +} + +then the import command is as follows + +#!/bin/bash + +```sh +$ pulumi import docker:index/container:Container foo 9a550c0f0163d39d77222d3efd58701b625d47676c25c686c95b5b92d1cba6fd +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_fixed.md new file mode 100644 index 000000000..6cde69cdf --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_fixed.md @@ -0,0 +1,20 @@ +Reads the local Docker plugin. The plugin must be installed locally. + +## Example Usage + +### With alias +```yaml +variables: + byAlias: + fn::docker:getPlugin: + alias: "sample-volume-plugin:latest" +``` + +### With ID +```yaml +variables: + byId: + fn::docker:getPlugin: + id: "e9a9db917b3bfd6706b5d3a66d4bceb9f" +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_original.md new file mode 100644 index 000000000..f4653d7d0 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/getPlugin/1_original.md @@ -0,0 +1,14 @@ +Reads the local Docker plugin. The plugin must be installed locally. + +## Example Usage + +### With alias +data "docker.Plugin" "by_alias" { + alias = "sample-volume-plugin:latest" +} + +### With ID +data "docker.Plugin" "by_id" { + id = "e9a9db917b3bfd6706b5d3a66d4bceb9f" +} +``` diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/network/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/network/1_fixed.md new file mode 100644 index 000000000..599393cc5 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/network/1_fixed.md @@ -0,0 +1,112 @@ + +`docker.Network` provides a docker network resource. + +## Example Usage + + +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as docker from "@pulumi/docker"; + +const privateNetwork = new docker.Network("privateNetwork", {}); +``` +```python +import pulumi +import pulumi_docker as docker + +private_network = docker.Network("privateNetwork") +``` +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using Docker = Pulumi.Docker; + +return await Deployment.RunAsync(() => +{ + var privateNetwork = new Docker.Network("privateNetwork"); + +}); +``` +```go +package main + +import ( + "github.com/pulumi/pulumi-docker/sdk/v4/go/docker" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + _, err := docker.NewNetwork(ctx, "privateNetwork", nil) + if err != nil { + return err + } + return nil + }) +} +``` +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.docker.Network; +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) { + var privateNetwork = new Network("privateNetwork"); + + } +} +``` +```yaml +resources: + privateNetwork: + type: docker:Network +``` + + +## Import + +### Example + +Assuming you created a `network` as follows + +```shell +docker network create foo +```` + +prints the long ID + +```text +87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 +``` + +you provide the definition for the resource as follows + +```yaml +resources: + foo: + type: docker:Network + properties: + name: "foo" +``` + +then the import command is as follows + +```sh +$ pulumi import docker:index/network:Network foo 87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/network/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/network/1_original.md new file mode 100644 index 000000000..c270c88a9 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/network/1_original.md @@ -0,0 +1,112 @@ + +`docker.Network` provides a docker network resource. + +## Example Usage + + +```typescript +import * as pulumi from "@pulumi/pulumi"; +import * as docker from "@pulumi/docker"; + +const privateNetwork = new docker.Network("privateNetwork", {}); +``` +```python +import pulumi +import pulumi_docker as docker + +private_network = docker.Network("privateNetwork") +``` +```csharp +using System.Collections.Generic; +using System.Linq; +using Pulumi; +using Docker = Pulumi.Docker; + +return await Deployment.RunAsync(() => +{ + var privateNetwork = new Docker.Network("privateNetwork"); + +}); +``` +```go +package main + +import ( + "github.com/pulumi/pulumi-docker/sdk/v4/go/docker" + "github.com/pulumi/pulumi/sdk/v3/go/pulumi" +) + +func main() { + pulumi.Run(func(ctx *pulumi.Context) error { + _, err := docker.NewNetwork(ctx, "privateNetwork", nil) + if err != nil { + return err + } + return nil + }) +} +``` +```java +package generated_program; + +import com.pulumi.Context; +import com.pulumi.Pulumi; +import com.pulumi.core.Output; +import com.pulumi.docker.Network; +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) { + var privateNetwork = new Network("privateNetwork"); + + } +} +``` +```yaml +resources: + privateNetwork: + type: docker:Network +``` + + +## Import + +### Example + +Assuming you created a `network` as follows + +#!/bin/bash + +docker network create foo + +prints the long ID + +87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 + +you provide the definition for the resource as follows + +terraform + +resource "docker_network" "foo" { + + name = "foo" + +} + +then the import command is as follows + +#!/bin/bash + +```sh +$ pulumi import docker:index/network:Network foo 87b57a9b91ecab2db2a6dbf38df74c67d7c7108cbe479d6576574ec2cd8c2d73 +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_fixed.md new file mode 100644 index 000000000..9a34549dc --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_fixed.md @@ -0,0 +1,7 @@ + + +## Import + +``` +# Docker secret cannot be imported as the secret data, once set, is never exposed again. +``` diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_original.md new file mode 100644 index 000000000..98c304933 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/secret/1_original.md @@ -0,0 +1,8 @@ + + +## Import + +#!/bin/bash + +Docker secret cannot be imported as the secret data, once set, is never exposed again. + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/service/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/service/1_fixed.md new file mode 100644 index 000000000..fa739e98d --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/service/1_fixed.md @@ -0,0 +1,44 @@ + +This resource manages the lifecycle of a Docker service. By default, the creation, update and delete of services are detached. +With the Converge Config Name of the service +- `task_spec` (Block List, Min: 1, Max: 1) User modifiable task configuration (see below for nested schema) + +## Import + +### Example + +Assuming you created a `service` as follows + +```shell +docker service create --name foo -p 8080:80 nginx +``` + +prints this ID + +```text +4pcphbxkfn2rffhbhe6czytgi +``` + +you provide the definition for the resource as follows + +```yaml +resources: + foo: + type: docker:Service + name: foo + properties: + taskSpec: + containerSpec: + image: "nginx" + endpointSpec: + ports: + - targetPort: 80 + publishedPort: 8080 +``` + +then the import command is as follows + +```sh +$ pulumi import docker:index/service:Service foo 4pcphbxkfn2rffhbhe6czytgi +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/service/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/service/1_original.md new file mode 100644 index 000000000..dce522d5e --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/service/1_original.md @@ -0,0 +1,59 @@ + +This resource manages the lifecycle of a Docker service. By default, the creation, update and delete of services are detached. + With the Converge Config Name of the service +- `task_spec` (Block List, Min: 1, Max: 1) User modifiable task configuration (see below for nested schema) + +## Import + +### Example + +Assuming you created a `service` as follows + +#!/bin/bash + +docker service create --name foo -p 8080:80 nginx + +prints th ID + +4pcphbxkfn2rffhbhe6czytgi + +you provide the definition for the resource as follows + +terraform + +resource "docker_service" "foo" { + + name = "foo" + + task_spec { + + container_spec { + + image = "nginx" + + } + + } + + endpoint_spec { + + ports { + + target_port = "80" + + published_port = "8080" + + } + + } + +} + +then the import command is as follows + +#!/bin/bash + +```sh +$ pulumi import docker:index/service:Service foo 4pcphbxkfn2rffhbhe6czytgi +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_fixed.md b/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_fixed.md new file mode 100644 index 000000000..f5b25fe05 --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_fixed.md @@ -0,0 +1,35 @@ + + +## Import + +### Example + +Assuming you created a `config` as follows + +```shell +printf '{"a":"b"}' | docker config create foo - +``` + +prints the id + +```text +08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d +``` + +you provide the definition for the resource as follows + +```yaml +resources: + foo: + type: docker:ServiceConfig + name: foo + properties: + data: 'base64encode("{\"a\": \"b\"}")' +``` + +then the import command is as follows + +```sh +$ pulumi import docker:index/serviceConfig:ServiceConfig foo 08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d +``` + diff --git a/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_original.md b/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_original.md new file mode 100644 index 000000000..cc53e750b --- /dev/null +++ b/pulumi_wasm_generator_lib/src/dockerfixes/serviceConfig/1_original.md @@ -0,0 +1,36 @@ + + +## Import + +### Example + +Assuming you created a `config` as follows + +#!/bin/bash + +printf '{"a":"b"}' | docker config create foo - + +prints the id + +08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d + +you provide the definition for the resource as follows + +terraform + +resource "docker_config" "foo" { + + name = "foo" + + data = base64encode("{\"a\": \"b\"}") + +} + +then the import command is as follows + +#!/bin/bash + +```sh +$ pulumi import docker:index/serviceConfig:ServiceConfig foo 08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d +``` + diff --git a/pulumi_wasm_generator_lib/src/output/rust/source_code_function_code.rs b/pulumi_wasm_generator_lib/src/output/rust/source_code_function_code.rs index 3df1ec20f..a5c09f1e7 100644 --- a/pulumi_wasm_generator_lib/src/output/rust/source_code_function_code.rs +++ b/pulumi_wasm_generator_lib/src/output/rust/source_code_function_code.rs @@ -51,7 +51,11 @@ fn convert_model(package: &crate::model::Package) -> Package { name: element_id.get_rust_namespace_name(), struct_name: element_id.name.clone().to_case(Case::Pascal), function_name: element_id.get_rust_function_name(), - description_lines: crate::utils::to_lines(resource.description.clone(), package), + description_lines: crate::utils::to_lines( + resource.description.clone(), + package, + Some(element_id.clone()), + ), input_properties: resource .input_properties .iter() @@ -63,6 +67,7 @@ fn convert_model(package: &crate::model::Package) -> Package { description_lines: crate::utils::to_lines( input_property.description.clone(), package, + None, ), }) .collect(), @@ -76,6 +81,7 @@ fn convert_model(package: &crate::model::Package) -> Package { description_lines: crate::utils::to_lines( output_property.description.clone(), package, + None, ), }) .collect(), diff --git a/pulumi_wasm_generator_lib/src/output/rust/source_code_resource_code.rs b/pulumi_wasm_generator_lib/src/output/rust/source_code_resource_code.rs index 0550a405e..257259cf6 100644 --- a/pulumi_wasm_generator_lib/src/output/rust/source_code_resource_code.rs +++ b/pulumi_wasm_generator_lib/src/output/rust/source_code_resource_code.rs @@ -50,7 +50,11 @@ fn convert_model(package: &crate::model::Package) -> Package { name: element_id.get_rust_namespace_name(), struct_name: element_id.name.clone(), function_name: element_id.get_rust_function_name(), - description_lines: crate::utils::to_lines(resource.description.clone(), package), + description_lines: crate::utils::to_lines( + resource.description.clone(), + package, + Some(element_id.clone()), + ), input_properties: resource .input_properties .iter() @@ -62,6 +66,7 @@ fn convert_model(package: &crate::model::Package) -> Package { description_lines: crate::utils::to_lines( input_property.description.clone(), package, + None, ), }) .collect(), @@ -75,6 +80,7 @@ fn convert_model(package: &crate::model::Package) -> Package { description_lines: crate::utils::to_lines( output_property.description.clone(), package, + None, ), }) .collect(), diff --git a/pulumi_wasm_generator_lib/src/output/rust/source_code_types_code.rs b/pulumi_wasm_generator_lib/src/output/rust/source_code_types_code.rs index ca8b43768..f3767d514 100644 --- a/pulumi_wasm_generator_lib/src/output/rust/source_code_types_code.rs +++ b/pulumi_wasm_generator_lib/src/output/rust/source_code_types_code.rs @@ -64,6 +64,7 @@ fn convert_model(package: &crate::model::Package) -> Package { description_lines: crate::utils::to_lines( global_type_property.description.clone(), package, + None, ), }) .collect(), diff --git a/pulumi_wasm_generator_lib/src/utils.rs b/pulumi_wasm_generator_lib/src/utils.rs index 351a1bcc4..62c5ec444 100644 --- a/pulumi_wasm_generator_lib/src/utils.rs +++ b/pulumi_wasm_generator_lib/src/utils.rs @@ -1,5 +1,10 @@ use crate::code_generation::generate_code_from_string; +use crate::model::ElementId; use regex::Regex; +use std::cell::LazyCell; +use std::collections::HashMap; +use std::fs; +use std::sync::LazyLock; pub(crate) fn replace_multiple_dashes(s: &str) -> String { let re = Regex::new("-+").unwrap(); @@ -76,8 +81,15 @@ pub(crate) fn escape_wit_identifier(s: &str) -> &str { } } -pub(crate) fn to_lines(s: Option, package: &crate::model::Package) -> Vec { - let binding = s.clone().unwrap_or("".to_string()); +pub(crate) fn to_lines( + s: Option, + package: &crate::model::Package, + element_id: Option, +) -> Vec { + let binding = s + .clone() + .map(|s| fix_pulumi_docker_docs(s, element_id)) + .unwrap_or("".to_string()); let lines = binding.lines(); let mut in_yaml = false; @@ -148,6 +160,10 @@ pub(crate) fn to_lines(s: Option, package: &crate::model::Package) -> Ve in_shell = true; vec!["```sh".to_string()] } + "```text" => { + in_shell = true; + vec!["```text".to_string()] + } _ => vec![line.to_string()], }; @@ -156,3 +172,67 @@ pub(crate) fn to_lines(s: Option, package: &crate::model::Package) -> Ve new_lines } + +const DOCKER_SERVICE_REPLACEMENTS: LazyCell>> = + LazyCell::new(|| { + HashMap::from([ + ( + ElementId::new("docker:index/service:Service").unwrap(), + vec![( + include_str!("dockerfixes/service/1_original.md"), + include_str!("dockerfixes/service/1_fixed.md"), + )], + ), + ( + ElementId::new("docker:index/getPlugin:getPlugin").unwrap(), + vec![( + include_str!("dockerfixes/getPlugin/1_original.md"), + include_str!("dockerfixes/getPlugin/1_fixed.md"), + )], + ), + ( + ElementId::new("docker:index/network:Network").unwrap(), + vec![( + include_str!("dockerfixes/network/1_original.md"), + include_str!("dockerfixes/network/1_fixed.md"), + )], + ), + ( + ElementId::new("docker:index/secret:Secret").unwrap(), + vec![( + include_str!("dockerfixes/secret/1_original.md"), + include_str!("dockerfixes/secret/1_fixed.md"), + )], + ), + ( + ElementId::new("docker:index/serviceConfig:ServiceConfig").unwrap(), + vec![( + include_str!("dockerfixes/serviceConfig/1_original.md"), + include_str!("dockerfixes/serviceConfig/1_fixed.md"), + )], + ), + ( + ElementId::new("docker:index/container:Container").unwrap(), + vec![( + include_str!("dockerfixes/container/1_original.md"), + include_str!("dockerfixes/container/1_fixed.md"), + )], + ), + ]) + }); + +fn fix_pulumi_docker_docs(s: String, element_id: Option) -> String { + if let Some(id) = element_id { + if let Some(replacements) = DOCKER_SERVICE_REPLACEMENTS.get(&id) { + for (origin, fixed) in replacements { + if s.contains(origin) { + return fixed.to_string(); + } + } + fs::write("error.md", s).unwrap(); + panic!("ElementId {:?} does not have valid replacement. Original markdown was saved to error.md", id); + } + } + + s +}