diff --git a/.copywrite.hcl b/.copywrite.hcl new file mode 100644 index 00000000..07f43e75 --- /dev/null +++ b/.copywrite.hcl @@ -0,0 +1,20 @@ +schema_version = 1 + +project { + license = "MPL-2.0" + copyright_year = 2023 + + header_ignore = [ + # examples used within documentation (prose) + "examples/**", + + # GitHub issue template configuration + ".github/ISSUE_TEMPLATE/*.yml", + + # golangci-lint tooling configuration + ".golangci.yml", + + # GoReleaser tooling configuration + ".goreleaser.yml", + ] +} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 75490490..88f03496 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - go-version: [1.19.x, 1.20.x] + go-version: [1.20.x, 1.21.x] os: [ubuntu-latest] runs-on: ${{ matrix.os }} steps: @@ -24,8 +24,25 @@ jobs: run: make test - name: Run OSS acceptance tests run: | - curl -LO https://releases.hashicorp.com/consul/1.16.0/consul_1.16.0_linux_amd64.zip - sudo unzip consul_1.16.0_linux_amd64.zip consul -d /usr/local/bin + curl -LO https://releases.hashicorp.com/consul/1.16.2/consul_1.16.2_linux_amd64.zip + sudo unzip consul_1.16.2_linux_amd64.zip consul -d /usr/local/bin SKIP_REMOTE_DATACENTER_TESTS=1 make testacc TESTARGS="-count=1" - name: Run go vet run: make vet + + docs: + runs-on: ubuntu-latest + steps: + - name: Install Go + uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0 + with: + go-version: 1.20.x + - name: Checkout code + uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 + - name: Run OSS acceptance tests + run: | + curl -LO https://github.com/hashicorp/terraform-plugin-docs/releases/download/v0.16.0/tfplugindocs_0.16.0_linux_amd64.zip + sudo unzip tfplugindocs_0.16.0_linux_amd64.zip tfplugindocs -d /usr/local/bin + tfplugindocs generate --ignore-deprecated true + - name: Fail if repo has changes + uses: UnicornGlobal/has-changes-action@ea00e6f831a9e785271645729fa251907b314707 # v1.0.12 diff --git a/LICENSE b/LICENSE index b9ac071e..0efb0a53 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2017 HashiCorp, Inc. +Copyright (c) 2023 HashiCorp, Inc. Mozilla Public License Version 2.0 ================================== diff --git a/consul/data_source_consul_service_health_test.go b/consul/data_source_consul_service_health_test.go index 45a9eb16..a1303b8c 100644 --- a/consul/data_source_consul_service_health_test.go +++ b/consul/data_source_consul_service_health_test.go @@ -33,7 +33,7 @@ func TestAccDataConsulServiceHealth(t *testing.T) { testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.address", ""), testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.datacenter", "dc1"), testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.tagged_addresses.%", "4"), - testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.meta.%", "1"), + testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.meta.%", "2"), testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.meta.consul-network-segment", ""), testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.service.0.id", "consul"), diff --git a/consul/data_source_consul_service_test.go b/consul/data_source_consul_service_test.go index 78a40f40..69f869d2 100644 --- a/consul/data_source_consul_service_test.go +++ b/consul/data_source_consul_service_test.go @@ -28,7 +28,7 @@ func TestAccDataConsulService_basic(t *testing.T) { testAccCheckDataSourceValue("data.consul_service.read", "service.0.name", ""), testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_address", ""), testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_id", ""), - testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_meta.%", "1"), + testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_meta.%", "2"), testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_meta.consul-network-segment", ""), testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_name", ""), testAccCheckDataSourceValue("data.consul_service.read", "service.0.port", ""), diff --git a/consul/resource_consul_service.go b/consul/resource_consul_service.go index 269e2002..628137f3 100644 --- a/consul/resource_consul_service.go +++ b/consul/resource_consul_service.go @@ -17,13 +17,15 @@ import ( var headerResource = &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Description: "The name of the header.", }, "value": { - Type: schema.TypeList, - Required: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "The header's list of values.", }, }, } @@ -45,37 +47,53 @@ func resourceConsulService() *schema.Resource { Read: resourceConsulServiceRead, Delete: resourceConsulServiceDelete, + Description: ` +A high-level resource for creating a Service in Consul in the Consul catalog. This +is appropriate for registering [external services](https://www.consul.io/docs/guides/external.html) and +can be used to create services addressable by Consul that cannot be registered +with a [local agent](https://www.consul.io/docs/agent/basics.html). + +-> **NOTE:** If a Consul agent is running on the node where this service is +registered, it is not recommended to use this resource as the service will be +removed during the next [anti-entropy synchronization](https://www.consul.io/docs/architecture/anti-entropy). +`, + Schema: map[string]*schema.Schema{ "address": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "The address of the service. Defaults to the address of the node.", }, "service_id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + Description: "If the service ID is not provided, it will be defaulted to the value of the `name` attribute.", }, "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The name of the service.", }, "node": { - Type: schema.TypeString, - Required: true, - ForceNew: true, + Type: schema.TypeString, + Required: true, + ForceNew: true, + Description: "The name of the node the to register the service on.", }, "datacenter": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + Description: "The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup.", }, "external": { @@ -85,14 +103,16 @@ func resourceConsulService() *schema.Resource { }, "port": { - Type: schema.TypeInt, - Optional: true, + Type: schema.TypeInt, + Optional: true, + Description: "The port of the service.", }, "tags": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "A list of values that are opaque to Consul, but can be used to distinguish between services or nodes.", }, "meta": { @@ -101,6 +121,7 @@ func resourceConsulService() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, + Description: "A map of arbitrary KV metadata linked to the service instance.", }, "check": { @@ -137,76 +158,89 @@ func resourceConsulService() *schema.Resource { Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "check_id": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Description: "An ID, *unique per agent*.", }, "name": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Description: "The name of the health-check.", }, "notes": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Description: "An opaque field meant to hold human readable text.", }, "status": { - Type: schema.TypeString, - Optional: true, - Computed: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "The initial health-check status.", }, "tcp": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Description: "The TCP address and port to connect to for a TCP check.", }, "http": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeString, + Optional: true, + Description: "The HTTP endpoint to call for an HTTP check.", }, "header": { - Type: schema.TypeSet, - Optional: true, - Elem: headerResource, + Type: schema.TypeSet, + Optional: true, + Elem: headerResource, + Description: "The headers to send for an HTTP check. The attributes of each header is given below.", }, "tls_skip_verify": { - Type: schema.TypeBool, - Optional: true, - Default: false, + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "Whether to deactivate certificate verification for HTTP health-checks. Defaults to `false`.", }, "method": { - Type: schema.TypeString, - Optional: true, - Default: "GET", + Type: schema.TypeString, + Optional: true, + Default: "GET", + Description: "The method to use for HTTP health-checks. Defaults to `GET`.", }, "interval": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Description: "The interval to wait between each health-check invocation.", }, "timeout": { - Type: schema.TypeString, - Required: true, + Type: schema.TypeString, + Required: true, + Description: "Specifies a timeout for outgoing connections in the case of a HTTP or TCP check.", }, "deregister_critical_service_after": { - Type: schema.TypeString, - Optional: true, - Default: "30s", + Type: schema.TypeString, + Optional: true, + Default: "30s", + Description: "The time after which the service is automatically deregistered when in the `critical` state. Defaults to `30s`.", }, }, }, }, "namespace": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: "The namespace to create the service within.", }, "partition": { @@ -217,8 +251,9 @@ func resourceConsulService() *schema.Resource { }, "enable_tag_override": { - Type: schema.TypeBool, - Optional: true, + Type: schema.TypeBool, + Optional: true, + Description: "Specifies to disable the anti-entropy feature for this service's tags. Defaults to `false`.", }, }, } diff --git a/consul/resource_provider_test.go b/consul/resource_provider_test.go index 9c7743d9..7c074db8 100644 --- a/consul/resource_provider_test.go +++ b/consul/resource_provider_test.go @@ -350,10 +350,23 @@ func waitForService(t *testing.T, address string) (terraform.ResourceProvider, * t.Fatalf("failed to instantiate client: %v", err) } + logger := func(format string, args ...any) {} + if os.Getenv("TF_ACC_CONSUL_LOG") != "" { + logger = t.Logf + } + var services []*consulapi.ServiceEntry for i := 0; i < 20; i++ { services, _, err = client.Health().Service("consul", "", true, nil) - if err == nil && len(services) == 1 && len(services[0].Node.Meta) == 1 { + if err != nil { + logger("got error while waiting for server to start: %v", err) + } else if len(services) != 1 { + logger("got wrong number of services: %d", len(services)) + } else if len(services[0].Node.Meta) == 0 { + logger("got empty metadata") + } else if len(services[0].Node.Meta) < 2 { + logger("missing metadata") + } else { return Provider(), client } diff --git a/docs/resources/service.md b/docs/resources/service.md index 55081c16..87cacd7a 100644 --- a/docs/resources/service.md +++ b/docs/resources/service.md @@ -1,12 +1,17 @@ --- -layout: "consul" -page_title: "Consul: consul_service" -sidebar_current: "docs-consul-resource-service" +page_title: "consul_service Resource - terraform-provider-consul" +subcategory: "" description: |- - A high-level resource for creating a Service in Consul in the Consul catalog. + A high-level resource for creating a Service in Consul in the Consul catalog. This + is appropriate for registering external services https://www.consul.io/docs/guides/external.html and + can be used to create services addressable by Consul that cannot be registered + with a local agent https://www.consul.io/docs/agent/basics.html. + -> NOTE: If a Consul agent is running on the node where this service is + registered, it is not recommended to use this resource as the service will be + removed during the next anti-entropy synchronization https://www.consul.io/docs/architecture/anti-entropy. --- -# consul_service +# consul_service (Resource) A high-level resource for creating a Service in Consul in the Consul catalog. This is appropriate for registering [external services](https://www.consul.io/docs/guides/external.html) and @@ -17,6 +22,7 @@ with a [local agent](https://www.consul.io/docs/agent/basics.html). registered, it is not recommended to use this resource as the service will be removed during the next [anti-entropy synchronization](https://www.consul.io/docs/architecture/anti-entropy). + ## Example Usage Creating a new node with the service: @@ -77,78 +83,57 @@ resource "consul_service" "redis" { } ``` -## Argument Reference - -The following arguments are supported: - -* `name` - (Required, string) The name of the service. - -* `node` - (Required, string) The name of the node the to register the service on. - -* `address` - (Optional, string) The address of the service. Defaults to the - address of the node. - -* `service_id` (Optional, string) - If the service ID is not provided, it will be defaulted to the value -of the `name` attribute. + +## Schema -* `port` - (Optional, int) The port of the service. +### Required -* `checks` - (Optional, list of checks) Health-checks to register to monitor the - service. The list of attributes for each health-check is detailed below. +- `name` (String) The name of the service. +- `node` (String) The name of the node the to register the service on. -* `tags` - (Optional, set of strings) A list of values that are opaque to Consul, - but can be used to distinguish between services or nodes. +### Optional -* `enable_tag_override` - (Optional, boolean) Specifies to disable the - anti-entropy feature for this service's tags. Defaults to `false`. +- `address` (String) The address of the service. Defaults to the address of the node. +- `check` (Block Set) (see [below for nested schema](#nestedblock--check)) +- `datacenter` (String) The datacenter to use. This overrides the agent's default datacenter and the datacenter in the provider setup. +- `enable_tag_override` (Boolean) Specifies to disable the anti-entropy feature for this service's tags. Defaults to `false`. +- `external` (Boolean, Deprecated) +- `meta` (Map of String) A map of arbitrary KV metadata linked to the service instance. +- `namespace` (String) The namespace to create the service within. +- `partition` (String) The partition the service is associated with. +- `port` (Number) The port of the service. +- `service_id` (String) If the service ID is not provided, it will be defaulted to the value of the `name` attribute. +- `tags` (List of String) A list of values that are opaque to Consul, but can be used to distinguish between services or nodes. -* `datacenter` - (Optional) The datacenter to use. This overrides the - agent's default datacenter and the datacenter in the provider setup. +### Read-Only -* `meta` - (Optional) A map of arbitrary KV metadata linked to the service - instance. +- `id` (String) The ID of this resource. -* `namespace` - (Optional, Enterprise Only) The namespace to create the service within. + +### Nested Schema for `check` -* `partition` - (Optional, Enterprise Only) The partition the service is associated with. +Required: -The following attributes are available for each health-check: +- `check_id` (String) An ID, *unique per agent*. +- `interval` (String) The interval to wait between each health-check invocation. +- `name` (String) The name of the health-check. +- `timeout` (String) Specifies a timeout for outgoing connections in the case of a HTTP or TCP check. -* `check_id` - (Optional, string) An ID, *unique per agent*. Will default to *name* - if not set. -* `name` - (Required) The name of the health-check. -* `notes` - (Optional, string) An opaque field meant to hold human readable text. -* `status` - (Optional, string) The initial health-check status. -* `tcp` - (Optional, string) The TCP address and port to connect to for a TCP check. -* `http` - (Optional, string) The HTTP endpoint to call for an HTTP check. -* `header` - (Optional, set of headers) The headers to send for an HTTP check. - The attributes of each header is given below. -* `tls_skip_verify` - (Optional, boolean) Whether to deactivate certificate - verification for HTTP health-checks. Defaults to `false`. -* `method` - (Optional, string) The method to use for HTTP health-checks. Defaults - to `GET`. -* `interval` - (Required, string) The interval to wait between each health-check - invocation. -* `timeout` - (Required, string) Specifies a timeout for outgoing connections in - the case of a HTTP or TCP check. -* `deregister_critical_service_after` - (Optional, string) The time after which - the service is automatically deregistered when in the `critical` state. - Defaults to `30s`. +Optional: -Each `header` must have the following attributes: -* `name` - (Required, string) The name of the header. -* `value` - (Required, list of strings) The header's list of values. +- `deregister_critical_service_after` (String) The time after which the service is automatically deregistered when in the `critical` state. Defaults to `30s`. +- `header` (Block Set) The headers to send for an HTTP check. The attributes of each header is given below. (see [below for nested schema](#nestedblock--check--header)) +- `http` (String) The HTTP endpoint to call for an HTTP check. +- `method` (String) The method to use for HTTP health-checks. Defaults to `GET`. +- `notes` (String) An opaque field meant to hold human readable text. +- `status` (String) The initial health-check status. +- `tcp` (String) The TCP address and port to connect to for a TCP check. +- `tls_skip_verify` (Boolean) Whether to deactivate certificate verification for HTTP health-checks. Defaults to `false`. -## Attributes Reference + +### Nested Schema for `check.header` -The following attributes are exported: +Required: -* `service_id` - The ID of the service. -* `address` - The address of the service. -* `node` - The node the service is registered on. -* `name` - The name of the service. -* `port` - The port of the service. -* `tags` - The tags of the service. -* `checks` - The list of health-checks associated with the service. -* `datacenter` - The datacenter of the service. -* `meta` - A map of arbitrary KV metadata linked to the service instance. +- `name` (String) The name of the header. +- `value` (List of String) The header's list of values. diff --git a/go.mod b/go.mod index df391ba3..b48e012d 100644 --- a/go.mod +++ b/go.mod @@ -100,4 +100,4 @@ require ( google.golang.org/protobuf v1.29.1 // indirect ) -go 1.19 +go 1.21 diff --git a/go.sum b/go.sum index f704096c..6becda55 100644 --- a/go.sum +++ b/go.sum @@ -116,6 +116,7 @@ cloud.google.com/go/language v1.6.0/go.mod h1:6dJ8t3B+lUYfStgls25GusK04NLh3eDLQn cloud.google.com/go/lifesciences v0.5.0/go.mod h1:3oIKy8ycWGPUyZDR/8RNnTOYevhaMLqh5vLUXs9zvT8= cloud.google.com/go/lifesciences v0.6.0/go.mod h1:ddj6tSX/7BOnhxCSd3ZcETvtNr8NZ6t/iPhY2Tyfu08= cloud.google.com/go/longrunning v0.4.1 h1:v+yFJOfKC3yZdY6ZUI933pIYdhyhV8S3NpWrXWmg7jM= +cloud.google.com/go/longrunning v0.4.1/go.mod h1:4iWDqhBZ70CvZ6BfETbvam3T8FMvLK+eFj0E6AaRQTo= cloud.google.com/go/mediatranslation v0.5.0/go.mod h1:jGPUhGTybqsPQn91pNXw0xVHfuJ3leR1wj37oU3y1f4= cloud.google.com/go/mediatranslation v0.6.0/go.mod h1:hHdBCTYNigsBxshbznuIMFNe5QXEowAuNmmC7h8pu5w= cloud.google.com/go/memcache v1.4.0/go.mod h1:rTOfiGZtJX1AaFUrOgsMHX5kAzaTQ8azHiuDoTPzNsE= @@ -347,6 +348,7 @@ github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4= +github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -370,6 +372,7 @@ github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIG github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= github.com/google/martian/v3 v3.2.1/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw= +github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= @@ -431,6 +434,7 @@ github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJ github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-msgpack v0.5.5 h1:i9R9JSrqIz0QVLz3sz+i3YJdT7TTSLcfLLzJi9aZTuI= +github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= @@ -444,6 +448,7 @@ github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhE github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc= +github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -601,6 +606,7 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= @@ -621,6 +627,7 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 h1:nn5Wsu0esKSJiIVhscUtVbo7ada43DJhG55ua/hjS5I= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= @@ -652,6 +659,7 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM= github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8= diff --git a/templates/resources/service.md b/templates/resources/service.md deleted file mode 100644 index 55081c16..00000000 --- a/templates/resources/service.md +++ /dev/null @@ -1,154 +0,0 @@ ---- -layout: "consul" -page_title: "Consul: consul_service" -sidebar_current: "docs-consul-resource-service" -description: |- - A high-level resource for creating a Service in Consul in the Consul catalog. ---- - -# consul_service - -A high-level resource for creating a Service in Consul in the Consul catalog. This -is appropriate for registering [external services](https://www.consul.io/docs/guides/external.html) and -can be used to create services addressable by Consul that cannot be registered -with a [local agent](https://www.consul.io/docs/agent/basics.html). - --> **NOTE:** If a Consul agent is running on the node where this service is -registered, it is not recommended to use this resource as the service will be -removed during the next [anti-entropy synchronization](https://www.consul.io/docs/architecture/anti-entropy). - -## Example Usage - -Creating a new node with the service: - -```hcl -resource "consul_service" "google" { - name = "google" - node = "${consul_node.compute.name}" - port = 80 - tags = ["tag0"] -} - -resource "consul_node" "compute" { - name = "compute-google" - address = "www.google.com" -} -``` - -Utilizing an existing known node: - -```hcl -resource "consul_service" "google" { - name = "google" - node = "google" - port = 443 -} -``` - -Register a health-check: - -```hcl -resource "consul_service" "redis" { - name = "redis" - node = "redis" - port = 6379 - - check { - check_id = "service:redis1" - name = "Redis health check" - status = "passing" - http = "https://www.hashicorptest.com" - tls_skip_verify = false - method = "PUT" - interval = "5s" - timeout = "1s" - deregister_critical_service_after = "30s" - - header { - name = "foo" - value = ["test"] - } - - header { - name = "bar" - value = ["test"] - } - } -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required, string) The name of the service. - -* `node` - (Required, string) The name of the node the to register the service on. - -* `address` - (Optional, string) The address of the service. Defaults to the - address of the node. - -* `service_id` (Optional, string) - If the service ID is not provided, it will be defaulted to the value -of the `name` attribute. - -* `port` - (Optional, int) The port of the service. - -* `checks` - (Optional, list of checks) Health-checks to register to monitor the - service. The list of attributes for each health-check is detailed below. - -* `tags` - (Optional, set of strings) A list of values that are opaque to Consul, - but can be used to distinguish between services or nodes. - -* `enable_tag_override` - (Optional, boolean) Specifies to disable the - anti-entropy feature for this service's tags. Defaults to `false`. - -* `datacenter` - (Optional) The datacenter to use. This overrides the - agent's default datacenter and the datacenter in the provider setup. - -* `meta` - (Optional) A map of arbitrary KV metadata linked to the service - instance. - -* `namespace` - (Optional, Enterprise Only) The namespace to create the service within. - -* `partition` - (Optional, Enterprise Only) The partition the service is associated with. - -The following attributes are available for each health-check: - -* `check_id` - (Optional, string) An ID, *unique per agent*. Will default to *name* - if not set. -* `name` - (Required) The name of the health-check. -* `notes` - (Optional, string) An opaque field meant to hold human readable text. -* `status` - (Optional, string) The initial health-check status. -* `tcp` - (Optional, string) The TCP address and port to connect to for a TCP check. -* `http` - (Optional, string) The HTTP endpoint to call for an HTTP check. -* `header` - (Optional, set of headers) The headers to send for an HTTP check. - The attributes of each header is given below. -* `tls_skip_verify` - (Optional, boolean) Whether to deactivate certificate - verification for HTTP health-checks. Defaults to `false`. -* `method` - (Optional, string) The method to use for HTTP health-checks. Defaults - to `GET`. -* `interval` - (Required, string) The interval to wait between each health-check - invocation. -* `timeout` - (Required, string) Specifies a timeout for outgoing connections in - the case of a HTTP or TCP check. -* `deregister_critical_service_after` - (Optional, string) The time after which - the service is automatically deregistered when in the `critical` state. - Defaults to `30s`. - -Each `header` must have the following attributes: -* `name` - (Required, string) The name of the header. -* `value` - (Required, list of strings) The header's list of values. - -## Attributes Reference - -The following attributes are exported: - -* `service_id` - The ID of the service. -* `address` - The address of the service. -* `node` - The node the service is registered on. -* `name` - The name of the service. -* `port` - The port of the service. -* `tags` - The tags of the service. -* `checks` - The list of health-checks associated with the service. -* `datacenter` - The datacenter of the service. -* `meta` - A map of arbitrary KV metadata linked to the service instance. diff --git a/templates/resources/service.md.tmpl b/templates/resources/service.md.tmpl new file mode 100644 index 00000000..949e626f --- /dev/null +++ b/templates/resources/service.md.tmpl @@ -0,0 +1,73 @@ +--- +page_title: "{{.Name}} {{.Type}} - {{.ProviderName}}" +subcategory: "" +description: |- +{{ .Description | plainmarkdown | trimspace | prefixlines " " }} +--- + +# {{.Name}} ({{.Type}}) + +{{ .Description | trimspace }} + + +## Example Usage + +Creating a new node with the service: + +```hcl +resource "consul_service" "google" { + name = "google" + node = "${consul_node.compute.name}" + port = 80 + tags = ["tag0"] +} + +resource "consul_node" "compute" { + name = "compute-google" + address = "www.google.com" +} +``` + +Utilizing an existing known node: + +```hcl +resource "consul_service" "google" { + name = "google" + node = "google" + port = 443 +} +``` + +Register a health-check: + +```hcl +resource "consul_service" "redis" { + name = "redis" + node = "redis" + port = 6379 + + check { + check_id = "service:redis1" + name = "Redis health check" + status = "passing" + http = "https://www.hashicorptest.com" + tls_skip_verify = false + method = "PUT" + interval = "5s" + timeout = "1s" + deregister_critical_service_after = "30s" + + header { + name = "foo" + value = ["test"] + } + + header { + name = "bar" + value = ["test"] + } + } +} +``` + +{{ .SchemaMarkdown | trimspace }}