Skip to content

Commit 586b405

Browse files
committed
Revert "dns managed zone with plugin-framework (#7182) (#5176)"
This reverts commit e1bf221.
1 parent cf929e9 commit 586b405

File tree

5 files changed

+73
-169
lines changed

5 files changed

+73
-169
lines changed

.changelog/7182.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 61 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,170 +1,101 @@
11
package google
22

33
import (
4-
"context"
54
"fmt"
65

7-
"google.golang.org/api/dns/v1"
8-
9-
"github.com/hashicorp/terraform-plugin-framework/datasource"
10-
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
11-
"github.com/hashicorp/terraform-plugin-framework/diag"
12-
"github.com/hashicorp/terraform-plugin-framework/types"
13-
"github.com/hashicorp/terraform-plugin-log/tflog"
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
147
)
158

16-
var _ datasource.DataSource = &GoogleDnsManagedZoneDataSource{}
17-
18-
func NewGoogleDnsManagedZoneDataSource() datasource.DataSource {
19-
return &GoogleDnsManagedZoneDataSource{}
20-
}
21-
22-
// GoogleDnsManagedZoneDataSource defines the data source implementation
23-
type GoogleDnsManagedZoneDataSource struct {
24-
client *dns.Service
25-
project types.String
26-
}
27-
28-
type GoogleDnsManagedZoneModel struct {
29-
Id types.String `tfsdk:"id"`
30-
DnsName types.String `tfsdk:"dns_name"`
31-
Name types.String `tfsdk:"name"`
32-
Description types.String `tfsdk:"description"`
33-
ManagedZoneId types.Int64 `tfsdk:"managed_zone_id"`
34-
NameServers types.List `tfsdk:"name_servers"`
35-
Visibility types.String `tfsdk:"visibility"`
36-
Project types.String `tfsdk:"project"`
37-
}
9+
func dataSourceDnsManagedZone() *schema.Resource {
10+
return &schema.Resource{
11+
Read: dataSourceDnsManagedZoneRead,
3812

39-
func (d *GoogleDnsManagedZoneDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
40-
resp.TypeName = req.ProviderTypeName + "_dns_managed_zone"
41-
}
42-
43-
func (d *GoogleDnsManagedZoneDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
44-
resp.Schema = schema.Schema{
45-
// This description is used by the documentation generator and the language server.
46-
MarkdownDescription: "Provides access to a zone's attributes within Google Cloud DNS",
47-
48-
Attributes: map[string]schema.Attribute{
49-
"dns_name": schema.StringAttribute{
50-
Description: "The fully qualified DNS name of this zone.",
51-
MarkdownDescription: "The fully qualified DNS name of this zone.",
52-
Computed: true,
13+
Schema: map[string]*schema.Schema{
14+
"dns_name": {
15+
Type: schema.TypeString,
16+
Computed: true,
5317
},
5418

55-
"name": schema.StringAttribute{
56-
Description: "A unique name for the resource.",
57-
MarkdownDescription: "A unique name for the resource.",
58-
Required: true,
19+
"name": {
20+
Type: schema.TypeString,
21+
Required: true,
5922
},
6023

61-
"description": schema.StringAttribute{
62-
Description: "A textual description field.",
63-
MarkdownDescription: "A textual description field.",
64-
Computed: true,
24+
"description": {
25+
Type: schema.TypeString,
26+
Computed: true,
6527
},
6628

67-
"managed_zone_id": schema.Int64Attribute{
68-
Description: "Unique identifier for the resource; defined by the server.",
69-
MarkdownDescription: "Unique identifier for the resource; defined by the server.",
70-
Computed: true,
29+
"managed_zone_id": {
30+
Type: schema.TypeInt,
31+
Computed: true,
32+
Description: `Unique identifier for the resource; defined by the server.`,
7133
},
7234

73-
"name_servers": schema.ListAttribute{
74-
Description: "The list of nameservers that will be authoritative for this " +
75-
"domain. Use NS records to redirect from your DNS provider to these names, " +
76-
"thus making Google Cloud DNS authoritative for this zone.",
77-
MarkdownDescription: "The list of nameservers that will be authoritative for this " +
78-
"domain. Use NS records to redirect from your DNS provider to these names, " +
79-
"thus making Google Cloud DNS authoritative for this zone.",
80-
Computed: true,
81-
ElementType: types.StringType,
35+
"name_servers": {
36+
Type: schema.TypeList,
37+
Computed: true,
38+
Elem: &schema.Schema{
39+
Type: schema.TypeString,
40+
},
8241
},
8342

84-
"visibility": schema.StringAttribute{
85-
Description: "The zone's visibility: public zones are exposed to the Internet, " +
86-
"while private zones are visible only to Virtual Private Cloud resources.",
87-
MarkdownDescription: "The zone's visibility: public zones are exposed to the Internet, " +
88-
"while private zones are visible only to Virtual Private Cloud resources.",
43+
"visibility": {
44+
Type: schema.TypeString,
8945
Computed: true,
9046
},
9147

9248
// Google Cloud DNS ManagedZone resources do not have a SelfLink attribute.
93-
"project": schema.StringAttribute{
94-
Description: "The ID of the project for the Google Cloud.",
95-
MarkdownDescription: "The ID of the project for the Google Cloud.",
96-
Optional: true,
97-
},
98-
"id": schema.StringAttribute{
99-
Description: "DNS managed zone identifier",
100-
MarkdownDescription: "DNS managed zone identifier",
101-
Computed: true,
49+
"project": {
50+
Type: schema.TypeString,
51+
Optional: true,
10252
},
10353
},
10454
}
10555
}
10656

107-
func (d *GoogleDnsManagedZoneDataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
108-
// Prevent panic if the provider has not been configured.
109-
if req.ProviderData == nil {
110-
return
57+
func dataSourceDnsManagedZoneRead(d *schema.ResourceData, meta interface{}) error {
58+
config := meta.(*Config)
59+
userAgent, err := generateUserAgentString(d, config.userAgent)
60+
if err != nil {
61+
return err
11162
}
11263

113-
p, ok := req.ProviderData.(*frameworkProvider)
114-
if !ok {
115-
resp.Diagnostics.AddError(
116-
"Unexpected Data Source Configure Type",
117-
fmt.Sprintf("Expected *frameworkProvider, got: %T. Please report this issue to the provider developers.", req.ProviderData),
118-
)
119-
return
64+
project, err := getProject(d, config)
65+
if err != nil {
66+
return err
12067
}
12168

122-
d.client = p.NewDnsClient(p.userAgent, &resp.Diagnostics)
123-
d.project = p.project
124-
}
125-
126-
func (d *GoogleDnsManagedZoneDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
127-
var data GoogleDnsManagedZoneModel
128-
var metaData *ProviderMetaModel
129-
var diags diag.Diagnostics
69+
name := d.Get("name").(string)
70+
d.SetId(fmt.Sprintf("projects/%s/managedZones/%s", project, name))
13071

131-
// Read Provider meta into the meta model
132-
resp.Diagnostics.Append(req.ProviderMeta.Get(ctx, &metaData)...)
133-
if resp.Diagnostics.HasError() {
134-
return
72+
zone, err := config.NewDnsClient(userAgent).ManagedZones.Get(
73+
project, name).Do()
74+
if err != nil {
75+
return handleNotFoundError(err, d, fmt.Sprintf("dataSourceDnsManagedZone %q", name))
13576
}
13677

137-
d.client.UserAgent = generateFrameworkUserAgentString(metaData, d.client.UserAgent)
138-
139-
// Read Terraform configuration data into the model
140-
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
141-
if resp.Diagnostics.HasError() {
142-
return
78+
if err := d.Set("dns_name", zone.DnsName); err != nil {
79+
return fmt.Errorf("Error setting dns_name: %s", err)
14380
}
144-
145-
data.Project = getProjectFramework(data.Project, d.project, &resp.Diagnostics)
146-
if resp.Diagnostics.HasError() {
147-
return
81+
if err := d.Set("name", zone.Name); err != nil {
82+
return fmt.Errorf("Error setting name: %s", err)
14883
}
149-
150-
data.Id = types.StringValue(fmt.Sprintf("projects/%s/managedZones/%s", data.Project.ValueString(), data.Name.ValueString()))
151-
clientResp, err := d.client.ManagedZones.Get(data.Project.ValueString(), data.Name.ValueString()).Do()
152-
if err != nil {
153-
handleDatasourceNotFoundError(ctx, err, &resp.State, fmt.Sprintf("dataSourceDnsManagedZone %q", data.Name.ValueString()), &resp.Diagnostics)
84+
if err := d.Set("description", zone.Description); err != nil {
85+
return fmt.Errorf("Error setting description: %s", err)
15486
}
155-
156-
tflog.Trace(ctx, "read dns record set data source")
157-
158-
data.DnsName = types.StringValue(clientResp.DnsName)
159-
data.Description = types.StringValue(clientResp.Description)
160-
data.ManagedZoneId = types.Int64Value(int64(clientResp.Id))
161-
data.Visibility = types.StringValue(clientResp.Visibility)
162-
data.NameServers, diags = types.ListValueFrom(ctx, types.StringType, clientResp.NameServers)
163-
resp.Diagnostics.Append(diags...)
164-
if resp.Diagnostics.HasError() {
165-
return
87+
if err := d.Set("managed_zone_id", zone.Id); err != nil {
88+
return fmt.Errorf("Error setting managed_zone_id: %s", err)
89+
}
90+
if err := d.Set("name_servers", zone.NameServers); err != nil {
91+
return fmt.Errorf("Error setting name_servers: %s", err)
92+
}
93+
if err := d.Set("visibility", zone.Visibility); err != nil {
94+
return fmt.Errorf("Error setting visibility: %s", err)
95+
}
96+
if err := d.Set("project", project); err != nil {
97+
return fmt.Errorf("Error setting project: %s", err)
16698
}
16799

168-
// Save data into Terraform state
169-
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
100+
return nil
170101
}

google-beta/data_source_dns_managed_zone_test.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,23 @@ func TestAccDataSourceDnsManagedZone_basic(t *testing.T) {
1414

1515
vcrTest(t, resource.TestCase{
1616
PreCheck: func() { testAccPreCheck(t) },
17-
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducerFramework(t),
17+
Providers: testAccProviders,
18+
CheckDestroy: testAccCheckDNSManagedZoneDestroyProducer(t),
1819
Steps: []resource.TestStep{
1920
{
20-
ExternalProviders: providerVersion450(),
21-
Config: testAccDataSourceDnsManagedZone_basic(randString(t, 10)),
21+
Config: testAccDataSourceDnsManagedZone_basic(randString(t, 10)),
2222
Check: checkDataSourceStateMatchesResourceStateWithIgnores(
2323
"data.google_dns_managed_zone.qa",
2424
"google_dns_managed_zone.foo",
2525
map[string]struct{}{
26-
"dnssec_config.#": {},
27-
"private_visibility_config.#": {},
28-
"peering_config.#": {},
29-
"forwarding_config.#": {},
30-
"force_destroy": {},
31-
"labels.#": {},
32-
"creation_time": {},
33-
"cloud_logging_config.#": {},
34-
"cloud_logging_config.0.%": {},
35-
"cloud_logging_config.0.enable_logging": {},
36-
"reverse_lookup": {},
37-
},
38-
),
39-
},
40-
{
41-
ProtoV5ProviderFactories: protoV5ProviderFactories(t),
42-
Config: testAccDataSourceDnsManagedZone_basic(randString(t, 10)),
43-
Check: checkDataSourceStateMatchesResourceStateWithIgnores(
44-
"data.google_dns_managed_zone.qa",
45-
"google_dns_managed_zone.foo",
46-
map[string]struct{}{
47-
"dnssec_config.#": {},
48-
"private_visibility_config.#": {},
49-
"peering_config.#": {},
50-
"forwarding_config.#": {},
51-
"force_destroy": {},
52-
"labels.#": {},
53-
"creation_time": {},
54-
"cloud_logging_config.#": {},
55-
"cloud_logging_config.0.%": {},
56-
"cloud_logging_config.0.enable_logging": {},
57-
"reverse_lookup": {},
26+
"dnssec_config.#": {},
27+
"private_visibility_config.#": {},
28+
"peering_config.#": {},
29+
"forwarding_config.#": {},
30+
"force_destroy": {},
31+
"labels.#": {},
32+
"creation_time": {},
33+
"reverse_lookup": {},
5834
},
5935
),
6036
},

google-beta/framework_provider.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,6 @@ func (p *frameworkProvider) Configure(ctx context.Context, req provider.Configur
928928
// DataSources defines the data sources implemented in the provider.
929929
func (p *frameworkProvider) DataSources(_ context.Context) []func() datasource.DataSource {
930930
return []func() datasource.DataSource{
931-
NewGoogleDnsManagedZoneDataSource,
932931
NewGoogleDnsRecordSetDataSource,
933932
}
934933
}

google-beta/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ func Provider() *schema.Provider {
700700
"google_container_registry_repository": dataSourceGoogleContainerRepo(),
701701
"google_dataproc_metastore_service": dataSourceDataprocMetastoreService(),
702702
"google_dns_keys": dataSourceDNSKeys(),
703+
"google_dns_managed_zone": dataSourceDnsManagedZone(),
703704
"google_game_services_game_server_deployment_rollout": dataSourceGameServicesGameServerDeploymentRollout(),
704705
"google_iam_policy": dataSourceGoogleIamPolicy(),
705706
"google_iam_role": dataSourceGoogleIamRole(),

0 commit comments

Comments
 (0)