All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pulumi.gcp.endpoints.kotlin.Service.kt Maven / Gradle / Ivy

@file:Suppress("NAME_SHADOWING", "DEPRECATION")

package com.pulumi.gcp.endpoints.kotlin

import com.pulumi.core.Output
import com.pulumi.gcp.endpoints.kotlin.outputs.ServiceApi
import com.pulumi.gcp.endpoints.kotlin.outputs.ServiceEndpoint
import com.pulumi.kotlin.KotlinCustomResource
import com.pulumi.kotlin.PulumiTagMarker
import com.pulumi.kotlin.ResourceMapper
import com.pulumi.kotlin.options.CustomResourceOptions
import com.pulumi.kotlin.options.CustomResourceOptionsBuilder
import com.pulumi.resources.Resource
import kotlin.Boolean
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import com.pulumi.gcp.endpoints.kotlin.outputs.ServiceApi.Companion.toKotlin as serviceApiToKotlin
import com.pulumi.gcp.endpoints.kotlin.outputs.ServiceEndpoint.Companion.toKotlin as serviceEndpointToKotlin

/**
 * Builder for [Service].
 */
@PulumiTagMarker
public class ServiceResourceBuilder internal constructor() {
    public var name: String? = null

    public var args: ServiceArgs = ServiceArgs()

    public var opts: CustomResourceOptions = CustomResourceOptions()

    /**
     * @param name The _unique_ name of the resulting resource.
     */
    public fun name(`value`: String) {
        this.name = value
    }

    /**
     * @param block The arguments to use to populate this resource's properties.
     */
    public suspend fun args(block: suspend ServiceArgsBuilder.() -> Unit) {
        val builder = ServiceArgsBuilder()
        block(builder)
        this.args = builder.build()
    }

    /**
     * @param block A bag of options that control this resource's behavior.
     */
    public suspend fun opts(block: suspend CustomResourceOptionsBuilder.() -> Unit) {
        this.opts = com.pulumi.kotlin.options.CustomResourceOptions.opts(block)
    }

    internal fun build(): Service {
        val builtJavaResource = com.pulumi.gcp.endpoints.Service(
            this.name,
            this.args.toJava(),
            this.opts.toJava(),
        )
        return Service(builtJavaResource)
    }
}

