Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Net 5676 - Service Defaults, Service Splitter, Service Resolver, Service Router and Service Intentions Resource In Terraform Consul Provider #355

Closed
wants to merge 102 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
37bc41b
added resouce service defauls config entry
absolutelightning Sep 20, 2023
f8f28d7
working code
absolutelightning Sep 22, 2023
ef02971
some prog
absolutelightning Sep 22, 2023
b4554cf
working code
absolutelightning Sep 23, 2023
430bb64
fixes
absolutelightning Sep 23, 2023
7c7ce96
fix import
absolutelightning Sep 23, 2023
7be801d
final changes without tests
absolutelightning Sep 25, 2023
b610737
test
absolutelightning Sep 25, 2023
928f582
tests for ce working
absolutelightning Sep 25, 2023
fad1749
added ee tests
absolutelightning Sep 25, 2023
bfd4810
force new
absolutelightning Sep 25, 2023
7c7f340
service splitter
absolutelightning Sep 25, 2023
37746be
fixes during testing
absolutelightning Sep 25, 2023
fb0ba93
added test files
absolutelightning Sep 26, 2023
40c285a
comments addressed
absolutelightning Sep 26, 2023
eba61e3
fix typo
absolutelightning Sep 26, 2023
282c9ad
service splitter
absolutelightning Sep 26, 2023
bfb32f1
fix force new
absolutelightning Sep 26, 2023
f8ed7ef
added tests for service splitter
absolutelightning Sep 26, 2023
33f0c9c
merge NET-5676
absolutelightning Sep 26, 2023
bdfab6d
Merge pull request #1 from absolutelightning/NET-5676-service-splitter
absolutelightning Sep 26, 2023
74c2353
update tests
absolutelightning Sep 26, 2023
b98982a
rename files
absolutelightning Sep 26, 2023
444c996
init
absolutelightning Sep 26, 2023
e265a5e
made the function private
absolutelightning Sep 26, 2023
7943cac
added helper test
absolutelightning Sep 26, 2023
1e5a15c
removed is struct method
absolutelightning Sep 26, 2023
25dee15
Merge branch 'NET-5676' into NET-5676-service-resolvers
absolutelightning Sep 27, 2023
07d2409
fix func name
absolutelightning Sep 27, 2023
7ea84d5
init
absolutelightning Sep 27, 2023
9dac561
fixes while testing
absolutelightning Sep 27, 2023
68bb034
some fixes
absolutelightning Sep 27, 2023
c4e1193
read
absolutelightning Sep 27, 2023
72e719d
Add read support
remilapeyre Sep 27, 2023
08d5184
code service defaults config entry
absolutelightning Sep 28, 2023
d82a7d2
fix resource provider
absolutelightning Sep 28, 2023
d6ec4fb
fixes during testing
absolutelightning Sep 28, 2023
e663022
fix resource name in testS
absolutelightning Sep 28, 2023
7ba2e43
added len check
absolutelightning Sep 28, 2023
d8b0bef
fix nil checks and tests
absolutelightning Sep 28, 2023
832327b
removed helper go
absolutelightning Sep 28, 2023
4e5d6f9
nil check
absolutelightning Sep 28, 2023
86ae204
added description
absolutelightning Sep 28, 2023
4d6a00a
add description fields
absolutelightning Sep 28, 2023
16d4f31
merge NET-5676
absolutelightning Sep 28, 2023
c5dd53a
decode
absolutelightning Sep 28, 2023
c1d8271
init write
absolutelightning Sep 28, 2023
8ffb8a8
rename var name
absolutelightning Sep 28, 2023
5441b06
Merge branch 'NET-5676' into NET-5676-service-resolvers
absolutelightning Sep 28, 2023
e907aa0
write
absolutelightning Sep 28, 2023
f9385ff
delete helper
absolutelightning Sep 28, 2023
ee7e870
fix upstream config
absolutelightning Sep 29, 2023
bed043a
fix tests
absolutelightning Sep 29, 2023
0e70cc2
Fix namespace
absolutelightning Sep 29, 2023
405487b
fix file name
absolutelightning Sep 29, 2023
4d30f5a
manual test of service resolver
absolutelightning Sep 30, 2023
83443fb
server resolver tests flaky
absolutelightning Sep 30, 2023
e35b130
resolver tests
absolutelightning Sep 30, 2023
3bbe42c
tests commented
absolutelightning Sep 30, 2023
93ba3d6
ee tests
absolutelightning Sep 30, 2023
c843ac8
init
absolutelightning Oct 1, 2023
9730ae1
Simplify serviceDefaults.Decode()
remilapeyre Oct 1, 2023
94d240f
fix errors
absolutelightning Oct 2, 2023
959a66e
decode
absolutelightning Oct 3, 2023
1147415
Update consul/resource_consul_config_entry_service_defaults.go
absolutelightning Oct 3, 2023
9935559
schema fix
absolutelightning Oct 3, 2023
dc0e5a8
fix schema
absolutelightning Oct 3, 2023
2260af1
Merge branch 'NET-5676' of ssh://github.com/absolutelightning/terrafo…
absolutelightning Oct 3, 2023
4e35678
fix pointeR
absolutelightning Oct 3, 2023
3deb445
added nil checks
absolutelightning Oct 3, 2023
f25a6aa
fix schema and checks
absolutelightning Oct 3, 2023
c1ac7fd
added nil checks in service splitter
absolutelightning Oct 3, 2023
3309664
fix initializatin
absolutelightning Oct 3, 2023
b75bce6
fix ee tests
absolutelightning Oct 3, 2023
d56fe73
fix tests
absolutelightning Oct 3, 2023
0777493
some fixes
absolutelightning Oct 3, 2023
92044ad
write
absolutelightning Oct 3, 2023
8a4d3e4
return nil
absolutelightning Oct 3, 2023
8e469ee
fixes
absolutelightning Oct 4, 2023
58a2c7b
added description
absolutelightning Oct 4, 2023
30b50e3
intentions
absolutelightning Oct 4, 2023
0120ded
Merge pull request #4 from absolutelightning/NET-5676-service-intentions
absolutelightning Oct 4, 2023
9a03247
Merge branch 'NET-5676' into NET-5676-service-resolvers
absolutelightning Oct 4, 2023
fdfeff2
merge
absolutelightning Oct 4, 2023
c3e9d36
Merge pull request #2 from absolutelightning/NET-5676-service-resolvers
absolutelightning Oct 4, 2023
1778d73
Merge branch 'NET-5676' into NET-5676-service-router
absolutelightning Oct 4, 2023
08916f3
Merge pull request #3 from absolutelightning/NET-5676-service-router
absolutelightning Oct 4, 2023
bee3491
fix resource provider
absolutelightning Oct 4, 2023
56cc862
fix intentinos schema
absolutelightning Oct 4, 2023
28bd93e
fix intentions
absolutelightning Oct 4, 2023
5ac3ed7
intentions fixes
absolutelightning Oct 4, 2023
31aec22
intentions test
absolutelightning Oct 4, 2023
3b703a9
[COMPLIANCE] Add Copyright and License Headers (#353)
hashicorp-copywrite[bot] Oct 8, 2023
bb9bac0
Fix consul_service resource documentation (#352)
remilapeyre Oct 8, 2023
656eb65
Indicate that max_token_ttl is required for OIDC auth methods (#360)
am-ak Oct 8, 2023
c0afbe9
Fix consul_config_entry_service_router tests
remilapeyre Oct 9, 2023
4e3b4e5
Merge remote-tracking branch 'origin/master' into absolutelightning-N…
remilapeyre Oct 9, 2023
65c97db
service router ee test
absolutelightning Oct 9, 2023
d05516b
fix intentnios
absolutelightning Oct 9, 2023
d323696
make intentinos tests passing
absolutelightning Oct 9, 2023
0e691fb
update tests
absolutelightning Oct 9, 2023
ca04233
fix tests
absolutelightning Oct 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,3 @@ test-compile:
go test -c $(TEST) $(TESTARGS)

.PHONY: build test testacc vet fmt fmtcheck errcheck test-compile test-serv

1 change: 1 addition & 0 deletions consul/data_source_consul_service_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestAccDataConsulServiceHealth(t *testing.T) {
testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.node.0.tagged_addresses.%", "4"),
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.node.0.meta.consul-version", "<any>"),

testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.service.0.id", "consul"),
testAccCheckDataSourceValue("data.consul_service_health.consul", "results.0.service.0.name", "consul"),
Expand Down
1 change: 1 addition & 0 deletions consul/data_source_consul_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func TestAccDataConsulService_basic(t *testing.T) {
testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_id", "<any>"),
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_meta.consul-version", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.node_name", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.port", "<any>"),
testAccCheckDataSourceValue("data.consul_service.read", "service.0.tagged_addresses.%", "4"),
Expand Down
129 changes: 129 additions & 0 deletions consul/resource_consul_config_entry_concrete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package consul

import (
"fmt"
"strings"

consulapi "github.com/hashicorp/consul/api"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

// ConfigEntryImplementation is the common implementation for all specific
// config entries.
type ConfigEntryImplementation interface {
GetKind() string
GetDescription() string
GetSchema() map[string]*schema.Schema
Decode(d *schema.ResourceData) (consulapi.ConfigEntry, error)
Write(ce consulapi.ConfigEntry, d *schema.ResourceData, sw *stateWriter) error
}

func resourceFromConfigEntryImplementation(c ConfigEntryImplementation) *schema.Resource {
return &schema.Resource{
Description: c.GetDescription(),
Schema: c.GetSchema(),
Create: configEntryImplementationWrite(c),
Update: configEntryImplementationWrite(c),
Read: configEntryImplementationRead(c),
Delete: configEntryImplementationDelete(c),
Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
parts := strings.Split(d.Id(), "/")
var name, partition, namespace string
switch len(parts) {
case 1:
name = parts[0]
case 3:
partition = parts[0]
namespace = parts[1]
name = parts[2]
default:
return nil, fmt.Errorf(`expected path of the form "<name>" or "<partition>/<namespace>/<name>"`)
}

d.SetId(name)
sw := newStateWriter(d)
sw.set("name", name)
sw.set("partition", partition)
sw.set("namespace", namespace)

err := sw.error()
if err != nil {
return nil, err
}

return []*schema.ResourceData{d}, nil
},
},
}
}

func configEntryImplementationWrite(impl ConfigEntryImplementation) func(d *schema.ResourceData, meta interface{}) error {
return func(d *schema.ResourceData, meta interface{}) error {
client, qOpts, wOpts := getClient(d, meta)

configEntry, err := impl.Decode(d)
if err != nil {
return err
}

if _, _, err := client.ConfigEntries().Set(configEntry, wOpts); err != nil {
return fmt.Errorf("failed to set '%s' config entry: %v", configEntry.GetName(), err)
}
_, _, err = client.ConfigEntries().Get(configEntry.GetKind(), configEntry.GetName(), qOpts)
if err != nil {
if strings.Contains(err.Error(), "Unexpected response code: 404") {
return fmt.Errorf("failed to read config entry after setting it")
}
return fmt.Errorf("failed to read config entry: %v", err)
}

d.SetId(configEntry.GetName())
return configEntryImplementationRead(impl)(d, meta)
}
}

func configEntryImplementationRead(impl ConfigEntryImplementation) func(d *schema.ResourceData, meta interface{}) error {
return func(d *schema.ResourceData, meta interface{}) error {
client, qOpts, _ := getClient(d, meta)
name := d.Get("name").(string)

fixQOptsForConfigEntry(name, impl.GetKind(), qOpts)

ce, _, err := client.ConfigEntries().Get(impl.GetKind(), name, qOpts)
if err != nil {
if strings.Contains(err.Error(), "Unexpected response code: 404") {
// The config entry has been removed
d.SetId("")
return nil
}
return fmt.Errorf("failed to fetch '%s' config entry: %v", name, err)
}
if ce == nil {
d.SetId("")
return nil
}

sw := newStateWriter(d)
if err := impl.Write(ce, d, sw); err != nil {
return err
}
return sw.error()
}
}

func configEntryImplementationDelete(impl ConfigEntryImplementation) func(d *schema.ResourceData, meta interface{}) error {
return func(d *schema.ResourceData, meta interface{}) error {
client, _, wOpts := getClient(d, meta)
name := d.Get("name").(string)

if _, err := client.ConfigEntries().Delete(impl.GetKind(), name, wOpts); err != nil {
return fmt.Errorf("failed to delete '%s' config entry: %v", name, err)
}
d.SetId("")
return nil
}
}
Loading
Loading