diff --git a/docs/data-sources/buildpacks.md b/docs/data-sources/buildpacks.md new file mode 100644 index 0000000..c6eea25 --- /dev/null +++ b/docs/data-sources/buildpacks.md @@ -0,0 +1,58 @@ +--- +page_title: "cloudfoundry_buildpacks Data Source - terraform-provider-cloudfoundry" +subcategory: "" +description: |- + Gets information of Cloud Foundry buildpacks present. +--- + +# cloudfoundry_buildpacks (Data Source) + +Gets information of Cloud Foundry buildpacks present. + +## Example Usage + +```terraform +data "cloudfoundry_buildpacks" "buildpack" { + name = "java_buildpack" +} + +output "buildpack" { + value = data.cloudfoundry_buildpacks.buildpack +} +``` + + +## Schema + +### Optional + +- `name` (String) Name of the buildpack to filter by +- `stack` (String) The name of the stack to filter by + +### Read-Only + +- `buildpacks` (Attributes List) The list of buildpacks (see [below for nested schema](#nestedatt--buildpacks)) + + +### Nested Schema for `buildpacks` + +Required: + +- `name` (String) Name of the buildpack + +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). +- `enabled` (Boolean) Whether or not the buildpack can be used for staging +- `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). +- `locked` (Boolean) Whether or not the buildpack is locked to prevent updating the bits +- `position` (Number) The order in which the buildpacks are checked during buildpack auto-detection +- `stack` (String) The name of the stack that the buildpack will use + +Read-Only: + +- `created_at` (String) The date and time when the resource was created in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) format. +- `filename` (String) The filename of the buildpack +- `id` (String) The GUID of the object. +- `state` (String) The state of the buildpack +- `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_buildpacks/data-source.tf b/examples/data-sources/cloudfoundry_buildpacks/data-source.tf new file mode 100644 index 0000000..98b9ddb --- /dev/null +++ b/examples/data-sources/cloudfoundry_buildpacks/data-source.tf @@ -0,0 +1,7 @@ +data "cloudfoundry_buildpacks" "buildpack" { + name = "java_buildpack" +} + +output "buildpack" { + value = data.cloudfoundry_buildpacks.buildpack +} \ No newline at end of file diff --git a/internal/provider/datasource_buildpacks.go b/internal/provider/datasource_buildpacks.go new file mode 100644 index 0000000..f4a2d6f --- /dev/null +++ b/internal/provider/datasource_buildpacks.go @@ -0,0 +1,154 @@ +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" +) + +var _ datasource.DataSource = &buildpacksDataSource{} +var _ datasource.DataSourceWithConfigure = &buildpacksDataSource{} + +func NewBuildpacksDataSource() datasource.DataSource { + return &buildpacksDataSource{} +} + +type buildpacksDataSource struct { + cfClient *cfv3client.Client +} + +func (d *buildpacksDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = req.ProviderTypeName + "_buildpacks" +} + +func (d *buildpacksDataSource) 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 *buildpacksDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + MarkdownDescription: "Gets information of Cloud Foundry buildpacks present.", + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + MarkdownDescription: "Name of the buildpack to filter by", + Optional: true, + }, + "stack": schema.StringAttribute{ + MarkdownDescription: "The name of the stack to filter by", + Optional: true, + }, + "buildpacks": schema.ListNestedAttribute{ + MarkdownDescription: "The list of buildpacks", + Computed: true, + NestedObject: schema.NestedAttributeObject{ + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + MarkdownDescription: "Name of the buildpack", + Required: true, + }, + "stack": schema.StringAttribute{ + MarkdownDescription: "The name of the stack that the buildpack will use", + Optional: true, + }, + "position": schema.Int64Attribute{ + MarkdownDescription: "The order in which the buildpacks are checked during buildpack auto-detection", + Optional: true, + Computed: true, + }, + "enabled": schema.BoolAttribute{ + MarkdownDescription: "Whether or not the buildpack can be used for staging", + Optional: true, + Computed: true, + }, + "locked": schema.BoolAttribute{ + MarkdownDescription: "Whether or not the buildpack is locked to prevent updating the bits", + Optional: true, + Computed: true, + }, + "state": schema.StringAttribute{ + MarkdownDescription: "The state of the buildpack", + Computed: true, + }, + "filename": schema.StringAttribute{ + MarkdownDescription: "The filename of the buildpack", + Computed: true, + }, + labelsKey: resourceLabelsSchema(), + annotationsKey: resourceAnnotationsSchema(), + createdAtKey: createdAtSchema(), + updatedAtKey: updatedAtSchema(), + idKey: guidSchema(), + }, + }, + }, + }, + } +} + +func (d *buildpacksDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { + + var data datasourceBuildpacksType + + diags := req.Config.Get(ctx, &data) + resp.Diagnostics.Append(diags...) + if resp.Diagnostics.HasError() { + return + } + + blo := cfv3client.NewBuildpackListOptions() + + if !data.Name.IsNull() { + blo.Names = cfv3client.Filter{ + Values: []string{ + data.Name.ValueString(), + }, + } + } + if !data.Stack.IsNull() { + blo.Stacks = cfv3client.Filter{ + Values: []string{ + data.Stack.ValueString(), + }, + } + } + + buildpacks, err := d.cfClient.Buildpacks.ListAll(ctx, blo) + if err != nil { + resp.Diagnostics.AddError( + "API Error Fetching Buildpacks", + "Response failed with %s"+err.Error(), + ) + return + } + + if len(buildpacks) == 0 { + resp.Diagnostics.AddError( + "Unable to find any buildpack in the list", + "No buildpack present with mentioned criteria", + ) + return + } + + data.Buildpacks, diags = mapBuildpacksValuesToType(ctx, buildpacks) + resp.Diagnostics.Append(diags...) + + tflog.Trace(ctx, "read the buildpacks data source") + resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) +} diff --git a/internal/provider/datasource_buildpacks_test.go b/internal/provider/datasource_buildpacks_test.go new file mode 100644 index 0000000..72f645f --- /dev/null +++ b/internal/provider/datasource_buildpacks_test.go @@ -0,0 +1,105 @@ +package provider + +import ( + "bytes" + "regexp" + "testing" + "text/template" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +type BuildpacksModelPtr struct { + HclType string + HclObjectName string + Name *string + Stack *string + Buildpacks *string +} + +func hclBuildpacks(ddsmp *BuildpacksModelPtr) string { + if ddsmp != nil { + s := ` + {{.HclType}} "cloudfoundry_buildpacks" "{{.HclObjectName}}" { + {{- if .Name}} + name = "{{.Name}}" + {{- end -}} + {{if .Stack}} + stack = "{{.Stack}}" + {{- end }} + {{if .Buildpacks}} + buildpacks = {{.Buildpacks}} + {{- end }} + }` + tmpl, err := template.New("buildpacks").Parse(s) + if err != nil { + panic(err) + } + buf := new(bytes.Buffer) + err = tmpl.Execute(buf, ddsmp) + if err != nil { + panic(err) + } + return buf.String() + } + return ddsmp.HclType + ` cloudfoundry_Buildpacks" ` + ddsmp.HclObjectName + ` {}` +} +func TestBuildpacksDataSource_Configure(t *testing.T) { + resourceName := "data.cloudfoundry_buildpacks.ds" + buildpackName := "java_buildpack" + stackName := "cflinuxfs4" + t.Parallel() + t.Run("error path - get buildpacks", func(t *testing.T) { + cfg := getCFHomeConf() + rec := cfg.SetupVCR(t, "fixtures/datasource_buildpacks_invalid") + defer stopQuietly(rec) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclBuildpacks(&BuildpacksModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: &invalidOrgGUID, + }), + ExpectError: regexp.MustCompile(`Unable to find any buildpack in the list`), + }, + }, + }) + }) + t.Run("happy path - get buildpacks", func(t *testing.T) { + cfg := getCFHomeConf() + + rec := cfg.SetupVCR(t, "fixtures/datasource_buildpacks") + defer stopQuietly(rec) + + resource.Test(t, resource.TestCase{ + IsUnitTest: true, + ProtoV6ProviderFactories: getProviders(rec.GetDefaultClient()), + Steps: []resource.TestStep{ + { + Config: hclProvider(nil) + hclBuildpacks(&BuildpacksModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Name: &buildpackName, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "buildpacks.#", "2"), + ), + }, + { + Config: hclProvider(nil) + hclBuildpacks(&BuildpacksModelPtr{ + HclType: hclObjectDataSource, + HclObjectName: "ds", + Stack: &stackName, + }), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(resourceName, "buildpacks.#", "8"), + ), + }, + }, + }) + }) +} diff --git a/internal/provider/datasource_domains.go b/internal/provider/datasource_domains.go index c941126..75f8c18 100644 --- a/internal/provider/datasource_domains.go +++ b/internal/provider/datasource_domains.go @@ -141,7 +141,7 @@ func (d *DomainsDataSource) Read(ctx context.Context, req datasource.ReadRequest if err != nil { resp.Diagnostics.AddError( "API Error Fetching Domains", - "Could not get domains for organization "+data.Org.ValueString()+" : "+err.Error(), + "Could not get domains : "+err.Error(), ) return } @@ -149,7 +149,7 @@ func (d *DomainsDataSource) Read(ctx context.Context, req datasource.ReadRequest if len(domains) == 0 { resp.Diagnostics.AddError( "Unable to find any domain in the list", - fmt.Sprintf("No domain present under org %s with mentioned criteria", data.Org.ValueString()), + "No domain present with mentioned criteria", ) return } diff --git a/internal/provider/fixtures/datasource_buildpacks.yaml b/internal/provider/fixtures/datasource_buildpacks.yaml new file mode 100644 index 0000000..f7b1992 --- /dev/null +++ b/internal/provider/fixtures/datasource_buildpacks.yaml @@ -0,0 +1,405 @@ +--- +version: 2 +interactions: + - id: 0 + 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/buildpacks?names=java_buildpack&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1472 + uncompressed: false + body: '{"pagination":{"total_results":2,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"a7b75648-ba6e-41c5-b87b-9134beefe8c6","created_at":"2018-12-11T21:17:59Z","updated_at":"2023-05-25T19:26:44Z","name":"java_buildpack","stack":"cflinuxfs3","state":"READY","filename":"java_buildpack-cached-cflinuxfs3-v4.58.zip","position":10,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "1472" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:14 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 56dadf460db3e801 + X-B3-Traceid: + - 7324ec2770ca46da56dadf460db3e801 + 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: + - "1730883788" + X-Runtime: + - "0.008379" + X-Vcap-Request-Id: + - 7324ec27-70ca-46da-56da-df460db3e801::6091aaf1-3f38-428b-9dc4-bdb4167a6ae1 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 244.564875ms + - 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/buildpacks?names=java_buildpack&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1472 + uncompressed: false + body: '{"pagination":{"total_results":2,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"a7b75648-ba6e-41c5-b87b-9134beefe8c6","created_at":"2018-12-11T21:17:59Z","updated_at":"2023-05-25T19:26:44Z","name":"java_buildpack","stack":"cflinuxfs3","state":"READY","filename":"java_buildpack-cached-cflinuxfs3-v4.58.zip","position":10,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "1472" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:14 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 463079cc20096f47 + X-B3-Traceid: + - fd53a996c0824560463079cc20096f47 + 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: + - "1730883788" + X-Runtime: + - "0.008019" + X-Vcap-Request-Id: + - fd53a996-c082-4560-4630-79cc20096f47::634e94ce-5d83-460f-b701-152a26fd0195 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 241.234917ms + - id: 2 + 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/buildpacks?names=java_buildpack&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 1472 + uncompressed: false + body: '{"pagination":{"total_results":2,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=java_buildpack\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"a7b75648-ba6e-41c5-b87b-9134beefe8c6","created_at":"2018-12-11T21:17:59Z","updated_at":"2023-05-25T19:26:44Z","name":"java_buildpack","stack":"cflinuxfs3","state":"READY","filename":"java_buildpack-cached-cflinuxfs3-v4.58.zip","position":10,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/a7b75648-ba6e-41c5-b87b-9134beefe8c6/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "1472" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:14 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 7f619f3128518633 + X-B3-Traceid: + - 2820668fc1c449967f619f3128518633 + 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: + - "1730883788" + X-Runtime: + - "0.006547" + X-Vcap-Request-Id: + - 2820668f-c1c4-4996-7f61-9f3128518633::73397d20-0e46-40c4-998e-c9c2f3cccae8 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 246.107166ms + - 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/buildpacks?page=1&per_page=50&stacks=cflinuxfs4 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 4915 + uncompressed: false + body: '{"pagination":{"total_results":8,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"next":null,"previous":null},"resources":[{"guid":"89ec5bd7-9f3a-4cbb-8f78-01074a56acf0","created_at":"2023-03-16T01:11:39Z","updated_at":"2024-10-09T10:14:15Z","name":"staticfile_buildpack","stack":"cflinuxfs4","state":"READY","filename":"staticfile_buildpack-cached-cflinuxfs4-v1.6.17.zip","position":1,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0/upload","method":"POST"}}},{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"198a5fba-bbf1-4467-91a9-b98b36de81ca","created_at":"2022-12-22T01:51:44Z","updated_at":"2024-10-09T10:14:30Z","name":"nodejs_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nodejs_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":5,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca/upload","method":"POST"}}},{"guid":"c82da378-285d-4f3c-a80b-c6a63db36315","created_at":"2023-01-19T18:31:16Z","updated_at":"2024-10-09T10:14:41Z","name":"go_buildpack","stack":"cflinuxfs4","state":"READY","filename":"go_buildpack-cached-cflinuxfs4-v1.10.23.zip","position":6,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315/upload","method":"POST"}}},{"guid":"8cdd0491-8e80-45b2-b1da-56db51349c56","created_at":"2022-12-22T01:50:51Z","updated_at":"2024-10-09T10:14:59Z","name":"python_buildpack","stack":"cflinuxfs4","state":"READY","filename":"python_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":7,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56/upload","method":"POST"}}},{"guid":"66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7","created_at":"2023-03-31T20:58:01Z","updated_at":"2024-09-26T02:44:19Z","name":"php_buildpack","stack":"cflinuxfs4","state":"READY","filename":"php_buildpack-cached-cflinuxfs4-v4.6.23.zip","position":8,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7/upload","method":"POST"}}},{"guid":"7ad12dbf-21bf-4a39-97bb-7d34e378efa9","created_at":"2023-03-16T01:12:49Z","updated_at":"2024-10-09T10:15:03Z","name":"nginx_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nginx_buildpack-cached-cflinuxfs4-v1.2.19.zip","position":9,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9/upload","method":"POST"}}},{"guid":"8a5a46a4-3f5d-4133-a18f-458e1ab158a1","created_at":"2023-01-19T18:32:21Z","updated_at":"2024-10-09T10:15:07Z","name":"binary_buildpack","stack":"cflinuxfs4","state":"READY","filename":"binary_buildpack-cached-cflinuxfs4-v1.1.14.zip","position":11,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "4915" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:15 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 74f2a46485f79b91 + X-B3-Traceid: + - 6c5b5cac604e4fc174f2a46485f79b91 + 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: + - "1730883788" + X-Runtime: + - "0.009746" + X-Vcap-Request-Id: + - 6c5b5cac-604e-4fc1-74f2-a46485f79b91::f15852b0-b13f-4a55-9464-ef83a8af725d + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 245.682375ms + - id: 4 + 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/buildpacks?page=1&per_page=50&stacks=cflinuxfs4 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 4915 + uncompressed: false + body: '{"pagination":{"total_results":8,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"next":null,"previous":null},"resources":[{"guid":"89ec5bd7-9f3a-4cbb-8f78-01074a56acf0","created_at":"2023-03-16T01:11:39Z","updated_at":"2024-10-09T10:14:15Z","name":"staticfile_buildpack","stack":"cflinuxfs4","state":"READY","filename":"staticfile_buildpack-cached-cflinuxfs4-v1.6.17.zip","position":1,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0/upload","method":"POST"}}},{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"198a5fba-bbf1-4467-91a9-b98b36de81ca","created_at":"2022-12-22T01:51:44Z","updated_at":"2024-10-09T10:14:30Z","name":"nodejs_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nodejs_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":5,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca/upload","method":"POST"}}},{"guid":"c82da378-285d-4f3c-a80b-c6a63db36315","created_at":"2023-01-19T18:31:16Z","updated_at":"2024-10-09T10:14:41Z","name":"go_buildpack","stack":"cflinuxfs4","state":"READY","filename":"go_buildpack-cached-cflinuxfs4-v1.10.23.zip","position":6,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315/upload","method":"POST"}}},{"guid":"8cdd0491-8e80-45b2-b1da-56db51349c56","created_at":"2022-12-22T01:50:51Z","updated_at":"2024-10-09T10:14:59Z","name":"python_buildpack","stack":"cflinuxfs4","state":"READY","filename":"python_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":7,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56/upload","method":"POST"}}},{"guid":"66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7","created_at":"2023-03-31T20:58:01Z","updated_at":"2024-09-26T02:44:19Z","name":"php_buildpack","stack":"cflinuxfs4","state":"READY","filename":"php_buildpack-cached-cflinuxfs4-v4.6.23.zip","position":8,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7/upload","method":"POST"}}},{"guid":"7ad12dbf-21bf-4a39-97bb-7d34e378efa9","created_at":"2023-03-16T01:12:49Z","updated_at":"2024-10-09T10:15:03Z","name":"nginx_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nginx_buildpack-cached-cflinuxfs4-v1.2.19.zip","position":9,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9/upload","method":"POST"}}},{"guid":"8a5a46a4-3f5d-4133-a18f-458e1ab158a1","created_at":"2023-01-19T18:32:21Z","updated_at":"2024-10-09T10:15:07Z","name":"binary_buildpack","stack":"cflinuxfs4","state":"READY","filename":"binary_buildpack-cached-cflinuxfs4-v1.1.14.zip","position":11,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "4915" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:15 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 578fdb4d32360727 + X-B3-Traceid: + - 52939ec1abc048d7578fdb4d32360727 + 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: + - "1730883788" + X-Runtime: + - "0.014068" + X-Vcap-Request-Id: + - 52939ec1-abc0-48d7-578f-db4d32360727::8a772434-5ef2-4772-b617-f1dd65b791a3 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 251.831291ms + - 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/buildpacks?page=1&per_page=50&stacks=cflinuxfs4 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 4915 + uncompressed: false + body: '{"pagination":{"total_results":8,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?page=1\u0026per_page=50\u0026stacks=cflinuxfs4"},"next":null,"previous":null},"resources":[{"guid":"89ec5bd7-9f3a-4cbb-8f78-01074a56acf0","created_at":"2023-03-16T01:11:39Z","updated_at":"2024-10-09T10:14:15Z","name":"staticfile_buildpack","stack":"cflinuxfs4","state":"READY","filename":"staticfile_buildpack-cached-cflinuxfs4-v1.6.17.zip","position":1,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/89ec5bd7-9f3a-4cbb-8f78-01074a56acf0/upload","method":"POST"}}},{"guid":"45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9","created_at":"2023-03-02T04:06:04Z","updated_at":"2024-08-28T13:02:25Z","name":"java_buildpack","stack":"cflinuxfs4","state":"READY","filename":"java_buildpack-cached-cflinuxfs4-v4.71.0.zip","position":2,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/45a5e8b9-f9a1-4bc0-8ea8-4467ef0d14c9/upload","method":"POST"}}},{"guid":"198a5fba-bbf1-4467-91a9-b98b36de81ca","created_at":"2022-12-22T01:51:44Z","updated_at":"2024-10-09T10:14:30Z","name":"nodejs_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nodejs_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":5,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/198a5fba-bbf1-4467-91a9-b98b36de81ca/upload","method":"POST"}}},{"guid":"c82da378-285d-4f3c-a80b-c6a63db36315","created_at":"2023-01-19T18:31:16Z","updated_at":"2024-10-09T10:14:41Z","name":"go_buildpack","stack":"cflinuxfs4","state":"READY","filename":"go_buildpack-cached-cflinuxfs4-v1.10.23.zip","position":6,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/c82da378-285d-4f3c-a80b-c6a63db36315/upload","method":"POST"}}},{"guid":"8cdd0491-8e80-45b2-b1da-56db51349c56","created_at":"2022-12-22T01:50:51Z","updated_at":"2024-10-09T10:14:59Z","name":"python_buildpack","stack":"cflinuxfs4","state":"READY","filename":"python_buildpack-cached-cflinuxfs4-v1.8.29.zip","position":7,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8cdd0491-8e80-45b2-b1da-56db51349c56/upload","method":"POST"}}},{"guid":"66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7","created_at":"2023-03-31T20:58:01Z","updated_at":"2024-09-26T02:44:19Z","name":"php_buildpack","stack":"cflinuxfs4","state":"READY","filename":"php_buildpack-cached-cflinuxfs4-v4.6.23.zip","position":8,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/66c3c1a4-ae6b-48b9-86b5-d7e8c071b8f7/upload","method":"POST"}}},{"guid":"7ad12dbf-21bf-4a39-97bb-7d34e378efa9","created_at":"2023-03-16T01:12:49Z","updated_at":"2024-10-09T10:15:03Z","name":"nginx_buildpack","stack":"cflinuxfs4","state":"READY","filename":"nginx_buildpack-cached-cflinuxfs4-v1.2.19.zip","position":9,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/7ad12dbf-21bf-4a39-97bb-7d34e378efa9/upload","method":"POST"}}},{"guid":"8a5a46a4-3f5d-4133-a18f-458e1ab158a1","created_at":"2023-01-19T18:32:21Z","updated_at":"2024-10-09T10:15:07Z","name":"binary_buildpack","stack":"cflinuxfs4","state":"READY","filename":"binary_buildpack-cached-cflinuxfs4-v1.1.14.zip","position":11,"enabled":true,"locked":false,"metadata":{"labels":{},"annotations":{}},"links":{"self":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1"},"upload":{"href":"https://api.x.x.x.x.com/v3/buildpacks/8a5a46a4-3f5d-4133-a18f-458e1ab158a1/upload","method":"POST"}}}]}' + headers: + Content-Length: + - "4915" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:15 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 59f5c4695f5f60d5 + X-B3-Traceid: + - 53c733471a6b484c59f5c4695f5f60d5 + 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: + - "1730883788" + X-Runtime: + - "0.014530" + X-Vcap-Request-Id: + - 53c73347-1a6b-484c-59f5-c4695f5f60d5::fe219149-f30c-4e54-b104-86f05760ce2c + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 258.964667ms diff --git a/internal/provider/fixtures/datasource_buildpacks_invalid.yaml b/internal/provider/fixtures/datasource_buildpacks_invalid.yaml new file mode 100644 index 0000000..82c21f1 --- /dev/null +++ b/internal/provider/fixtures/datasource_buildpacks_invalid.yaml @@ -0,0 +1,70 @@ +--- +version: 2 +interactions: + - id: 0 + 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/buildpacks?names=40b73419-5e01-4be0-baea-932d46cea45b&page=1&per_page=50 + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 376 + uncompressed: false + body: '{"pagination":{"total_results":0,"total_pages":1,"first":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=40b73419-5e01-4be0-baea-932d46cea45b\u0026page=1\u0026per_page=50"},"last":{"href":"https://api.x.x.x.x.com/v3/buildpacks?names=40b73419-5e01-4be0-baea-932d46cea45b\u0026page=1\u0026per_page=50"},"next":null,"previous":null},"resources":[]}' + headers: + Content-Length: + - "376" + Content-Type: + - application/json; charset=utf-8 + Date: + - Wed, 06 Nov 2024 08:39:13 GMT + Referrer-Policy: + - strict-origin-when-cross-origin + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload; + X-B3-Spanid: + - 5c2b3c314dea206b + X-B3-Traceid: + - c4dd3e0dc58944545c2b3c314dea206b + 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: + - "1730883788" + X-Runtime: + - "0.004359" + X-Vcap-Request-Id: + - c4dd3e0d-c589-4454-5c2b-3c314dea206b::351fe609-9dcf-4d21-b47f-18365902dc90 + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: 744.018625ms diff --git a/internal/provider/provider.go b/internal/provider/provider.go index b0fd7ea..c3e4e88 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, + NewBuildpacksDataSource, } } diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index bb9f96b..1467049 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", + "cloufoundry_buildpacks", } ctx := context.Background() diff --git a/internal/provider/types_buildpack.go b/internal/provider/types_buildpack.go index 85d3f44..2c62795 100644 --- a/internal/provider/types_buildpack.go +++ b/internal/provider/types_buildpack.go @@ -26,6 +26,33 @@ type buildpackType struct { SourceCodeHash types.String `tfsdk:"source_code_hash"` } +type datasourceBuildpackType struct { + Name types.String `tfsdk:"name"` + Id types.String `tfsdk:"id"` + State types.String `tfsdk:"state"` + Stack types.String `tfsdk:"stack"` + Filename types.String `tfsdk:"filename"` + Position types.Int64 `tfsdk:"position"` + Enabled types.Bool `tfsdk:"enabled"` + Locked types.Bool `tfsdk:"locked"` + Labels types.Map `tfsdk:"labels"` + Annotations types.Map `tfsdk:"annotations"` + CreatedAt types.String `tfsdk:"created_at"` + UpdatedAt types.String `tfsdk:"updated_at"` +} + +type datasourceBuildpacksType struct { + Name types.String `tfsdk:"name"` + Stack types.String `tfsdk:"stack"` + Buildpacks []datasourceBuildpackType `tfsdk:"buildpacks"` +} + +func (a *buildpackType) Reduce() datasourceBuildpackType { + var reduced datasourceBuildpackType + copyFields(&reduced, a) + return reduced +} + // Sets the terraform struct values from the buildpack resource returned by the cf-client. func mapBuildpackValuesToType(ctx context.Context, buildpack *resource.Buildpack) (buildpackType, diag.Diagnostics) { @@ -55,6 +82,19 @@ func mapBuildpackValuesToType(ctx context.Context, buildpack *resource.Buildpack return buildpackType, diagnostics } +func mapBuildpacksValuesToType(ctx context.Context, buildpacks []*resource.Buildpack) ([]datasourceBuildpackType, diag.Diagnostics) { + + var diagnostics diag.Diagnostics + buildpackList := []datasourceBuildpackType{} + for _, buildpack := range buildpacks { + buildpackValue, diags := mapBuildpackValuesToType(ctx, buildpack) + diagnostics.Append(diags...) + buildpackList = append(buildpackList, buildpackValue.Reduce()) + } + + return buildpackList, diagnostics +} + // Sets the buildpack resource values for creation with cf-client from the terraform struct values. func (data *buildpackType) mapCreateBuildpackTypeToValues(ctx context.Context) (resource.BuildpackCreateOrUpdate, diag.Diagnostics) { diff --git a/migration-guide/Readme.md b/migration-guide/Readme.md index 60054da..8c88aae 100644 --- a/migration-guide/Readme.md +++ b/migration-guide/Readme.md @@ -195,6 +195,7 @@ Few resources required a major change in functionality or the way the resources The below mentioned dataSources have been newly added in the current provider. - [Applications](../docs/data-sources/apps.md) +- [Buildpacks](../docs/data-sources/buildpacks.md) - [Domains](../docs/data-sources/domains.md) - [Multi Target Application](../docs/data-sources/mta.md) - [Multi Target Applications](../docs/data-sources/mtas.md)