ServiceConfig class

<!-- Bug: Type and Name are switched --> Manages the configs of a Docker service in a swarm.

{{% examples %}}

Example Usage

Basic

resource "docker_config" "foo_config" {
  name = "foo_config"
  data = base64encode("{\"a\": \"b\"}")
}

Advanced

Dynamically set config with a template

In this example you can use the ${var.foo_port} variable to dynamically set the ${port} variable in the foo.configs.json.tpl template and create the data of the fooConfig with the help of the base64encode interpolation function.

The file foo.config.json.tpl has the following content:

{
  "server": {
    "public_port": ${port}
  }
}

and the resource uses it as follows:

resource "docker_config" "foo_config" {
  name = "foo_config"
  data = base64encode(
    templatefile("${path.cwd}/foo.config.json.tpl",
      {
        port = 8080
      }
    )
  )
}

Update config with no downtime

To update a config, Terraform will destroy the existing resource and create a replacement. To effectively use a docker.ServiceConfig resource with a docker.Service resource, it's recommended to specify createBeforeDestroy in a lifecycle block. Provide a unique name attribute, for example with one of the interpolation functions uuid or timestamp as shown in the example below. The reason is this issue.

resource "docker_config" "service_config" {
  name = "${var.service_name}-config-${replace(timestamp(), ":", ".")}"
  data = base64encode(
    templatefile("${path.cwd}/foo.config.json.tpl",
      {
        port = 8080
      }
    )
  )

  lifecycle {
    ignore_changes        = ["name"]
    create_before_destroy = true
  }
}

resource "docker_service" "service" {
  # ... other attributes omitted for brevity
  configs {
    config_id   = docker_config.service_config.id
    config_name = docker_config.service_config.name
    file_name   = "/root/configs/configs.json"
  }
}

Import

!/bin/bash

$ pulumi import docker:index/serviceConfig:ServiceConfig foo id

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

resource "docker_config" "foo" {
  name = "foo"
  data = base64encode("{\"a\": \"b\"}")
}

then the import command is as follows

!/bin/bash

$ pulumi import docker:index/serviceConfig:ServiceConfig foo 08c26c477474478d971139f750984775a7f019dbe8a2e7f09d66a187c009e66d

{{% /examples %}}

Constructors

ServiceConfig(String name, {ServiceConfigArgs? args, CustomResourceOptions? options})
Creates a new ServiceConfig. name The Pulumi resource name. args Arguments used to configure this ServiceConfig. The set of arguments for ServiceConfig. options Resource options controlling this resource's behavior.
ServiceConfig.reference(String urn)
Creates a typed reference to an existing ServiceConfig resource.

Properties

childResources → Set<Resource>
finalinherited
completionSources ↔ Map<String, IOutputCompletionSource>
latefinalinherited
data ↔ Output<String?>
Base64-url-safe-encoded config data
latefinal
dataRaw ↔ Output<String?>
Raw (plain text) config data
latefinal
hashCode → int
The hash code for this object.
no setterinherited
id ↔ Output<String>
getter/setter pairinherited
isCustom → bool
Returns whether this resource is provider-managed.
no setterinherited
isProtected → bool
Returns whether this resource is protected from deletion.
no setterinherited
isRemote → bool
Whether this resource is registered as remote.
no setterinherited
isResourceReference → bool
Whether this instance represents a resource value returned over RPC.
finalinherited
labels ↔ Output<List<ServiceConfigLabel>?>
User-defined key/value metadata
latefinal
name ↔ Output<String>
User-defined name of the config
latefinal
resourceTransforms → List<ResourceTransform>
Inherited/explicit async transforms.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
transformations → List<ResourceTransformation>
Inherited/explicit legacy transformations.
no setterinherited
urn ↔ Output<String>
latefinalinherited

Methods

failId(Object error) → void
Completes this resource ID with an error when registration fails.
inherited
failOutputs(Object error) → void
Completes all output properties with error.
inherited
failUrn(Object error) → void
Completes this resource URN with an error when registration fails.
inherited
getProvider(String moduleMember) → ProviderResource?
Returns provider for moduleMember's package, if configured.
inherited
getResourceName() → String
Returns this resource's logical name.
inherited
getResourceType() → String
Returns this resource's Pulumi type token.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerOutput<T>(String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output<T>
Registers a dynamic output property for this resource.
inherited
resolveId(String? value, {required bool isKnown}) → void
Resolves the provider-assigned ID for this resource.
inherited
resolveOutputs(Struct outputs) → void
Resolves all output properties from a monitor response payload.
inherited
resolveUrn(String value) → void
Resolves this resource's URN once assigned by the engine.
inherited
serializeProperties(Map<String, dynamic> properties) → Future<Struct>
Serializes resource properties for RPC transmission.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

get(String name, Input<String> id, {ServiceConfigState? state, CustomResourceOptions? options}) → ServiceConfig
Gets an existing ServiceConfig resource's state with the given name and id.