From f4b425569e5e9c1110f7a9da894387074fdec65e Mon Sep 17 00:00:00 2001 From: Debaditya Date: Wed, 6 Nov 2024 15:42:40 +0530 Subject: [PATCH] Added isolation_segments datasource --- docs/data-sources/isolation_segments.md | 41 ++ .../data-source.tf | 3 + .../provider/datasource_isolation_segments.go | 118 ++++++ .../datasource_isolation_segments_test.go | 93 +++++ .../datasource_isolation_segments.yaml | 375 ++++++++++++++++++ ...datasource_isolation_segments_invalid.yaml | 127 ++++++ internal/provider/provider.go | 1 + internal/provider/provider_test.go | 1 + internal/provider/types_isolation_segment.go | 18 + internal/provider/types_org.go | 1 - migration-guide/Readme.md | 1 + 11 files changed, 778 insertions(+), 1 deletion(-) create mode 100644 docs/data-sources/isolation_segments.md create mode 100644 examples/data-sources/cloudfoundry_isolation_segments/data-source.tf create mode 100644 internal/provider/datasource_isolation_segments.go create mode 100644 internal/provider/datasource_isolation_segments_test.go create mode 100644 internal/provider/fixtures/datasource_isolation_segments.yaml create mode 100644 internal/provider/fixtures/datasource_isolation_segments_invalid.yaml diff --git a/docs/data-sources/isolation_segments.md b/docs/data-sources/isolation_segments.md new file mode 100644 index 0000000..a6a9171 --- /dev/null +++ b/docs/data-sources/isolation_segments.md @@ -0,0 +1,41 @@ +--- +page_title: "cloudfoundry_isolation_segments Data Source - terraform-provider-cloudfoundry" +subcategory: "" +description: |- + Gets information on Cloud Foundry Isolation Segments present. +--- + +# cloudfoundry_isolation_segments (Data Source) + +Gets information on Cloud Foundry Isolation Segments present. + +## Example Usage + +```terraform +data "cloudfoundry_isolation_segments" "isosegments" { + name = "hifi" +} +``` + + +## Schema + +### Optional + +- `name` (String) Name of the isolation segment to filter by + +### Read-Only + +- `isolation_segments` (Attributes List) List of the isolation segments (see [below for nested schema](#nestedatt--isolation_segments)) + + +### Nested Schema for `isolation_segments` + +Read-Only: + +- `annotations` (Map of String) The annotations associated with Cloud Foundry resources. +- `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. +- `labels` (Map of String) The labels associated with Cloud Foundry resources. +- `name` (String) Name of the isolation segment +- `updated_at` (String) The date and time when the resource was updated in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format. \ No newline at end of file diff --git a/examples/data-sources/cloudfoundry_isolation_segments/data-source.tf b/examples/data-sources/cloudfoundry_isolation_segments/data-source.tf new file mode 100644 index 0000000..5830a3c --- /dev/null +++ b/examples/data-sources/cloudfoundry_isolation_segments/data-source.tf @@ -0,0 +1,3 @@ +data "cloudfoundry_isolation_segments" "isosegments" { + name = "hifi" +} \ No newline at end of file diff --git a/internal/provider/datasource_isolation_segments.go b/internal/provider/datasource_isolation_segments.go new file mode 100644 index 0000000..2b71a5e --- /dev/null +++ b/internal/provider/datasource_isolation_segments.go @@ -0,0 +1,118 @@ +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" + "github.com/hashicorp/terraform-plugin-log/tflog" +) + +// Ensure provider defined types fully satisfy framework interfaces. +var ( + _ datasource.DataSource = &IsolationSegmentsDataSource{} + _ datasource.DataSourceWithConfigure = &IsolationSegmentsDataSource{} +) + +func NewIsolationSegmentsDataSource() datasource.DataSource { + return &IsolationSegmentsDataSource{} +} + +type IsolationSegmentsDataSource struct { + cfClient *cfv3client.Client +} + +func (d *IsolationSegmentsDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_isolation_segments" +} + +func (d *IsolationSegmentsDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Gets information on Cloud Foundry Isolation Segments present.", + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + MarkdownDescription: "Name of the isolation segment to filter by", + Optional: true, + }, + "isolation_segments": schema.ListNestedAttribute{ + MarkdownDescription: "List of the isolation segments", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + idKey: guidSchema(), + "name": schema.StringAttribute{ + MarkdownDescription: "Name of the isolation segment", + Computed: true, + }, + labelsKey: datasourceLabelsSchema(), + annotationsKey: datasourceAnnotationsSchema(), + createdAtKey: createdAtSchema(), + updatedAtKey: updatedAtSchema(), + }, + }, + }, + }, + } +} + +func (d *IsolationSegmentsDataSource) 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 *IsolationSegmentsDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + + var data IsolationSegmentsType + + diags := req.Config.Get(ctx, &data) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + getOptions := cfv3client.NewIsolationSegmentOptions() + if !data.Name.IsNull() { + getOptions.Names = cfv3client.Filter{ + Values: []string{ + data.Name.ValueString(), + }, + } + } + + isolationSegments, err := d.cfClient.IsolationSegments.ListAll(ctx, getOptions) + if err != nil { + resp.Diagnostics.AddError( + "API Error Fetching Isolation Segment.", + fmt.Sprintf("Request failed with %s.", err.Error()), + ) + return + } + + if len(isolationSegments) == 0 { + resp.Diagnostics.AddError( + "Unable to find any Isolation Segment in given list", + "No isolation segment found with given criteria", + ) + return + } + + data.IsolationSegments, diags = mapIsolationSegmentsValuesToType(ctx, isolationSegments) + resp.Diagnostics.Append(diags...) + + tflog.Trace(ctx, "read an isolation segments data source") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/internal/provider/datasource_isolation_segments_test.go b/internal/provider/datasource_isolation_segments_test.go new file mode 100644 index 0000000..646a58c --- /dev/null +++ b/internal/provider/datasource_isolation_segments_test.go @@ -0,0 +1,93 @@ +package provider + +import ( + "bytes" + "regexp" + "testing" + "text/template" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +type IsolationSegmentsModelPtr struct { + HclType string + HclObjectName string + Name *string + IsolationSegments *string +} + +func hclIsolationSegments(ismp *IsolationSegmentsModelPtr) string { + if ismp != nil { + s := ` + {{.HclType}} "cloudfoundry_isolation_segments" "{{.HclObjectName}}" { + {{- if .Name}} + name = "{{.Name}}" + {{- end -}} + {{if .IsolationSegments}} + isolation_segments = {{.IsolationSegments}} + {{- end }} + }` + tmpl, err := template.New("isolation_segments").Parse(s) + if err != nil { + panic(err) + } + buf := new(bytes.Buffer) + err = tmpl.Execute(buf, ismp) + if err != nil { + panic(err) + } + return buf.String() + } + return ismp.HclType + ` cloudfoundry_isolation_segments" ` + ismp.HclObjectName + ` {}` +} + +func TestIsolationSegmentsDataSource_Configure(t *testing.T) { + var ( + // in staging + isolationSegmentName = "trial" + resourceName = "data.cloudfoundry_isolation_segments.ds" + ) + t.Parallel() + t.Run("get available datasource isolation segments", func(t *testing.T) { + cfg := getCFHomeConf() + rec := cfg.SetupVCR(t, "fixtures/datasource_isolation_segments") + defer stopQuietly(rec) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclIsolationSegments(&IsolationSegmentsModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: &isolationSegmentName, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "isolation_segments.#", "1"), + ), + }, + }, + }) + }) + t.Run("error path - get unavailable isolation segments", func(t *testing.T) { + cfg := getCFHomeConf() + rec := cfg.SetupVCR(t, "fixtures/datasource_isolation_segments_invalid") + defer stopQuietly(rec) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclIsolationSegments(&IsolationSegmentsModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: strtostrptr("testunavailable"), + }), + ExpectError: regexp.MustCompile(`Unable to find any Isolation Segment in given list`), + }, + }, + }) + }) +} diff --git a/internal/provider/fixtures/datasource_isolation_segments.yaml b/internal/provider/fixtures/datasource_isolation_segments.yaml new file mode 100644 index 0000000..5845293 --- /dev/null +++ b/internal/provider/fixtures/datasource_isolation_segments.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=a9d90095c23749238e2e6b6e90bd2047-r + form: + grant_type: + - refresh_token + refresh_token: + - a9d90095c23749238e2e6b6e90bd2047-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":"a9d90095c23749238e2e6b6e90bd2047-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"70586f3d80a64f36af02143d390d22bc"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 06 Nov 2024 10:06:52 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: + - 5799265b-ddd8-4456-61fc-11f05f418476 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 729.076458ms + - 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/isolation_segments?names=trial&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 767 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"07632c44-95c2-4ce6-92c6-a47e7cbe340b","created_at":"2019-09-27T14:01:25Z","updated_at":"2019-09-27T14:01:25Z","name":"trial","metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b"},"organizations":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b/organizations"}}}]}' + headers: + Content-Length: + - "767" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 10:06:53 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 7ae151889e6f17fc + X-B3-Traceid: + - a53c7ab436bc427f7ae151889e6f17fc + 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: + - "1730889188" + X-Runtime: + - "0.026977" + X-Vcap-Request-Id: + - a53c7ab4-36bc-427f-7ae1-51889e6f17fc::b16d9178-2a7c-4d8f-a7d7-db4fd1c3cb0d + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 786.660417ms + - 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=a9d90095c23749238e2e6b6e90bd2047-r + form: + grant_type: + - refresh_token + refresh_token: + - a9d90095c23749238e2e6b6e90bd2047-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":"a9d90095c23749238e2e6b6e90bd2047-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"8dabb1e39cef485d8733566c3ecf982a"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 06 Nov 2024 10:06:53 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: + - a8a526b6-f10f-49e2-787f-83730f760f25 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 246.543166ms + - 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/isolation_segments?names=trial&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 767 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"07632c44-95c2-4ce6-92c6-a47e7cbe340b","created_at":"2019-09-27T14:01:25Z","updated_at":"2019-09-27T14:01:25Z","name":"trial","metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b"},"organizations":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b/organizations"}}}]}' + headers: + Content-Length: + - "767" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 10:06:54 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 5c4e48977c7a9116 + X-B3-Traceid: + - 9ee35b2c8c0c474f5c4e48977c7a9116 + 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: + - "1730889188" + X-Runtime: + - "0.021155" + X-Vcap-Request-Id: + - 9ee35b2c-8c0c-474f-5c4e-48977c7a9116::258dbb21-5ed4-4ec4-88b5-a0073bb44d6a + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 275.800333ms + - 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=a9d90095c23749238e2e6b6e90bd2047-r + form: + grant_type: + - refresh_token + refresh_token: + - a9d90095c23749238e2e6b6e90bd2047-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":"a9d90095c23749238e2e6b6e90bd2047-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"58df1ec70c584c21bd7bc317910c1a9d"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 06 Nov 2024 10:06:54 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: + - 3f3ec443-9697-4cec-7fe7-755d74d70439 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 310.622166ms + - 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/isolation_segments?names=trial&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 767 + uncompressed: false + body: '{"pagination":{"total_results":1,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=trial\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"07632c44-95c2-4ce6-92c6-a47e7cbe340b","created_at":"2019-09-27T14:01:25Z","updated_at":"2019-09-27T14:01:25Z","name":"trial","metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b"},"organizations":{"href":"https://api.x.x.x.x.com/v3/isolation_segments/07632c44-95c2-4ce6-92c6-a47e7cbe340b/organizations"}}}]}' + headers: + Content-Length: + - "767" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 10:06:54 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 62f2c648680181fc + X-B3-Traceid: + - 8f59140c83d7495862f2c648680181fc + 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: + - "1730889188" + X-Runtime: + - "0.024169" + X-Vcap-Request-Id: + - 8f59140c-83d7-4958-62f2-c648680181fc::abb08e8b-4c77-447c-bc65-cff8a3f3d831 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 302.650833ms diff --git a/internal/provider/fixtures/datasource_isolation_segments_invalid.yaml b/internal/provider/fixtures/datasource_isolation_segments_invalid.yaml new file mode 100644 index 0000000..8bf74f8 --- /dev/null +++ b/internal/provider/fixtures/datasource_isolation_segments_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=a9d90095c23749238e2e6b6e90bd2047-r + form: + grant_type: + - refresh_token + refresh_token: + - a9d90095c23749238e2e6b6e90bd2047-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":"a9d90095c23749238e2e6b6e90bd2047-r","expires_in":1199,"scope":"cloud_controller.read password.write cloud_controller.write openid uaa.user","jti":"24d5b45ad74e4b2a9d71e4259dd4afe5"}' + headers: + Cache-Control: + - no-store + Content-Security-Policy: + - script-src 'self' + Content-Type: + - application/json;charset=UTF-8 + Date: + - Wed, 06 Nov 2024 10:06:54 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: + - e135d70d-3f86-412a-7982-3a3687956dfa + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 251.111333ms + - 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/isolation_segments?names=testunavailable&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 350 + uncompressed: false + body: '{"pagination":{"total_results":0,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=testunavailable\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/isolation_segments?names=testunavailable\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[]}' + headers: + Content-Length: + - "350" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 10:06:55 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 5dae051012c33b6a + X-B3-Traceid: + - fe839269260b410c5dae051012c33b6a + 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: + - "1730889188" + X-Runtime: + - "0.005870" + X-Vcap-Request-Id: + - fe839269-260b-410c-5dae-051012c33b6a::39347dcd-70cd-4cf0-9df4-a5f517deca54 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 255.705709ms diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b0fd7ea..3ac24b6 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -347,6 +347,7 @@ func (p *CloudFoundryProvider) DataSources(ctx context.Context) []func() datasou NewServiceRouteBindingsDataSource, NewServiceBrokersDataSource, NewServiceRouteBindingDataSource, + NewIsolationSegmentsDataSource, } } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index bb9f96b..9255b61 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -326,6 +326,7 @@ func TestProvider_HasDataSources(t *testing.T) { "cloudfoundry_service_route_bindings", "cloudfoundry_service_brokers", "cloudfoundry_service_route_binding", + "cloudfoundry_isolation_segments", } ctx := context.Background() diff --git a/internal/provider/types_isolation_segment.go b/internal/provider/types_isolation_segment.go index 8c9b02f..8d44e75 100644 --- a/internal/provider/types_isolation_segment.go +++ b/internal/provider/types_isolation_segment.go @@ -32,6 +32,11 @@ type IsolationSegmentEntitlementDataSourceType struct { Orgs types.Set `tfsdk:"orgs"` } +type IsolationSegmentsType struct { + Name types.String `tfsdk:"name"` + IsolationSegments []IsolationSegmentType `tfsdk:"isolation_segments"` +} + // Sets the isolation segment resource values for creation with cf-client from the terraform struct values. func (data *IsolationSegmentType) mapCreateIsolationSegmentTypeToValues(ctx context.Context) (resource.IsolationSegmentCreate, diag.Diagnostics) { @@ -94,3 +99,16 @@ func (plan *IsolationSegmentEntitlementType) mapIsolationSegmentEntitlementValue return diagnostics } + +func mapIsolationSegmentsValuesToType(ctx context.Context, isoSegs []*resource.IsolationSegment) ([]IsolationSegmentType, diag.Diagnostics) { + var diagnostics diag.Diagnostics + + isoSegsList := []IsolationSegmentType{} + for _, isoSeg := range isoSegs { + isoSegValue, diags := mapIsolationSegmentValuesToType(ctx, isoSeg) + diagnostics.Append(diags...) + isoSegsList = append(isoSegsList, isoSegValue) + } + + return isoSegsList, diagnostics +} diff --git a/internal/provider/types_org.go b/internal/provider/types_org.go index c568fbf..7aa608e 100644 --- a/internal/provider/types_org.go +++ b/internal/provider/types_org.go @@ -54,5 +54,4 @@ func mapOrgsValuesToType(ctx context.Context, orgs []*resource.Organization) ([] } return orgsList, diagnostics - } diff --git a/migration-guide/Readme.md b/migration-guide/Readme.md index 60054da..ede2d40 100644 --- a/migration-guide/Readme.md +++ b/migration-guide/Readme.md @@ -199,6 +199,7 @@ The below mentioned dataSources have been newly added in the current provider. - [Multi Target Application](../docs/data-sources/mta.md) - [Multi Target Applications](../docs/data-sources/mtas.md) - [Isolation Segment Entitlement](../docs/data-sources/isolation_segment_entitlement.md) +- [Isolation Segments](../docs/data-sources/isolation_segments.md) - [Org Role](../docs/data-sources/org_role.md) - [Org Roles](../docs/data-sources/org_roles.md) - [Organizations](../docs/data-sources/orgs.md)