diff --git a/docs/data-sources/service_broker.md b/docs/data-sources/service_broker.md new file mode 100644 index 0000000..f699779 --- /dev/null +++ b/docs/data-sources/service_broker.md @@ -0,0 +1,42 @@ +--- +page_title: "cloudfoundry_service_broker Data Source - terraform-provider-cloudfoundry" +subcategory: "" +description: |- + Gets information of a Service broker. +--- + +# cloudfoundry_service_broker (Data Source) + +Gets information of a Service broker. + +## Example Usage + +```terraform +data "cloudfoundry_service_broker" "broker" { + name = "hi" +} + +output "se_br" { + value = data.cloudfoundry_service_broker.broker +} +``` + + +## Schema + +### Required + +- `name` (String) Name of the service broker + +### Optional + +- `annotations` (Map of String) The annotations associated with Cloud Foundry resources. Add as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object). +- `labels` (Map of String) The labels associated with Cloud Foundry resources. Add as described [here](https://docs.cloudfoundry.org/adminguide/metadata.html#-view-metadata-for-an-object). + +### Read-Only + +- `created_at` (String) The date and time when the resource was created in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format. +- `id` (String) The GUID of the object. +- `space` (String) The GUID of the space the service broker is restricted to; omitted for globally available service brokers +- `updated_at` (String) The date and time when the resource was updated in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format. +- `url` (String) URL of the service broker \ No newline at end of file diff --git a/examples/data-sources/cloudfoundry_service_broker/data-source.tf b/examples/data-sources/cloudfoundry_service_broker/data-source.tf new file mode 100644 index 0000000..5a32f5c --- /dev/null +++ b/examples/data-sources/cloudfoundry_service_broker/data-source.tf @@ -0,0 +1,7 @@ +data "cloudfoundry_service_broker" "broker" { + name = "hi" +} + +output "se_br" { + value = data.cloudfoundry_service_broker.broker +} diff --git a/internal/provider/datasource_service_broker.go b/internal/provider/datasource_service_broker.go new file mode 100644 index 0000000..e6e6063 --- /dev/null +++ b/internal/provider/datasource_service_broker.go @@ -0,0 +1,104 @@ +package provider + +import ( + "context" + "fmt" + + cfv3client "github.com/cloudfoundry/go-cfclient/v3/client" + "github.com/cloudfoundry/terraform-provider-cloudfoundry/internal/provider/managers" + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" +) + +func NewServiceBrokerDataSource() datasource.DataSource { + return &ServiceBrokerDataSource{} +} + +type ServiceBrokerDataSource struct { + cfClient *cfv3client.Client +} + +func (d *ServiceBrokerDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_service_broker" +} + +func (d *ServiceBrokerDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Gets information of a Service broker.", + + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + MarkdownDescription: "Name of the service broker", + Required: true, + }, + "url": schema.StringAttribute{ + MarkdownDescription: "URL of the service broker", + Computed: true, + }, + "space": schema.StringAttribute{ + MarkdownDescription: "The GUID of the space the service broker is restricted to; omitted for globally available service brokers", + Computed: true, + }, + idKey: guidSchema(), + labelsKey: resourceLabelsSchema(), + annotationsKey: resourceAnnotationsSchema(), + createdAtKey: createdAtSchema(), + updatedAtKey: updatedAtSchema(), + }, + } +} + +func (d *ServiceBrokerDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { + // Prevent panic if the provider has not been configured. + if req.ProviderData == nil { + return + } + session, ok := req.ProviderData.(*managers.Session) + if !ok { + resp.Diagnostics.AddError( + "Unexpected Data Source Configure Type", + fmt.Sprintf("Expected *managers.Session, got: %T. Please report this issue to the provider developers.", req.ProviderData), + ) + return + } + d.cfClient = session.CFClient +} + +func (d *ServiceBrokerDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + + var data datasourceServiceBrokerType + + diags := req.Config.Get(ctx, &data) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + getOptions := cfv3client.NewServiceBrokerListOptions() + getOptions.Names = cfv3client.Filter{ + Values: []string{ + data.Name.ValueString(), + }, + } + + svcBrokers, err := d.cfClient.ServiceBrokers.ListAll(ctx, getOptions) + if err != nil { + resp.Diagnostics.AddError( + "API Error in fetching service broker data.", + fmt.Sprintf("Request failed with %s.", err.Error()), + ) + return + } + if len(svcBrokers) == 0 { + resp.Diagnostics.AddError( + "Unable to find service broker in list", + fmt.Sprintf("Given name %s not in the list of service brokers.", data.Name.ValueString()), + ) + return + } + + dataValue, diags := mapServiceBrokerValuesToType(ctx, svcBrokers[0]) + resp.Diagnostics.Append(diags...) + data = dataValue.Reduce() + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/internal/provider/datasource_service_broker_test.go b/internal/provider/datasource_service_broker_test.go new file mode 100644 index 0000000..4d79c5d --- /dev/null +++ b/internal/provider/datasource_service_broker_test.go @@ -0,0 +1,60 @@ +package provider + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +func TestServiceBrokerDataSource(t *testing.T) { + t.Parallel() + serviceBrokerName := "hi" + t.Run("happy path - read service broker", func(t *testing.T) { + cfg := getCFHomeConf() + dataSourceName := "data.cloudfoundry_service_broker.ds" + rec := cfg.SetupVCR(t, "fixtures/datasource_service_broker") + defer stopQuietly(rec) + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclServiceBroker(&ServiceBrokerModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: &serviceBrokerName, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestMatchResourceAttr(dataSourceName, "id", regexpValidUUID), + resource.TestMatchResourceAttr(dataSourceName, "space", regexpValidUUID), + resource.TestCheckResourceAttr(dataSourceName, "name", serviceBrokerName), + resource.TestMatchResourceAttr(dataSourceName, "created_at", regexpValidRFC3999Format), + resource.TestMatchResourceAttr(dataSourceName, "updated_at", regexpValidRFC3999Format), + ), + }, + }, + }) + }) + t.Run("error path - get unavailable service broker", func(t *testing.T) { + cfg := getCFHomeConf() + rec := cfg.SetupVCR(t, "fixtures/datasource_service_broker_invalid") + defer stopQuietly(rec) + // Create a Terraform configuration that uses the data source + // and run `terraform apply`. The data source should not be found. + resource.UnitTest(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclServiceBroker(&ServiceBrokerModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: strtostrptr("invalid-service-instance-name"), + }), + ExpectError: regexp.MustCompile(`Unable to find service broker in list`), + }, + }, + }) + }) +} diff --git a/internal/provider/fixtures/datasource_service_broker.yaml b/internal/provider/fixtures/datasource_service_broker.yaml new file mode 100644 index 0000000..0513e4b --- /dev/null +++ b/internal/provider/fixtures/datasource_service_broker.yaml @@ -0,0 +1,375 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 73 + transfer_encoding: [] + trailer: {} + host: uaa.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: grant_type=refresh_token&refresh_token=717a4fc677bd40218559c2c02ad83787-r + form: + grant_type: + - refresh_token + refresh_token: + - 717a4fc677bd40218559c2c02ad83787-r + headers: + Authorization: + - Basic Y2Y6 + Content-Type: + - application/x-www-form-urlencoded + url: https://uaa.x.x.x.x.com/oauth/token + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: false + body: '{"access_token":"redacted","token_type":"bearer","id_token":"redacted","refresh_token":"717a4fc677bd40218559c2c02ad83787-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"ba62502874f743b1b952cd403cee672f"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Thu, 31 Oct 2024 11:27:37 GMT + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Vcap-Request-Id: + - 90260229-72f7-4361-7899-dde17e8124f0 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 792.295208ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Authorization: + - Bearer redacted + User-Agent: + - Terraform/1.5.7 terraform-provider-cloudfoundry/dev + url: https://api.x.x.x.x.com/v3/service_brokers?names=hi&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1019 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"71203fb7-558a-4dd7-b87d-ddc289c5c85f","created_at":"2024-06-24T04:53:36Z","updated_at":"2024-06-24T04:53:36Z","name":"hi","url":"https://tf-test-do-not-delete-nodejs.cfapps.sap.hana.ondemand.com","relationships":{"space":{"data":{"guid":"02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}},"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/service_brokers/71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"service_offerings":{"href":"https://api.x.x.x.x.com/v3/service_offerings?service_broker_guids=71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"space":{"href":"https://api.x.x.x.x.com/v3/spaces/02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}}]}' + headers: + Content-Length: + - "1019" + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 31 Oct 2024 11:27:38 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 6cd2e6ed41b4dea0 + X-B3-Traceid: + - 663233bc952b466e6cd2e6ed41b4dea0 + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Ratelimit-Limit: + - "20000" + X-Ratelimit-Remaining: + - "18000" + X-Ratelimit-Reset: + - "1730374388" + X-Runtime: + - "0.029413" + X-Vcap-Request-Id: + - 663233bc-952b-466e-6cd2-e6ed41b4dea0::80c3048f-e6bd-4881-a392-8a081974fbdd + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 678.293459ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 73 + transfer_encoding: [] + trailer: {} + host: uaa.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: grant_type=refresh_token&refresh_token=717a4fc677bd40218559c2c02ad83787-r + form: + grant_type: + - refresh_token + refresh_token: + - 717a4fc677bd40218559c2c02ad83787-r + headers: + Authorization: + - Basic Y2Y6 + Content-Type: + - application/x-www-form-urlencoded + url: https://uaa.x.x.x.x.com/oauth/token + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: false + body: '{"access_token":"redacted","token_type":"bearer","id_token":"redacted","refresh_token":"717a4fc677bd40218559c2c02ad83787-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"5615f8abd23f451099c78b42d7cee807"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Thu, 31 Oct 2024 11:27:37 GMT + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Vcap-Request-Id: + - 152c4dce-49b9-4532-4d31-226473d7b4dd + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 206.022ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Authorization: + - Bearer redacted + User-Agent: + - Terraform/1.5.7 terraform-provider-cloudfoundry/dev + url: https://api.x.x.x.x.com/v3/service_brokers?names=hi&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1019 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"71203fb7-558a-4dd7-b87d-ddc289c5c85f","created_at":"2024-06-24T04:53:36Z","updated_at":"2024-06-24T04:53:36Z","name":"hi","url":"https://tf-test-do-not-delete-nodejs.cfapps.sap.hana.ondemand.com","relationships":{"space":{"data":{"guid":"02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}},"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/service_brokers/71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"service_offerings":{"href":"https://api.x.x.x.x.com/v3/service_offerings?service_broker_guids=71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"space":{"href":"https://api.x.x.x.x.com/v3/spaces/02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}}]}' + headers: + Content-Length: + - "1019" + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 31 Oct 2024 11:27:38 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 550a55864966ee24 + X-B3-Traceid: + - 59853e68757e404d550a55864966ee24 + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Ratelimit-Limit: + - "20000" + X-Ratelimit-Remaining: + - "18000" + X-Ratelimit-Reset: + - "1730374388" + X-Runtime: + - "0.030643" + X-Vcap-Request-Id: + - 59853e68-757e-404d-550a-55864966ee24::13455165-d1b0-423f-a309-cc1fac7b8af4 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 209.270542ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 73 + transfer_encoding: [] + trailer: {} + host: uaa.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: grant_type=refresh_token&refresh_token=717a4fc677bd40218559c2c02ad83787-r + form: + grant_type: + - refresh_token + refresh_token: + - 717a4fc677bd40218559c2c02ad83787-r + headers: + Authorization: + - Basic Y2Y6 + Content-Type: + - application/x-www-form-urlencoded + url: https://uaa.x.x.x.x.com/oauth/token + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: false + body: '{"access_token":"redacted","token_type":"bearer","id_token":"redacted","refresh_token":"717a4fc677bd40218559c2c02ad83787-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"30ca0abd95204e619a3b0a094e5161a7"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Thu, 31 Oct 2024 11:27:38 GMT + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Vcap-Request-Id: + - 48e0e91e-02ac-424e-518d-ee3f3ad0da0a + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 199.867459ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Authorization: + - Bearer redacted + User-Agent: + - Terraform/1.5.7 terraform-provider-cloudfoundry/dev + url: https://api.x.x.x.x.com/v3/service_brokers?names=hi&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1019 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=hi\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"71203fb7-558a-4dd7-b87d-ddc289c5c85f","created_at":"2024-06-24T04:53:36Z","updated_at":"2024-06-24T04:53:36Z","name":"hi","url":"https://tf-test-do-not-delete-nodejs.cfapps.sap.hana.ondemand.com","relationships":{"space":{"data":{"guid":"02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}},"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/service_brokers/71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"service_offerings":{"href":"https://api.x.x.x.x.com/v3/service_offerings?service_broker_guids=71203fb7-558a-4dd7-b87d-ddc289c5c85f"},"space":{"href":"https://api.x.x.x.x.com/v3/spaces/02c0cc92-6ecc-44b1-b7b2-096ca19ee143"}}}]}' + headers: + Content-Length: + - "1019" + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 31 Oct 2024 11:27:39 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 6c6f89625eb7111a + X-B3-Traceid: + - 97067e69f5554df26c6f89625eb7111a + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Ratelimit-Limit: + - "20000" + X-Ratelimit-Remaining: + - "18000" + X-Ratelimit-Reset: + - "1730374388" + X-Runtime: + - "0.030130" + X-Vcap-Request-Id: + - 97067e69-f555-4df2-6c6f-89625eb7111a::4100e87f-6773-40e8-8b0b-8b79e4daf988 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 208.156667ms diff --git a/internal/provider/fixtures/datasource_service_broker_invalid.yaml b/internal/provider/fixtures/datasource_service_broker_invalid.yaml new file mode 100644 index 0000000..b5af0c3 --- /dev/null +++ b/internal/provider/fixtures/datasource_service_broker_invalid.yaml @@ -0,0 +1,127 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 73 + transfer_encoding: [] + trailer: {} + host: uaa.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: grant_type=refresh_token&refresh_token=717a4fc677bd40218559c2c02ad83787-r + form: + grant_type: + - refresh_token + refresh_token: + - 717a4fc677bd40218559c2c02ad83787-r + headers: + Authorization: + - Basic Y2Y6 + Content-Type: + - application/x-www-form-urlencoded + url: https://uaa.x.x.x.x.com/oauth/token + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: false + body: '{"access_token":"redacted","token_type":"bearer","id_token":"redacted","refresh_token":"717a4fc677bd40218559c2c02ad83787-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"710be900e83b472a87d07988e6004988"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Thu, 31 Oct 2024 11:27:39 GMT + Pragma: + - no-cache + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + X-Vcap-Request-Id: + - 5c88b804-5c08-419d-5b39-5678c8372947 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 193.505375ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.x.x.x.x.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Authorization: + - Bearer redacted + User-Agent: + - Terraform/1.5.7 terraform-provider-cloudfoundry/dev + url: https://api.x.x.x.x.com/v3/service_brokers?names=invalid-service-instance-name&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 372 + uncompressed: false + body: '{"pagination":{"total_results":0,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=invalid-service-instance-name\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/service_brokers?names=invalid-service-instance-name\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[]}' + headers: + Content-Length: + - "372" + Content-Type: + - application/json; charset=utf-8 + Date: + - Thu, 31 Oct 2024 11:27:39 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 5de2d36f59d0a7d3 + X-B3-Traceid: + - 48d52a7b549641265de2d36f59d0a7d3 + X-Content-Type-Options: + - nosniff + X-Download-Options: + - noopen + X-Frame-Options: + - SAMEORIGIN + X-Permitted-Cross-Domain-Policies: + - none + X-Ratelimit-Limit: + - "20000" + X-Ratelimit-Remaining: + - "18000" + X-Ratelimit-Reset: + - "1730374387" + X-Runtime: + - "0.025211" + X-Vcap-Request-Id: + - 48d52a7b-5496-4126-5de2-d36f59d0a7d3::53d08a64-d5a5-4ad1-970f-c62796e08b50 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 206.848917ms diff --git a/internal/provider/provider.go b/internal/provider/provider.go index c05092d..8ddf5a0 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -343,6 +343,7 @@ func (p *CloudFoundryProvider) DataSources(ctx context.Context) []func() datasou NewSpaceRolesDataSource, NewDomainsDataSource, NewRoutesDataSource, + NewServiceBrokerDataSource, } } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index 59493ee..b6b23a3 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -322,6 +322,7 @@ func TestProvider_HasDataSources(t *testing.T) { "cloudfoundry_space_roles", "cloudfoundry_domains", "cloudfoundry_routes", + "cloudfoundry_service_broker", } ctx := context.Background() diff --git a/internal/provider/types_service_broker.go b/internal/provider/types_service_broker.go index ccde80d..41c7789 100644 --- a/internal/provider/types_service_broker.go +++ b/internal/provider/types_service_broker.go @@ -22,6 +22,23 @@ type serviceBrokerType struct { UpdatedAt types.String `tfsdk:"updated_at"` } +type datasourceServiceBrokerType struct { + Name types.String `tfsdk:"name"` + ID types.String `tfsdk:"id"` + Url types.String `tfsdk:"url"` + Space types.String `tfsdk:"space"` + Labels types.Map `tfsdk:"labels"` + Annotations types.Map `tfsdk:"annotations"` + CreatedAt types.String `tfsdk:"created_at"` + UpdatedAt types.String `tfsdk:"updated_at"` +} + +func (a *serviceBrokerType) Reduce() datasourceServiceBrokerType { + var reduced datasourceServiceBrokerType + copyFields(&reduced, a) + return reduced +} + func mapServiceBrokerValuesToType(ctx context.Context, value *resource.ServiceBroker) (serviceBrokerType, diag.Diagnostics) { var diagnostics, diags diag.Diagnostics serviceBrokerType := serviceBrokerType{ diff --git a/migration-guide/Readme.md b/migration-guide/Readme.md index 3233a11..ba69c03 100644 --- a/migration-guide/Readme.md +++ b/migration-guide/Readme.md @@ -202,6 +202,7 @@ The below mentioned dataSources have been newly added in the current provider. - [Org Roles](../docs/data-sources/org_roles.md) - [Organizations](../docs/data-sources/orgs.md) - [Routes](../docs/data-sources/routes.md) +- [Service Broker](../docs/data-sources/service_broker.md) - [Service Instances](../docs/data-sources/service_instances.md) - [Service Plans](../docs/data-sources/service_plans.md) - [Space Role](../docs/data-sources/space_role.md)