/**
 * This resource creates and rolls out a Cloud Endpoints service using OpenAPI or gRPC.  View the relevant docs for [OpenAPI](https://cloud.google.com/endpoints/docs/openapi/) and [gRPC](https://cloud.google.com/endpoints/docs/grpc/).
 * ## Example Usage
 * 
 * ```typescript
 * import * as pulumi from "@pulumi/pulumi";
 * import * as gcp from "@pulumi/gcp";
 * import * as std from "@pulumi/std";
 * const openapiService = new gcp.endpoints.Service("openapi_service", {
 *     serviceName: "api-name.endpoints.project-id.cloud.goog",
 *     project: "project-id",
 *     openapiConfig: std.file({
 *         input: "openapi_spec.yml",
 *     }).then(invoke => invoke.result),
 * });
 * const grpcService = new gcp.endpoints.Service("grpc_service", {
 *     serviceName: "api-name.endpoints.project-id.cloud.goog",
 *     project: "project-id",
 *     grpcConfig: std.file({
 *         input: "service_spec.yml",
 *     }).then(invoke => invoke.result),
 *     protocOutputBase64: std.filebase64({
 *         input: "compiled_descriptor_file.pb",
 *     }).then(invoke => invoke.result),
 * });
 * ```
 * ```python
 * import pulumi
 * import pulumi_gcp as gcp
 * import pulumi_std as std
 * openapi_service = gcp.endpoints.Service("openapi_service",
 *     service_name="api-name.endpoints.project-id.cloud.goog",
 *     project="project-id",
 *     openapi_config=std.file(input="openapi_spec.yml").result)
 * grpc_service = gcp.endpoints.Service("grpc_service",
 *     service_name="api-name.endpoints.project-id.cloud.goog",
 *     project="project-id",
 *     grpc_config=std.file(input="service_spec.yml").result,
 *     protoc_output_base64=std.filebase64(input="compiled_descriptor_file.pb").result)
 * ```
 * ```csharp
 * using System.Collections.Generic;
 * using System.Linq;
 * using Pulumi;
 * using Gcp = Pulumi.Gcp;
 * using Std = Pulumi.Std;
 * return await Deployment.RunAsync(() =>
 * {
 *     var openapiService = new Gcp.Endpoints.Service("openapi_service", new()
 *     {
 *         ServiceName = "api-name.endpoints.project-id.cloud.goog",
 *         Project = "project-id",
 *         OpenapiConfig = Std.File.Invoke(new()
 *         {
 *             Input = "openapi_spec.yml",
 *         }).Apply(invoke => invoke.Result),
 *     });
 *     var grpcService = new Gcp.Endpoints.Service("grpc_service", new()
 *     {
 *         ServiceName = "api-name.endpoints.project-id.cloud.goog",
 *         Project = "project-id",
 *         GrpcConfig = Std.File.Invoke(new()
 *         {
 *             Input = "service_spec.yml",
 *         }).Apply(invoke => invoke.Result),
 *         ProtocOutputBase64 = Std.Filebase64.Invoke(new()
 *         {
 *             Input = "compiled_descriptor_file.pb",
 *         }).Apply(invoke => invoke.Result),
 *     });
 * });
 * ```
 * ```go
 * package main
 * import (
 * 	"github.com/pulumi/pulumi-gcp/sdk/v7/go/gcp/endpoints"
 * 	"github.com/pulumi/pulumi-std/sdk/go/std"
 * 	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
 * )
 * func main() {
 * 	pulumi.Run(func(ctx *pulumi.Context) error {
 * 		invokeFile, err := std.File(ctx, &std.FileArgs{
 * 			Input: "openapi_spec.yml",
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = endpoints.NewService(ctx, "openapi_service", &endpoints.ServiceArgs{
 * 			ServiceName:   pulumi.String("api-name.endpoints.project-id.cloud.goog"),
 * 			Project:       pulumi.String("project-id"),
 * 			OpenapiConfig: pulumi.String(invokeFile.Result),
 * 		})
 * 		if err != nil {
 * 			return err
 * 		}
 * 		invokeFile1, err := std.File(ctx, &std.FileArgs{
 * 			Input: "service_spec.yml",
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		invokeFilebase642, err := std.Filebase64(ctx, &std.Filebase64Args{
 * 			Input: "compiled_descriptor_file.pb",
 * 		}, nil)
 * 		if err != nil {
 * 			return err
 * 		}
 * 		_, err = endpoints.NewService(ctx, "grpc_service", &endpoints.ServiceArgs{
 * 			ServiceName:        pulumi.String("api-name.endpoints.project-id.cloud.goog"),
 * 			Project:            pulumi.String("project-id"),
 * 			GrpcConfig:         pulumi.String(invokeFile1.Result),
 * 			ProtocOutputBase64: pulumi.String(invokeFilebase642.Result),
 * 		})
 * 		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.gcp.endpoints.Service;
 * import com.pulumi.gcp.endpoints.ServiceArgs;
 * 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 openapiService = new Service("openapiService", ServiceArgs.builder()
 *             .serviceName("api-name.endpoints.project-id.cloud.goog")
 *             .project("project-id")
 *             .openapiConfig(StdFunctions.file(FileArgs.builder()
 *                 .input("openapi_spec.yml")
 *                 .build()).result())
 *             .build());
 *         var grpcService = new Service("grpcService", ServiceArgs.builder()
 *             .serviceName("api-name.endpoints.project-id.cloud.goog")
 *             .project("project-id")
 *             .grpcConfig(StdFunctions.file(FileArgs.builder()
 *                 .input("service_spec.yml")
 *                 .build()).result())
 *             .protocOutputBase64(StdFunctions.filebase64(Filebase64Args.builder()
 *                 .input("compiled_descriptor_file.pb")
 *                 .build()).result())
 *             .build());
 *     }
 * }
 * ```
 * ```yaml
 * resources:
 *   openapiService:
 *     type: gcp:endpoints:Service
 *     name: openapi_service
 *     properties:
 *       serviceName: api-name.endpoints.project-id.cloud.goog
 *       project: project-id
 *       openapiConfig:
 *         fn::invoke:
 *           Function: std:file
 *           Arguments:
 *             input: openapi_spec.yml
 *           Return: result
 *   grpcService:
 *     type: gcp:endpoints:Service
 *     name: grpc_service
 *     properties:
 *       serviceName: api-name.endpoints.project-id.cloud.goog
 *       project: project-id
 *       grpcConfig:
 *         fn::invoke:
 *           Function: std:file
 *           Arguments:
 *             input: service_spec.yml
 *           Return: result
 *       protocOutputBase64:
 *         fn::invoke:
 *           Function: std:filebase64
 *           Arguments:
 *             input: compiled_descriptor_file.pb
 *           Return: result
 * ```
 * 
 * The example in `examples/endpoints_on_compute_engine` shows the API from the quickstart running on a Compute Engine VM and reachable through Cloud Endpoints, which may also be useful.
 * ## Import
 * This resource does not support import.
 */
