Skip to content

Commit e021998

Browse files
fix(api): Update zone subscription paths
1 parent 082cf15 commit e021998

File tree

14 files changed

+772
-2
lines changed

14 files changed

+772
-2
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 1749
1+
configured_endpoints: 1752
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-b15b44e0efd207de48e7e74e742b0b4b190c74f12a941a1a0ef59a51656a5224.yml
33
openapi_spec_hash: 83243c9ee06f88d0fa91e9b185d8a42e
4-
config_hash: f3028048c6dc3559115fdd749755dee2
4+
config_hash: 8601d43fd5ccaf9e3d08f26748a5a63a
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
data "cloudflare_zone_subscription" "example_zone_subscription" {
2+
zone_id = "506e3185e9c882d175a2d0cb0093d9f2"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ terraform import cloudflare_zone_subscription.example '<zone_id>'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "cloudflare_zone_subscription" "example_zone_subscription" {
2+
zone_id = "506e3185e9c882d175a2d0cb0093d9f2"
3+
frequency = "monthly"
4+
rate_plan = {
5+
id = "free"
6+
currency = "USD"
7+
externally_managed = false
8+
is_contract = false
9+
public_name = "Business Plan"
10+
scope = "zone"
11+
sets = ["string"]
12+
}
13+
}

internal/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ import (
218218
"github.com/cloudflare/terraform-provider-cloudflare/internal/services/zone_setting"
219219
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
220220
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
221+
"github.com/cloudflare/terraform-provider-cloudflare/internal/services/zone_subscription"
221222
"github.com/hashicorp/terraform-plugin-framework/datasource"
222223
"github.com/hashicorp/terraform-plugin-framework/path"
223224
"github.com/hashicorp/terraform-plugin-framework/provider"
@@ -393,6 +394,7 @@ func (p *CloudflareProvider) Resources(ctx context.Context) []func() resource.Re
393394
zone.NewResource,
394395
zone_setting.NewResource,
395396
zone_hold.NewResource,
397+
zone_subscription.NewResource,
396398
load_balancer.NewResource,
397399
load_balancer_monitor.NewResource,
398400
load_balancer_pool.NewResource,
@@ -598,6 +600,7 @@ func (p *CloudflareProvider) DataSources(ctx context.Context) []func() datasourc
598600
zone.NewZonesDataSource,
599601
zone_setting.NewZoneSettingDataSource,
600602
zone_hold.NewZoneHoldDataSource,
603+
zone_subscription.NewZoneSubscriptionDataSource,
601604
load_balancer.NewLoadBalancerDataSource,
602605
load_balancer.NewLoadBalancersDataSource,
603606
load_balancer_monitor.NewLoadBalancerMonitorDataSource,
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package zone_subscription
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"io"
9+
"net/http"
10+
11+
"github.com/cloudflare/cloudflare-go/v4"
12+
"github.com/cloudflare/cloudflare-go/v4/option"
13+
"github.com/cloudflare/terraform-provider-cloudflare/internal/apijson"
14+
"github.com/cloudflare/terraform-provider-cloudflare/internal/logging"
15+
"github.com/hashicorp/terraform-plugin-framework/datasource"
16+
)
17+
18+
type ZoneSubscriptionDataSource struct {
19+
client *cloudflare.Client
20+
}
21+
22+
var _ datasource.DataSourceWithConfigure = (*ZoneSubscriptionDataSource)(nil)
23+
24+
func NewZoneSubscriptionDataSource() datasource.DataSource {
25+
return &ZoneSubscriptionDataSource{}
26+
}
27+
28+
func (d *ZoneSubscriptionDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
29+
resp.TypeName = req.ProviderTypeName + "_zone_subscription"
30+
}
31+
32+
func (d *ZoneSubscriptionDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
33+
if req.ProviderData == nil {
34+
return
35+
}
36+
37+
client, ok := req.ProviderData.(*cloudflare.Client)
38+
39+
if !ok {
40+
resp.Diagnostics.AddError(
41+
"unexpected resource configure type",
42+
fmt.Sprintf("Expected *cloudflare.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData),
43+
)
44+
45+
return
46+
}
47+
48+
d.client = client
49+
}
50+
51+
func (d *ZoneSubscriptionDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
52+
var data *ZoneSubscriptionDataSourceModel
53+
54+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
55+
56+
if resp.Diagnostics.HasError() {
57+
return
58+
}
59+
60+
params, diags := data.toReadParams(ctx)
61+
resp.Diagnostics.Append(diags...)
62+
if resp.Diagnostics.HasError() {
63+
return
64+
}
65+
66+
res := new(http.Response)
67+
env := ZoneSubscriptionResultDataSourceEnvelope{*data}
68+
_, err := d.client.Zones.Subscriptions.Get(
69+
ctx,
70+
params,
71+
option.WithResponseBodyInto(&res),
72+
option.WithMiddleware(logging.Middleware(ctx)),
73+
)
74+
if err != nil {
75+
resp.Diagnostics.AddError("failed to make http request", err.Error())
76+
return
77+
}
78+
bytes, _ := io.ReadAll(res.Body)
79+
err = apijson.UnmarshalComputed(bytes, &env)
80+
if err != nil {
81+
resp.Diagnostics.AddError("failed to deserialize http request", err.Error())
82+
return
83+
}
84+
data = &env.Result
85+
86+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
87+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package zone_subscription
4+
5+
import (
6+
"context"
7+
8+
"github.com/cloudflare/cloudflare-go/v4"
9+
"github.com/cloudflare/cloudflare-go/v4/zones"
10+
"github.com/cloudflare/terraform-provider-cloudflare/internal/customfield"
11+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
12+
"github.com/hashicorp/terraform-plugin-framework/diag"
13+
"github.com/hashicorp/terraform-plugin-framework/types"
14+
)
15+
16+
type ZoneSubscriptionResultDataSourceEnvelope struct {
17+
Result ZoneSubscriptionDataSourceModel `json:"result,computed"`
18+
}
19+
20+
type ZoneSubscriptionDataSourceModel struct {
21+
ZoneID types.String `tfsdk:"zone_id" path:"zone_id,required"`
22+
Currency types.String `tfsdk:"currency" json:"currency,computed"`
23+
CurrentPeriodEnd timetypes.RFC3339 `tfsdk:"current_period_end" json:"current_period_end,computed" format:"date-time"`
24+
CurrentPeriodStart timetypes.RFC3339 `tfsdk:"current_period_start" json:"current_period_start,computed" format:"date-time"`
25+
Frequency types.String `tfsdk:"frequency" json:"frequency,computed"`
26+
ID types.String `tfsdk:"id" json:"id,computed"`
27+
Price types.Float64 `tfsdk:"price" json:"price,computed"`
28+
State types.String `tfsdk:"state" json:"state,computed"`
29+
RatePlan customfield.NestedObject[ZoneSubscriptionRatePlanDataSourceModel] `tfsdk:"rate_plan" json:"rate_plan,computed"`
30+
}
31+
32+
func (m *ZoneSubscriptionDataSourceModel) toReadParams(_ context.Context) (params zones.SubscriptionGetParams, diags diag.Diagnostics) {
33+
params = zones.SubscriptionGetParams{
34+
ZoneID: cloudflare.F(m.ZoneID.ValueString()),
35+
}
36+
37+
return
38+
}
39+
40+
type ZoneSubscriptionRatePlanDataSourceModel struct {
41+
ID types.String `tfsdk:"id" json:"id,computed"`
42+
Currency types.String `tfsdk:"currency" json:"currency,computed"`
43+
ExternallyManaged types.Bool `tfsdk:"externally_managed" json:"externally_managed,computed"`
44+
IsContract types.Bool `tfsdk:"is_contract" json:"is_contract,computed"`
45+
PublicName types.String `tfsdk:"public_name" json:"public_name,computed"`
46+
Scope types.String `tfsdk:"scope" json:"scope,computed"`
47+
Sets customfield.List[types.String] `tfsdk:"sets" json:"sets,computed"`
48+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package zone_subscription
4+
5+
import (
6+
"context"
7+
8+
"github.com/cloudflare/terraform-provider-cloudflare/internal/customfield"
9+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
10+
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
11+
"github.com/hashicorp/terraform-plugin-framework/datasource"
12+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
13+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
14+
"github.com/hashicorp/terraform-plugin-framework/types"
15+
)
16+
17+
var _ datasource.DataSourceWithConfigValidators = (*ZoneSubscriptionDataSource)(nil)
18+
19+
func DataSourceSchema(ctx context.Context) schema.Schema {
20+
return schema.Schema{
21+
Attributes: map[string]schema.Attribute{
22+
"zone_id": schema.StringAttribute{
23+
Description: "Subscription identifier tag.",
24+
Required: true,
25+
},
26+
"currency": schema.StringAttribute{
27+
Description: "The monetary unit in which pricing information is displayed.",
28+
Computed: true,
29+
},
30+
"current_period_end": schema.StringAttribute{
31+
Description: "The end of the current period and also when the next billing is due.",
32+
Computed: true,
33+
CustomType: timetypes.RFC3339Type{},
34+
},
35+
"current_period_start": schema.StringAttribute{
36+
Description: "When the current billing period started. May match initial_period_start if this is the first period.",
37+
Computed: true,
38+
CustomType: timetypes.RFC3339Type{},
39+
},
40+
"frequency": schema.StringAttribute{
41+
Description: "How often the subscription is renewed automatically.\nAvailable values: \"weekly\", \"monthly\", \"quarterly\", \"yearly\".",
42+
Computed: true,
43+
Validators: []validator.String{
44+
stringvalidator.OneOfCaseInsensitive(
45+
"weekly",
46+
"monthly",
47+
"quarterly",
48+
"yearly",
49+
),
50+
},
51+
},
52+
"id": schema.StringAttribute{
53+
Description: "Subscription identifier tag.",
54+
Computed: true,
55+
},
56+
"price": schema.Float64Attribute{
57+
Description: "The price of the subscription that will be billed, in US dollars.",
58+
Computed: true,
59+
},
60+
"state": schema.StringAttribute{
61+
Description: "The state that the subscription is in.\nAvailable values: \"Trial\", \"Provisioned\", \"Paid\", \"AwaitingPayment\", \"Cancelled\", \"Failed\", \"Expired\".",
62+
Computed: true,
63+
Validators: []validator.String{
64+
stringvalidator.OneOfCaseInsensitive(
65+
"Trial",
66+
"Provisioned",
67+
"Paid",
68+
"AwaitingPayment",
69+
"Cancelled",
70+
"Failed",
71+
"Expired",
72+
),
73+
},
74+
},
75+
"rate_plan": schema.SingleNestedAttribute{
76+
Description: "The rate plan applied to the subscription.",
77+
Computed: true,
78+
CustomType: customfield.NewNestedObjectType[ZoneSubscriptionRatePlanDataSourceModel](ctx),
79+
Attributes: map[string]schema.Attribute{
80+
"id": schema.StringAttribute{
81+
Description: "The ID of the rate plan.\nAvailable values: \"free\", \"lite\", \"pro\", \"pro_plus\", \"business\", \"enterprise\", \"partners_free\", \"partners_pro\", \"partners_business\", \"partners_enterprise\".",
82+
Computed: true,
83+
Validators: []validator.String{
84+
stringvalidator.OneOfCaseInsensitive(
85+
"free",
86+
"lite",
87+
"pro",
88+
"pro_plus",
89+
"business",
90+
"enterprise",
91+
"partners_free",
92+
"partners_pro",
93+
"partners_business",
94+
"partners_enterprise",
95+
),
96+
},
97+
},
98+
"currency": schema.StringAttribute{
99+
Description: "The currency applied to the rate plan subscription.",
100+
Computed: true,
101+
},
102+
"externally_managed": schema.BoolAttribute{
103+
Description: "Whether this rate plan is managed externally from Cloudflare.",
104+
Computed: true,
105+
},
106+
"is_contract": schema.BoolAttribute{
107+
Description: "Whether a rate plan is enterprise-based (or newly adopted term contract).",
108+
Computed: true,
109+
},
110+
"public_name": schema.StringAttribute{
111+
Description: "The full name of the rate plan.",
112+
Computed: true,
113+
},
114+
"scope": schema.StringAttribute{
115+
Description: "The scope that this rate plan applies to.",
116+
Computed: true,
117+
},
118+
"sets": schema.ListAttribute{
119+
Description: "The list of sets this rate plan applies to.",
120+
Computed: true,
121+
CustomType: customfield.NewListType[types.String](ctx),
122+
ElementType: types.StringType,
123+
},
124+
},
125+
},
126+
},
127+
}
128+
}
129+
130+
func (d *ZoneSubscriptionDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
131+
resp.Schema = DataSourceSchema(ctx)
132+
}
133+
134+
func (d *ZoneSubscriptionDataSource) ConfigValidators(_ context.Context) []datasource.ConfigValidator {
135+
return []datasource.ConfigValidator{}
136+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package zone_subscription_test
4+
5+
import (
6+
"context"
7+
"testing"
8+
9+
"github.com/cloudflare/terraform-provider-cloudflare/internal/services/zone_subscription"
10+
"github.com/cloudflare/terraform-provider-cloudflare/internal/test_helpers"
11+
)
12+
13+
func TestZoneSubscriptionDataSourceModelSchemaParity(t *testing.T) {
14+
t.Parallel()
15+
model := (*zone_subscription.ZoneSubscriptionDataSourceModel)(nil)
16+
schema := zone_subscription.DataSourceSchema(context.TODO())
17+
errs := test_helpers.ValidateDataSourceModelSchemaIntegrity(model, schema)
18+
errs.Report(t)
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
package zone_subscription
4+
5+
import (
6+
"context"
7+
8+
"github.com/hashicorp/terraform-plugin-framework/resource"
9+
)
10+
11+
var _ resource.ResourceWithUpgradeState = (*ZoneSubscriptionResource)(nil)
12+
13+
func (r *ZoneSubscriptionResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
14+
return map[int64]resource.StateUpgrader{}
15+
}

0 commit comments

Comments
 (0)