Skip to content
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

r/aws_grafana_workspace: Allow in-place version updates #32679

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32679.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_grafana_workspace: Allow `grafana_version` to be updated in-place
```
2 changes: 1 addition & 1 deletion internal/service/grafana/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func waitWorkspaceCreated(ctx context.Context, conn *managedgrafana.ManagedGrafa

func waitWorkspaceUpdated(ctx context.Context, conn *managedgrafana.ManagedGrafana, id string, timeout time.Duration) (*managedgrafana.WorkspaceDescription, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: []string{managedgrafana.WorkspaceStatusUpdating},
Pending: []string{managedgrafana.WorkspaceStatusUpdating, managedgrafana.WorkspaceStatusVersionUpdating},
Target: []string{managedgrafana.WorkspaceStatusActive},
Refresh: statusWorkspaceStatus(ctx, conn, id),
Timeout: timeout,
Expand Down
56 changes: 28 additions & 28 deletions internal/service/grafana/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ func ResourceWorkspace() *schema.Resource {
},
"grafana_version": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Computed: true,
},
Expand Down Expand Up @@ -212,12 +211,16 @@ func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta i
input.WorkspaceDescription = aws.String(v.(string))
}

if v, ok := d.GetOk("grafana_version"); ok {
input.GrafanaVersion = aws.String(v.(string))
}

if v, ok := d.GetOk("name"); ok {
input.WorkspaceName = aws.String(v.(string))
}

if v, ok := d.GetOk("grafana_version"); ok {
input.GrafanaVersion = aws.String(v.(string))
if v, ok := d.GetOk("network_access_control"); ok {
input.NetworkAccessControl = expandNetworkAccessControl(v.([]interface{}))
}

if v, ok := d.GetOk("notification_destinations"); ok {
Expand All @@ -244,11 +247,6 @@ func resourceWorkspaceCreate(ctx context.Context, d *schema.ResourceData, meta i
input.VpcConfiguration = expandVPCConfiguration(v.([]interface{}))
}

if v, ok := d.GetOk("network_access_control"); ok {
input.NetworkAccessControl = expandNetworkAccessControl(v.([]interface{}))
}

log.Printf("[DEBUG] Creating Grafana Workspace: %s", input)
output, err := conn.CreateWorkspaceWithContext(ctx, input)

if err != nil {
Expand Down Expand Up @@ -296,22 +294,20 @@ func resourceWorkspaceRead(ctx context.Context, d *schema.ResourceData, meta int
d.Set("endpoint", workspace.Endpoint)
d.Set("grafana_version", workspace.GrafanaVersion)
d.Set("name", workspace.Name)
if err := d.Set("network_access_control", flattenNetworkAccessControl(workspace.NetworkAccessControl)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting network_access_control: %s", err)
}
d.Set("notification_destinations", workspace.NotificationDestinations)
d.Set("organization_role_name", workspace.OrganizationRoleName)
d.Set("organizational_units", workspace.OrganizationalUnits)
d.Set("permission_type", workspace.PermissionType)
d.Set("role_arn", workspace.WorkspaceRoleArn)
d.Set("saml_configuration_status", workspace.Authentication.SamlConfigurationStatus)
d.Set("stack_set_name", workspace.StackSetName)

if err := d.Set("vpc_configuration", flattenVPCConfiguration(workspace.VpcConfiguration)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting vpc_configuration: %s", err)
}

if err := d.Set("network_access_control", flattenNetworkAccessControl(workspace.NetworkAccessControl)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting network_access_control: %s", err)
}

setTagsOut(ctx, workspace.Tags)

input := &managedgrafana.DescribeWorkspaceConfigurationInput{
Expand All @@ -321,7 +317,7 @@ func resourceWorkspaceRead(ctx context.Context, d *schema.ResourceData, meta int
output, err := conn.DescribeWorkspaceConfigurationWithContext(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Grafana Workspace (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "reading Grafana Workspace (%s) configuration: %s", d.Id(), err)
}

d.Set("configuration", output.Configuration)
Expand All @@ -333,7 +329,7 @@ func resourceWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, meta i
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).GrafanaConn(ctx)

if d.HasChangesExcept("configuration", "tags", "tags_all") {
if d.HasChangesExcept("configuration", "grafana_version", "tags", "tags_all") {
input := &managedgrafana.UpdateWorkspaceInput{
WorkspaceId: aws.String(d.Id()),
}
Expand All @@ -354,6 +350,16 @@ func resourceWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, meta i
input.WorkspaceName = aws.String(d.Get("name").(string))
}

if d.HasChange("network_access_control") {
if v, ok := d.Get("network_access_control").([]interface{}); ok {
if len(v) > 0 {
input.NetworkAccessControl = expandNetworkAccessControl(v)
} else {
input.RemoveNetworkAccessConfiguration = aws.Bool(true)
}
}
}

if d.HasChange("notification_destinations") {
input.WorkspaceNotificationDestinations = flex.ExpandStringList(d.Get("notification_destinations").([]interface{}))
}
Expand Down Expand Up @@ -388,16 +394,6 @@ func resourceWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, meta i
}
}

if d.HasChange("network_access_control") {
if v, ok := d.Get("network_access_control").([]interface{}); ok {
if len(v) > 0 {
input.NetworkAccessControl = expandNetworkAccessControl(v)
} else {
input.RemoveNetworkAccessConfiguration = aws.Bool(true)
}
}
}

_, err := conn.UpdateWorkspaceWithContext(ctx, input)

if err != nil {
Expand All @@ -409,10 +405,14 @@ func resourceWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, meta i
}
}

if d.HasChange("configuration") {
if d.HasChanges("configuration", "grafana_version") {
input := &managedgrafana.UpdateWorkspaceConfigurationInput{
WorkspaceId: aws.String(d.Id()),
Configuration: aws.String(d.Get("configuration").(string)),
WorkspaceId: aws.String(d.Id()),
}

if d.HasChange("grafana_version") {
input.GrafanaVersion = aws.String(d.Get("grafana_version").(string))
}

_, err := conn.UpdateWorkspaceConfigurationWithContext(ctx, input)
Expand All @@ -422,7 +422,7 @@ func resourceWorkspaceUpdate(ctx context.Context, d *schema.ResourceData, meta i
}

if _, err := waitWorkspaceUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return sdkdiag.AppendErrorf(diags, "updating Grafana Workspace (%s) configuration: waiting for completion: %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "waiting for Grafana Workspace (%s) configuration update: %s", d.Id(), err)
}
}

Expand Down
1 change: 0 additions & 1 deletion internal/service/grafana/workspace_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func testAccWorkspaceDataSource_basic(t *testing.T) {
{
Config: testAccWorkspaceDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckWorkspaceExists(ctx, dataSourceName),
resource.TestCheckResourceAttrPair(resourceName, "account_access_type", dataSourceName, "account_access_type"),
resource.TestCheckResourceAttrPair(resourceName, "arn", dataSourceName, "arn"),
resource.TestCheckResourceAttrPair(resourceName, "authentication_providers.#", dataSourceName, "authentication_providers.#"),
Expand Down
Loading
Loading