public class Service internal constructor(
    override val javaResource: com.pulumi.gcp.endpoints.Service,
) : KotlinCustomResource(javaResource, ServiceMapper) {
    /**
     * A list of API objects; structure is documented below.
     */
    public val apis: Output>
        get() = javaResource.apis().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.let({ args0 ->
                    serviceApiToKotlin(args0)
                })
            })
        })

    /**
     * The autogenerated ID for the configuration that is rolled out as part of the creation of this resource.  Must be provided to compute engine instances as a tag.
     */
    public val configId: Output
        get() = javaResource.configId().applyValue({ args0 -> args0 })

    /**
     * The address at which the service can be found - usually the same as the service name.
     */
    public val dnsAddress: Output
        get() = javaResource.dnsAddress().applyValue({ args0 -> args0 })

    /**
     * A list of Endpoint objects; structure is documented below.
     */
    public val endpoints: Output>
        get() = javaResource.endpoints().applyValue({ args0 ->
            args0.map({ args0 ->
                args0.let({ args0 ->
                    serviceEndpointToKotlin(args0)
                })
            })
        })

    /**
     * The full text of the Service Config YAML file (Example located [here](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/main/endpoints/bookstore-grpc/api_config.yaml)).
     * If provided, must also provide `protoc_output_base64`.  `open_api` config must *not* be provided.
     */
    public val grpcConfig: Output?
        get() = javaResource.grpcConfig().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The full text of the OpenAPI YAML configuration as described [here](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md).
     * Either this, or *both* of `grpc_config` and `protoc_output_base64` must be specified.
     */
    public val openapiConfig: Output?
        get() = javaResource.openapiConfig().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The project ID that the service belongs to.  If not provided, provider project is used.
     */
    public val project: Output
        get() = javaResource.project().applyValue({ args0 -> args0 })

    /**
     * The full contents of the Service Descriptor File generated by protoc.  This should be a compiled .pb file, base64-encoded.
     */
    public val protocOutputBase64: Output?
        get() = javaResource.protocOutputBase64().applyValue({ args0 ->
            args0.map({ args0 ->
                args0
            }).orElse(null)
        })

    /**
     * The name of the service.  Usually of the form `$apiname.endpoints.$projectid.cloud.goog`.
     * - - -
     */
    public val serviceName: Output
        get() = javaResource.serviceName().applyValue({ args0 -> args0 })
}

public object ServiceMapper : ResourceMapper {
    override fun supportsMappingOfType(javaResource: Resource): Boolean =
        com.pulumi.gcp.endpoints.Service::class == javaResource::class

    override fun map(javaResource: Resource): Service = Service(
        javaResource as
            com.pulumi.gcp.endpoints.Service,
    )
}

/**
 * @see [Service].
 * @param name The _unique_ name of the resulting resource.
 * @param block Builder for [Service].
 */
public suspend fun service(name: String, block: suspend ServiceResourceBuilder.() -> Unit): Service {
    val builder = ServiceResourceBuilder()
    builder.name(name)
    block(builder)
    return builder.build()
}

/**
 * @see [Service].
 * @param name The _unique_ name of the resulting resource.
 */
public fun service(name: String): Service {
    val builder = ServiceResourceBuilder()
    builder.name(name)
    return builder.build()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy