Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into am-ak-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
remilapeyre committed Oct 8, 2023
2 parents aa165eb + 7ce8556 commit b73c47e
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 289 deletions.
20 changes: 20 additions & 0 deletions .copywrite.hcl
Original file line number Diff line number Diff line change
@@ -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",
]
}
23 changes: 20 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017 HashiCorp, Inc.
Copyright (c) 2023 HashiCorp, Inc.

Mozilla Public License Version 2.0
==================================
Expand Down
2 changes: 1 addition & 1 deletion consul/data_source_consul_service_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestAccDataConsulServiceHealth(t *testing.T) {
testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.address", "<any>"),
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"),
Expand Down
2 changes: 1 addition & 1 deletion consul/data_source_consul_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAccDataConsulService_basic(t *testing.T) {
testAccCheckDataSourceValue("data.consul_service.read", "service.0.name", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_address", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_id", "<any>"),
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", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.port", "<any>"),
Expand Down
157 changes: 96 additions & 61 deletions consul/resource_consul_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
},
}
Expand All @@ -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": {
Expand All @@ -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": {
Expand All @@ -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": {
Expand Down Expand Up @@ -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": {
Expand All @@ -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`.",
},
},
}
Expand Down
15 changes: 14 additions & 1 deletion consul/resource_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit b73c47e

Please sign in to comment.