Skip to content

Commit

Permalink
docs: update offer_url use in integration resource
Browse files Browse the repository at this point in the history
Per juju#449, indicate that offer_url and name/endpoint are mutually
exclusive in an integration resource.
  • Loading branch information
hmlanigan committed Nov 14, 2024
1 parent c7a9b4b commit a31d122
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
12 changes: 7 additions & 5 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ resource "juju_integration" "this" {

Optional:

- `endpoint` (String) The endpoint name.
- `name` (String) The name of the application.
- `offer_url` (String) The URL of a remote application.
- `endpoint` (String) The endpoint name. This attribute may not be used at the same time as the offer_url.
- `name` (String) The name of the application. This attribute may not be used at the same time as the offer_url.
- `offer_url` (String) The URL of a remote application. This attribute may not be used at the same time as name and endpoint.


### Notes
When creating this resource the `offer_url` property will show `(known after apply)` as below:
When creating this resource the `offer_url` property will show `(known after apply)` if a `name` or
`name` and `endpoint` are supplied as below:
```
+ resource "juju_integration" "this" {
+ id = (known after apply)
Expand All @@ -88,7 +89,8 @@ When creating this resource the `offer_url` property will show `(known after app
}
}
```
This is due to a bug in the sdk this provider uses - this property will never be computed and can only be provided by the user.
This is due to an integration requiring a name/endpoint combination or an offer_url, but not both
bits of data together.

## Import

Expand Down
9 changes: 4 additions & 5 deletions docs/resources/offer.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ A resource that represent a Juju Offer.
## Example Usage

```terraform
resource "juju_offer" "this" {
resource "juju_offer" "myoffer" {
model = juju_model.development.name
application_name = juju_application.percona-cluster.name
endpoint = server
}
// an offer can then be used in an integration as below:
resource "juju_integration" "this" {
// an offer can then be used in an cross model integration as below:
resource "juju_integration" "myintegration" {
model = juju_model.development-destination.name
application {
name = juju_application.wordpress.name
endpoint = "db"
}
application {
offer_url = juju_offer.this.url
offer_url = juju_offer.myoffer.url
}
}
```
Expand Down
9 changes: 4 additions & 5 deletions examples/resources/juju_offer/resource.tf
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
resource "juju_offer" "this" {
resource "juju_offer" "myoffer" {
model = juju_model.development.name
application_name = juju_application.percona-cluster.name
endpoint = server
}

// an offer can then be used in an integration as below:
resource "juju_integration" "this" {
// an offer can then be used in an cross model integration as below:
resource "juju_integration" "myintegration" {
model = juju_model.development-destination.name

application {
name = juju_application.wordpress.name
endpoint = "db"
}

application {
offer_url = juju_offer.this.url
offer_url = juju_offer.myoffer.url
}
}
34 changes: 27 additions & 7 deletions internal/provider/resource_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/hashicorp/terraform-plugin-framework-validators/setvalidator"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -138,20 +139,39 @@ func (r *integrationResource) Schema(_ context.Context, _ resource.SchemaRequest
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "The name of the application.",
Optional: true,
Description: "The name of the application. This attribute may not be used at the" +
" same time as the offer_url.",
Optional: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.Expressions{
path.MatchRelative().AtParent().AtName("offer_url"),
}...),
},
},
"endpoint": schema.StringAttribute{
Description: "The endpoint name.",
Optional: true,
Computed: true,
Description: "The endpoint name. This attribute may not be used at the" +
" same time as the offer_url.",
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.ConflictsWith(path.Expressions{
path.MatchRelative().AtParent().AtName("offer_url"),
}...),
},
},
"offer_url": schema.StringAttribute{
Description: "The URL of a remote application.",
Optional: true,
Description: "The URL of a remote application. This attribute may not be used at the" +
" same time as name and endpoint.",
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Validators: []validator.String{
stringvalidator.ConflictsWith(path.Expressions{
path.MatchRelative().AtParent().AtName("name"),
path.MatchRelative().AtParent().AtName("endpoint"),
}...),
},
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions templates/resources/integration.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ description: |-


### Notes
When creating this resource the `offer_url` property will show `(known after apply)` as below:
When creating this resource the `offer_url` property will show `(known after apply)` if a `name` or
`name` and `endpoint` are supplied as below:
```
+ resource "juju_integration" "this" {
+ id = (known after apply)
Expand All @@ -33,7 +34,8 @@ When creating this resource the `offer_url` property will show `(known after app
}
}
```
This is due to a bug in the sdk this provider uses - this property will never be computed and can only be provided by the user.
This is due to an integration requiring a name/endpoint combination or an offer_url, but not both
bits of data together.

{{ if .HasImport -}}
## Import
Expand Down

0 comments on commit a31d122

Please sign in to comment.