Skip to content

Commit

Permalink
app: Add internal_address and router fieldas as readOnly fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Apr 27, 2021
1 parent 2938b63 commit cb9a83e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tsuru/resource_tsuru_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,58 @@ func resourceTsuruApplication() *schema.Resource {
Description: "Restart app after applying changes",
Optional: true,
},

"internal_address": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"domain": {
Type: schema.TypeString,
Computed: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
},
"process": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
"protocol": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"router": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"addresses": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"options": {
Type: schema.TypeMap,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -245,6 +297,9 @@ func resourceTsuruApplicationRead(ctx context.Context, d *schema.ResourceData, m
}})
}

d.Set("internal_address", flattenInternalAddresses(app.InternalAddresses))
d.Set("router", flattenRouters(app.Routers))

return nil
}

Expand Down
19 changes: 19 additions & 0 deletions tsuru/resource_tsuru_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ func TestAccResourceTsuruApp(t *testing.T) {
Units: []tsuru.Unit{
{Processname: "web"},
},
InternalAddresses: []tsuru.AppInternalAddresses{
{
Version: "10",
Port: 8888,
Process: "web",
Domain: "app01.namespace.svc.cluster.local",
Protocol: "TCP",
},
},
Routers: []tsuru.AppRouters{
{
Name: "default-router",
Addresses: []string{
"my-app.router.io",
},
},
},
}
return c.JSON(http.StatusOK, app)
}
Expand Down Expand Up @@ -113,6 +130,8 @@ func TestAccResourceTsuruApp(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "pool", "prod"),
resource.TestCheckResourceAttr(resourceName, "tags.0", "tagA"),
resource.TestCheckResourceAttr(resourceName, "tags.1", "tagB"),
resource.TestCheckResourceAttr(resourceName, "router.0.name", "default-router"),
resource.TestCheckResourceAttr(resourceName, "internal_address.0.domain", "app01.namespace.svc.cluster.local"),
),
},
},
Expand Down

0 comments on commit cb9a83e

Please sign in to comment.