From a31d1229d704f550793a40b591a2713ee32eb942 Mon Sep 17 00:00:00 2001 From: Heather Lanigan Date: Wed, 23 Oct 2024 12:08:38 +0000 Subject: [PATCH] docs: update offer_url use in integration resource Per #449, indicate that offer_url and name/endpoint are mutually exclusive in an integration resource. --- docs/resources/integration.md | 12 ++++---- docs/resources/offer.md | 9 +++--- examples/resources/juju_offer/resource.tf | 9 +++--- internal/provider/resource_integration.go | 34 ++++++++++++++++++----- templates/resources/integration.md.tmpl | 6 ++-- 5 files changed, 46 insertions(+), 24 deletions(-) diff --git a/docs/resources/integration.md b/docs/resources/integration.md index 4632e927..1a4b57a8 100644 --- a/docs/resources/integration.md +++ b/docs/resources/integration.md @@ -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) @@ -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 diff --git a/docs/resources/offer.md b/docs/resources/offer.md index a145fefd..02c94610 100644 --- a/docs/resources/offer.md +++ b/docs/resources/offer.md @@ -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 } } ``` diff --git a/examples/resources/juju_offer/resource.tf b/examples/resources/juju_offer/resource.tf index 84e714a5..a7be5728 100644 --- a/examples/resources/juju_offer/resource.tf +++ b/examples/resources/juju_offer/resource.tf @@ -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 } } diff --git a/internal/provider/resource_integration.go b/internal/provider/resource_integration.go index 99e23881..70587a23 100644 --- a/internal/provider/resource_integration.go +++ b/internal/provider/resource_integration.go @@ -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" @@ -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"), + }...), + }, }, }, }, diff --git a/templates/resources/integration.md.tmpl b/templates/resources/integration.md.tmpl index bfea91e6..b422bafb 100644 --- a/templates/resources/integration.md.tmpl +++ b/templates/resources/integration.md.tmpl @@ -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) @@ -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