-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Adds new ip_addresses
computed attribute in mongodbatlas_project
resource and data sources
#1850
feat: Adds new ip_addresses
computed attribute in mongodbatlas_project
resource and data sources
#1850
Changes from all commits
11603af
374446e
0d259a6
71971b1
9a3b82b
d188935
fba3e23
c6329c1
3e2c1ef
7daa450
56a8830
ba4c763
ffed367
39491e4
a422d90
a857967
605705b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,15 +30,16 @@ type projectDS struct { | |
config.DSCommon | ||
} | ||
|
||
type TfProjectDSModel struct { | ||
RegionUsageRestrictions types.String `tfsdk:"region_usage_restrictions"` | ||
ProjectID types.String `tfsdk:"project_id"` | ||
Name types.String `tfsdk:"name"` | ||
OrgID types.String `tfsdk:"org_id"` | ||
type TFProjectDSModel struct { | ||
IPAddresses types.Object `tfsdk:"ip_addresses"` | ||
Created types.String `tfsdk:"created"` | ||
OrgID types.String `tfsdk:"org_id"` | ||
RegionUsageRestrictions types.String `tfsdk:"region_usage_restrictions"` | ||
ID types.String `tfsdk:"id"` | ||
Limits []*TfLimitModel `tfsdk:"limits"` | ||
Teams []*TfTeamDSModel `tfsdk:"teams"` | ||
Name types.String `tfsdk:"name"` | ||
ProjectID types.String `tfsdk:"project_id"` | ||
Teams []*TFTeamDSModel `tfsdk:"teams"` | ||
Limits []*TFLimitModel `tfsdk:"limits"` | ||
ClusterCount types.Int64 `tfsdk:"cluster_count"` | ||
IsCollectDatabaseSpecificsStatisticsEnabled types.Bool `tfsdk:"is_collect_database_specifics_statistics_enabled"` | ||
IsRealtimePerformancePanelEnabled types.Bool `tfsdk:"is_realtime_performance_panel_enabled"` | ||
|
@@ -48,7 +49,7 @@ type TfProjectDSModel struct { | |
IsDataExplorerEnabled types.Bool `tfsdk:"is_data_explorer_enabled"` | ||
} | ||
|
||
type TfTeamDSModel struct { | ||
type TFTeamDSModel struct { | ||
TeamID types.String `tfsdk:"team_id"` | ||
RoleNames types.List `tfsdk:"role_names"` | ||
} | ||
|
@@ -137,12 +138,40 @@ func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, re | |
}, | ||
}, | ||
}, | ||
"ip_addresses": schema.SingleNestedAttribute{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can something be used from project_ip_access_list resource/ds or they're different concepts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They seem to be different concepts. From testing I can see that it provides the IP address of each cluster node. This scope document gives some more details as to users that would leverage these ip addresses |
||
Computed: true, | ||
Attributes: map[string]schema.Attribute{ | ||
"services": schema.SingleNestedAttribute{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is services adding as opposed to not having it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I am sticking to the structure defined in the API. From the scope doc:
I believe sticking to this structure will avoid breaking changes in the future as more services are added. Also synced with Zuhair on this in the jira comments. |
||
Computed: true, | ||
Attributes: map[string]schema.Attribute{ | ||
"clusters": schema.ListNestedAttribute{ | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems like IP addresses are associated to clusters in the project? wouldn't it make more sense then that IP addresses are returned in the clustest/adv_cluster resource instead of project? or in addition to be returned in project? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This a fair point. The main reason I see for including in the project resource is due to the endpoint being tagged in the project section (https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Projects/operation/returnAllIPAddresses). |
||
Attributes: map[string]schema.Attribute{ | ||
"cluster_name": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"inbound": schema.ListAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
"outbound": schema.ListAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var projectState TfProjectDSModel | ||
var projectState TFProjectDSModel | ||
connV2 := d.Client.AtlasV2 | ||
|
||
resp.Diagnostics.Append(req.Config.Get(ctx, &projectState)...) | ||
|
@@ -173,15 +202,19 @@ func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp * | |
} | ||
} | ||
|
||
atlasTeams, atlasLimits, atlasProjectSettings, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) | ||
projectProps, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) | ||
if err != nil { | ||
resp.Diagnostics.AddError("error when getting project properties", fmt.Sprintf(ErrorProjectRead, project.GetId(), err.Error())) | ||
return | ||
} | ||
|
||
projectState = NewTFProjectDataSourceModel(ctx, project, atlasTeams, atlasProjectSettings, atlasLimits) | ||
newProjectState, diags := NewTFProjectDataSourceModel(ctx, project, *projectProps) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
resp.Diagnostics.Append(resp.State.Set(ctx, &projectState)...) | ||
resp.Diagnostics.Append(resp.State.Set(ctx, &newProjectState)...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion" | ||
|
@@ -32,7 +33,7 @@ type ProjectsDS struct { | |
|
||
type tfProjectsDSModel struct { | ||
ID types.String `tfsdk:"id"` | ||
Results []*TfProjectDSModel `tfsdk:"results"` | ||
Results []*TFProjectDSModel `tfsdk:"results"` | ||
PageNum types.Int64 `tfsdk:"page_num"` | ||
ItemsPerPage types.Int64 `tfsdk:"items_per_page"` | ||
TotalCount types.Int64 `tfsdk:"total_count"` | ||
|
@@ -134,6 +135,34 @@ func (d *ProjectsDS) Schema(ctx context.Context, req datasource.SchemaRequest, r | |
}, | ||
}, | ||
}, | ||
"ip_addresses": schema.SingleNestedAttribute{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can some part of the schema be reused from the RS or it's hard because here all are Computed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main limitation is that they are different schema types, |
||
Computed: true, | ||
Attributes: map[string]schema.Attribute{ | ||
"services": schema.SingleNestedAttribute{ | ||
Computed: true, | ||
Attributes: map[string]schema.Attribute{ | ||
"clusters": schema.ListNestedAttribute{ | ||
Computed: true, | ||
NestedObject: schema.NestedAttributeObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"cluster_name": schema.StringAttribute{ | ||
Computed: true, | ||
}, | ||
"inbound": schema.ListAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
"outbound": schema.ListAttribute{ | ||
ElementType: types.StringType, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
|
@@ -157,9 +186,9 @@ func (d *ProjectsDS) Read(ctx context.Context, req datasource.ReadRequest, resp | |
return | ||
} | ||
|
||
err = populateProjectsDataSourceModel(ctx, connV2, &stateModel, projectsRes) | ||
if err != nil { | ||
resp.Diagnostics.AddError("error in monogbatlas_projects data source", err.Error()) | ||
diags := populateProjectsDataSourceModel(ctx, connV2, &stateModel, projectsRes) | ||
resp.Diagnostics.Append(diags...) | ||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
|
@@ -169,19 +198,23 @@ func (d *ProjectsDS) Read(ctx context.Context, req datasource.ReadRequest, resp | |
} | ||
} | ||
|
||
func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClient, stateModel *tfProjectsDSModel, projectsRes *admin.PaginatedAtlasGroup) error { | ||
func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClient, stateModel *tfProjectsDSModel, projectsRes *admin.PaginatedAtlasGroup) diag.Diagnostics { | ||
diagnostics := []diag.Diagnostic{} | ||
input := projectsRes.GetResults() | ||
results := make([]*TfProjectDSModel, 0, len(input)) | ||
results := make([]*TFProjectDSModel, 0, len(input)) | ||
for i := range input { | ||
project := input[i] | ||
atlasTeams, atlasLimits, atlasProjectSettings, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) | ||
projectProps, err := GetProjectPropsFromAPI(ctx, ServiceFromClient(connV2), project.GetId()) | ||
if err == nil { // if the project is still valid, e.g. could have just been deleted | ||
projectModel := NewTFProjectDataSourceModel(ctx, &project, atlasTeams, atlasProjectSettings, atlasLimits) | ||
results = append(results, &projectModel) | ||
projectModel, diags := NewTFProjectDataSourceModel(ctx, &project, *projectProps) | ||
diagnostics = append(diagnostics, diags...) | ||
if projectModel != nil { | ||
results = append(results, projectModel) | ||
} | ||
} | ||
} | ||
stateModel.Results = results | ||
stateModel.TotalCount = types.Int64Value(int64(projectsRes.GetTotalCount())) | ||
stateModel.ID = types.StringValue(id.UniqueId()) | ||
return nil | ||
return diagnostics | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mockery config file was not working as expected, only the last package (in this case
advancedcluster
) was used for generating mocks.