Skip to content

Commit

Permalink
Minor updates based on testing with HCP and 1.14.7 (#5)
Browse files Browse the repository at this point in the history
* Allow passing additional environment variables to Consul agents.
* Avoid failing on "ACL not found" when creating an anonymous policy, since it can happen when the policy isn't found.
* Explicitly set 8500 for HTTP API.
  • Loading branch information
freddygv authored and nfi-hashicorp committed Jun 20, 2023
1 parent 74d19c2 commit 4422d4a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion sprawl/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ func CreateOrUpdatePolicy(client *api.Client, p *api.ACLPolicy) (*api.ACLPolicy,
Partition: p.Partition,
Namespace: p.Namespace,
})
if err != nil {

// There is a quirk about Consul 1.14.x, where: if reading a policy yields
// an empty result, we return "ACL not found". It's safe to ignore this here,
// because if the Client's ACL token truly doesn't exist, then the create fails below.
if err != nil && !strings.Contains(err.Error(), "ACL not found") {
return nil, err
} else if currentPolicy != nil {
p.ID = currentPolicy.ID
Expand Down
1 change: 1 addition & 0 deletions sprawl/internal/tfgen/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (g *Generator) generateAgentHCL(step Step, node *topology.Node) (string, er
b.add("grpc", 8502)
b.add("grpc_tls", -1)
}
b.add("http", 8500)
b.add("dns", 8600)
})

Expand Down
3 changes: 2 additions & 1 deletion sprawl/internal/tfgen/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type terraformConsulAgent struct {
ImageResource string
HCL string
EnterpriseLicense string
// Env: map[string]string{"CONSUL_LICENSE": opts.license},
Env []string
}

type terraformMeshGatewayService struct {
Expand Down Expand Up @@ -94,6 +94,7 @@ func (g *Generator) generateNodeContainers(
ImageResource: DockerImageResourceName(node.Images.Consul),
HCL: agentHCL,
EnterpriseLicense: g.license,
Env: node.AgentEnv,
}

switch {
Expand Down
9 changes: 6 additions & 3 deletions sprawl/internal/tfgen/templates/container-consul.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ resource "docker_container" "{{.Node.DockerName}}" {
restart = "always"

env = [
"CONSUL_UID=0",
"CONSUL_GID=0",
"CONSUL_LICENSE={{.EnterpriseLicense}}",
"CONSUL_UID=0",
"CONSUL_GID=0",
"CONSUL_LICENSE={{.EnterpriseLicense}}",
{{- range .Env }}
"{{.}}",
{{- end}}
]

{{- range $k, $v := .Labels }}
Expand Down
5 changes: 5 additions & 0 deletions topology/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ type Node struct {
// the enclosing Cluster.
Images Images

// AgentEnv contains optional environment variables to attach to Consul agents.
AgentEnv []string

Disabled bool `json:",omitempty"`

Addresses []*Address
Expand All @@ -437,8 +440,10 @@ type Node struct {
// denormalized at topology compile
Cluster string
Datacenter string

// computed at topology compile
Index int

// generated during network-and-tls
TLSCertPrefix string `json:",omitempty"`

Expand Down

0 comments on commit 4422d4a

Please sign in to comment.