Skip to content

Commit

Permalink
Remove module version from Waypoint templates + add-ons.
Browse files Browse the repository at this point in the history
  • Loading branch information
paladin-devops committed Jul 30, 2024
1 parent f77e1c4 commit 464f8e5
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 272 deletions.
29 changes: 4 additions & 25 deletions internal/provider/waypoint/data_source_waypoint_add_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type AddOnDataSourceModel struct {
DefinitionID types.String `tfsdk:"definition_id"`
OutputValues types.List `tfsdk:"output_values"`

TerraformNoCodeModule types.Object `tfsdk:"terraform_no_code_module"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`

InputVars types.Set `tfsdk:"input_variables"`
}
Expand Down Expand Up @@ -121,19 +121,9 @@ func (d *DataSourceAddOn) Schema(ctx context.Context, req datasource.SchemaReque
Computed: true,
Description: "The ID of the Application that this Add-on is created for.",
},
"terraform_no_code_module": &schema.SingleNestedAttribute{
"terraform_no_code_module_source": schema.StringAttribute{
Computed: true,
Description: "Terraform Cloud no-code Module details.",
Attributes: map[string]schema.Attribute{
"source": &schema.StringAttribute{
Computed: true,
Description: "Terraform Cloud no-code Module Source",
},
"version": &schema.StringAttribute{
Computed: true,
Description: "Terraform Cloud no-code Module Version",
},
},
Description: "The Terraform module source for the Add-on.",
},
"status": schema.Int64Attribute{
Computed: true,
Expand Down Expand Up @@ -243,6 +233,7 @@ func (d *DataSourceAddOn) Read(ctx context.Context, req datasource.ReadRequest,
}

state.Summary = types.StringValue(addOn.Summary)
state.TerraformNoCodeModuleSource = types.StringValue(addOn.ModuleSource)

labels, diags := types.ListValueFrom(ctx, types.StringType, addOn.Labels)
resp.Diagnostics.Append(diags...)
Expand All @@ -254,18 +245,6 @@ func (d *DataSourceAddOn) Read(ctx context.Context, req datasource.ReadRequest,
}
state.Labels = labels

if addOn.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{
Source: types.StringValue(addOn.TerraformNocodeModule.Source),
Version: types.StringValue(addOn.TerraformNocodeModule.Version),
}
state.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}

// set plan.description if it's not null or addOn.description is not empty
state.Description = types.StringValue(addOn.Description)
if addOn.Description == "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type DataSourceAddOnDefinitionModel struct {
Description types.String `tfsdk:"description"`
ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"`

TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"`
TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`
TerraformVariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
}

func NewAddOnDefinitionDataSource() datasource.DataSource {
Expand Down Expand Up @@ -210,6 +210,7 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea
state.OrgID = types.StringValue(client.Config.OrganizationID)
state.ProjectID = types.StringValue(client.Config.ProjectID)
state.Summary = types.StringValue(definition.Summary)
state.Description = types.StringValue(definition.Description)

if definition.TerraformCloudWorkspaceDetails != nil {
tfcWorkspace := &tfcWorkspace{
Expand All @@ -219,14 +220,6 @@ func (d *DataSourceAddOnDefinition) Read(ctx context.Context, req datasource.Rea
state.TerraformCloudWorkspace = tfcWorkspace
}

if definition.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{
Source: types.StringValue(definition.TerraformNocodeModule.Source),
Version: types.StringValue(definition.TerraformNocodeModule.Version),
}
state.TerraformNoCodeModule = tfcNoCode
}

labels, diags := types.ListValueFrom(ctx, types.StringType, definition.Labels)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand Down
29 changes: 6 additions & 23 deletions internal/provider/waypoint/data_source_waypoint_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type DataSourceTemplateModel struct {
Description types.String `tfsdk:"description"`
ReadmeMarkdownTemplate types.String `tfsdk:"readme_markdown_template"`

TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModule *tfcNoCodeModule `tfsdk:"terraform_no_code_module"`
VariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
TerraformCloudWorkspace *tfcWorkspace `tfsdk:"terraform_cloud_workspace_details"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`
VariableOptions []*tfcVariableOption `tfsdk:"variable_options"`
}

func NewTemplateDataSource() datasource.DataSource {
Expand Down Expand Up @@ -111,19 +111,9 @@ func (d *DataSourceTemplate) Schema(ctx context.Context, req datasource.SchemaRe
},
},
},
"terraform_no_code_module": &schema.SingleNestedAttribute{
"terraform_no_code_module_source": &schema.SingleNestedAttribute{
Computed: true,
Description: "Terraform Cloud No-Code Module details",
Attributes: map[string]schema.Attribute{
"source": &schema.StringAttribute{
Computed: true,
Description: "No-Code Module Source",
},
"version": &schema.StringAttribute{
Computed: true,
Description: "No-Code Module Version",
},
},
Description: "Terraform No Code Module source",
},
"variable_options": schema.ListNestedAttribute{
Computed: true,
Expand Down Expand Up @@ -210,6 +200,7 @@ func (d *DataSourceTemplate) Read(ctx context.Context, req datasource.ReadReques
data.OrgID = types.StringValue(client.Config.OrganizationID)
data.ProjectID = types.StringValue(client.Config.ProjectID)
data.Summary = types.StringValue(appTemplate.Summary)
data.TerraformNoCodeModuleSource = types.StringValue(appTemplate.ModuleSource)

if appTemplate.TerraformCloudWorkspaceDetails != nil {
tfcWorkspace := &tfcWorkspace{
Expand All @@ -219,14 +210,6 @@ func (d *DataSourceTemplate) Read(ctx context.Context, req datasource.ReadReques
data.TerraformCloudWorkspace = tfcWorkspace
}

if appTemplate.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{
Source: types.StringValue(appTemplate.TerraformNocodeModule.Source),
Version: types.StringValue(appTemplate.TerraformNocodeModule.Version),
}
data.TerraformNoCodeModule = tfcNoCode
}

data.VariableOptions, err = readVarOpts(ctx, appTemplate.VariableOptions, &resp.Diagnostics)
if err != nil {
tflog.Error(ctx, err.Error())
Expand Down
67 changes: 7 additions & 60 deletions internal/provider/waypoint/resource_waypoint_add_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type AddOnResourceModel struct {
DefinitionID types.String `tfsdk:"definition_id"`
OutputValues types.List `tfsdk:"output_values"`

TerraformNoCodeModule types.Object `tfsdk:"terraform_no_code_module"`
TerraformNoCodeModuleSource types.String `tfsdk:"terraform_no_code_module_source"`

InputVars types.Set `tfsdk:"add_on_input_variables"`
AddOnDefinitionInputVars types.Set `tfsdk:"add_on_definition_input_variables"`
Expand All @@ -75,13 +75,6 @@ func (o outputValue) attrTypes() map[string]attr.Type {
}
}

func (r tfcNoCodeModule) attrTypes() map[string]attr.Type {
return map[string]attr.Type{
"source": types.StringType,
"version": types.StringType,
}
}

func (r *AddOnResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_waypoint_add_on"
}
Expand Down Expand Up @@ -148,19 +141,9 @@ func (r *AddOnResource) Schema(ctx context.Context, req resource.SchemaRequest,
"Add-on Definition.",
Computed: true,
},
"terraform_no_code_module": &schema.SingleNestedAttribute{
"terraform_no_code_module_source": schema.StringAttribute{
Description: "The Terraform No Code Module source for the Add-on.",
Computed: true,
Description: "Terraform Cloud no-code Module details.",
Attributes: map[string]schema.Attribute{
"source": &schema.StringAttribute{
Computed: true,
Description: "Terraform Cloud no-code Module Source",
},
"version": &schema.StringAttribute{
Computed: true,
Description: "Terraform Cloud no-code Module Version",
},
},
},
"definition_id": schema.StringAttribute{
Required: true,
Expand Down Expand Up @@ -391,8 +374,9 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest,
plan.ProjectID = types.StringValue(projectID)
plan.OrgID = types.StringValue(orgID)
plan.Summary = types.StringValue(addOn.Summary)

plan.Description = types.StringValue(addOn.Description)
plan.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source)

// set plan.description if it's not null or addOn.description is not empty
if addOn.Description == "" {
plan.Description = types.StringNull()
Expand All @@ -410,21 +394,6 @@ func (r *AddOnResource) Create(ctx context.Context, req resource.CreateRequest,
}
plan.Labels = labels

if addOn.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{}
if addOn.TerraformNocodeModule.Source != "" {
tfcNoCode.Source = types.StringValue(addOn.TerraformNocodeModule.Source)
}
if addOn.TerraformNocodeModule.Version != "" {
tfcNoCode.Version = types.StringValue(addOn.TerraformNocodeModule.Version)
}
plan.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}

// Display the reference to the Definition in the plan
if addOn.Definition != nil {
if addOn.Definition.ID != "" {
Expand Down Expand Up @@ -557,6 +526,7 @@ func (r *AddOnResource) Read(ctx context.Context, req resource.ReadRequest, resp
state.ProjectID = types.StringValue(projectID)
state.OrgID = types.StringValue(orgID)
state.Summary = types.StringValue(addOn.Summary)
state.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source)

state.Description = types.StringValue(addOn.Description)
// set plan.description if it's not null or addOn.description is not empty
Expand All @@ -576,18 +546,6 @@ func (r *AddOnResource) Read(ctx context.Context, req resource.ReadRequest, resp
}
state.Labels = labels

if addOn.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{
Source: types.StringValue(addOn.TerraformNocodeModule.Source),
Version: types.StringValue(addOn.TerraformNocodeModule.Version),
}
state.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}

state.CreatedBy = types.StringValue(addOn.CreatedBy)

// If we can process status as an int64, add it to the plan
Expand Down Expand Up @@ -719,6 +677,7 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest,
plan.ProjectID = types.StringValue(projectID)
plan.OrgID = types.StringValue(orgID)
plan.Summary = types.StringValue(addOn.Summary)
plan.TerraformNoCodeModuleSource = types.StringValue(addOn.TerraformNocodeModule.Source)

plan.Description = types.StringValue(addOn.Description)
// set plan.description if it's not null or addOn.description is not empty
Expand All @@ -738,18 +697,6 @@ func (r *AddOnResource) Update(ctx context.Context, req resource.UpdateRequest,
}
plan.Labels = labels

if addOn.TerraformNocodeModule != nil {
tfcNoCode := &tfcNoCodeModule{
Source: types.StringValue(addOn.TerraformNocodeModule.Source),
Version: types.StringValue(addOn.TerraformNocodeModule.Version),
}
plan.TerraformNoCodeModule, diags = types.ObjectValueFrom(ctx, tfcNoCode.attrTypes(), tfcNoCode)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
}

// Display the reference to the Definition in the plan
if addOn.Definition != nil {
if addOn.Definition.ID != "" {
Expand Down
Loading

0 comments on commit 464f8e5

Please sign in to comment.