Skip to content

Commit

Permalink
Merge branch 'main' into tls_retirement/redis
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Jan 10, 2025
2 parents ee6a66d + 4f9ea9c commit 71a62b3
Show file tree
Hide file tree
Showing 147 changed files with 3,114 additions and 807 deletions.
34 changes: 27 additions & 7 deletions .github/workflows/auto-assign-reviewers-to-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
name: Assign Reviewer as Assignee

on:
pull_request_review:
workflow_run:
workflows:
- "Pull Request Reviewed"
types:
- submitted
- completed

permissions:
issues: write
Expand All @@ -13,20 +15,38 @@ jobs:
assign_reviewer:
runs-on: ubuntu-latest
steps:
- name: Get Artifact
id: get_artifact
continue-on-error: true
uses: dawidd6/action-download-artifact@09f2f74827fd3a8607589e5ad7f9398816f540fe # v3.1.4
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: pull-request-reviewed.yaml

- name: env_vars
id: env_vars
if: steps.get_artifact.outcome == 'success'
run: |
echo "reviewer=$(cat artifact/reviewer.txt)" >>${GITHUB_OUTPUT}
echo "reviewState=$(cat artifact/reviewstate.txt)" >>${GITHUB_OUTPUT}
echo "prNumber=$(cat artifact/prnumber.txt)" >>${GITHUB_OUTPUT}
- name: Assign the reviewer as assignee when changes are requested
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const reviewer = context.payload.review.user.login;
const prNumber = context.payload.pull_request.number;
const reviewState = context.payload.review.state;
const reviewer = '${{ steps.env_vars.outputs.reviewer }}';
const prNumber = parseInt('${{ steps.env_vars.outputs.prNumber }}', 10);
const reviewState = '${{ steps.env_vars.outputs.reviewState }}';
const repo = '${{ github.event.repository.name }}';
const owner = '${{ github.event.repository.owner.login }}';
if (reviewState === 'changes_requested') {
console.log(`Assigning reviewer: ${reviewer} to PR #${prNumber} as changes were requested.`);
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
owner: owner,
repo: repo,
issue_number: prNumber,
assignees: [reviewer],
});
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/pull-request-reviewed.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,26 @@ jobs:
add-or-remove-waiting-response:
runs-on: ubuntu-latest
steps:
- name: "Set Artifacts for add-waiting-response"
if: github.event.review.state != 'approved' && github.actor != github.event.pull_request.user.login
- name: "Set Artifacts"
shell: bash
run: |
mkdir -p wr_actions
echo ${{ github.owner }} > wr_actions/ghowner.txt
echo ${{ github.repository }} > wr_actions/ghrepo.txt
echo ${{ github.event.pull_request.number }} > wr_actions/prnumber.txt
echo ${{ github.event.review.user.login }} > wr_actions/reviewer.txt
echo ${{ github.event.review.state }} > wr_actions/reviewstate.txt
- name: "Set Artifacts for add-waiting-response"
if: github.event.review.state != 'approved' && github.actor != github.event.pull_request.user.login
shell: bash
run: |
mkdir -p wr_actions
echo "add-waiting-response" > wr_actions/action.txt
- name: "Set Artifacts for remove-waiting-response"
if: github.actor == github.event.pull_request.user.login
shell: bash
run: |
mkdir -p wr_actions
echo ${{ github.owner }} > wr_actions/ghowner.txt
echo ${{ github.repository }} > wr_actions/ghrepo.txt
echo ${{ github.event.pull_request.number }} > wr_actions/prnumber.txt
echo "remove-waiting-response" > wr_actions/action.txt
- uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
Expand Down
1 change: 1 addition & 0 deletions internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func SupportedTypedServices() []sdk.TypedServiceRegistration {
dataprotection.Registration{},
desktopvirtualization.Registration{},
digitaltwins.Registration{},
dns.Registration{},
domainservices.Registration{},
dynatrace.Registration{},
elasticsan.Registration{},
Expand Down
14 changes: 14 additions & 0 deletions internal/services/appservice/static_web_app_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ type StaticWebAppDataSourceModel struct {
SkuTier string `tfschema:"sku_tier"`
SkuSize string `tfschema:"sku_size"`
Tags map[string]string `tfschema:"tags"`
RepositoryUrl string `tfschema:"repository_url"`
RepositoryBranch string `tfschema:"repository_branch"`
}

func (s StaticWebAppDataSource) Arguments() map[string]*pluginsdk.Schema {
Expand Down Expand Up @@ -109,6 +111,16 @@ func (s StaticWebAppDataSource) Attributes() map[string]*pluginsdk.Schema {
Computed: true,
},

"repository_url": {
Type: pluginsdk.TypeString,
Computed: true,
},

"repository_branch": {
Type: pluginsdk.TypeString,
Computed: true,
},

"tags": tags.SchemaDataSource(),
}
}
Expand Down Expand Up @@ -157,6 +169,8 @@ func (s StaticWebAppDataSource) Read() sdk.ResourceFunc {
state.ConfigFileChanges = pointer.From(props.AllowConfigFileUpdates)
state.DefaultHostName = pointer.From(props.DefaultHostname)
state.PreviewEnvironments = pointer.From(props.StagingEnvironmentPolicy) == staticsites.StagingEnvironmentPolicyEnabled
state.RepositoryUrl = pointer.From(props.RepositoryURL)
state.RepositoryBranch = pointer.From(props.Branch)
state.PublicNetworkAccess = !strings.EqualFold(pointer.From(props.PublicNetworkAccess), helpers.PublicNetworkAccessDisabled)
}

Expand Down
48 changes: 48 additions & 0 deletions internal/services/appservice/static_web_app_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type StaticWebAppResourceModel struct {

ApiKey string `tfschema:"api_key"`
DefaultHostName string `tfschema:"default_host_name"`

RepositoryUrl string `tfschema:"repository_url"`
RepositoryToken string `tfschema:"repository_token"`
RepositoryBranch string `tfschema:"repository_branch"`
}

func (r StaticWebAppResource) Arguments() map[string]*pluginsdk.Schema {
Expand Down Expand Up @@ -112,6 +116,28 @@ func (r StaticWebAppResource) Arguments() map[string]*pluginsdk.Schema {

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"repository_url": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.IsURLWithHTTPorHTTPS,
RequiredWith: []string{"repository_token", "repository_branch"},
},

"repository_token": {
Type: pluginsdk.TypeString,
Optional: true,
Sensitive: true,
ValidateFunc: validation.StringIsNotEmpty,
RequiredWith: []string{"repository_url", "repository_branch"},
},

"repository_branch": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsNotEmpty,
RequiredWith: []string{"repository_url", "repository_token"},
},

"tags": tags.Schema(),
}
}
Expand Down Expand Up @@ -196,6 +222,13 @@ func (r StaticWebAppResource) Create() sdk.ResourceFunc {
props.StagingEnvironmentPolicy = pointer.To(staticsites.StagingEnvironmentPolicyDisabled)
}

// Check if repository URL, branch, or token are set
if model.RepositoryUrl != "" || model.RepositoryBranch != "" || model.RepositoryToken != "" {
props.Branch = pointer.To(model.RepositoryBranch)
props.RepositoryURL = pointer.To(model.RepositoryUrl)
props.RepositoryToken = pointer.To(model.RepositoryToken)
}

if !model.PublicNetworkAccess {
props.PublicNetworkAccess = pointer.To(helpers.PublicNetworkAccessDisabled)
}
Expand Down Expand Up @@ -279,6 +312,15 @@ func (r StaticWebAppResource) Read() sdk.ResourceFunc {
state.ConfigFileChanges = pointer.From(props.AllowConfigFileUpdates)
state.DefaultHostName = pointer.From(props.DefaultHostname)
state.PreviewEnvironments = pointer.From(props.StagingEnvironmentPolicy) == staticsites.StagingEnvironmentPolicyEnabled

state.RepositoryUrl = pointer.From(props.RepositoryURL)
state.RepositoryBranch = pointer.From(props.Branch)

// Token isn't returned in the response, so we need to grab it from the config
if repositoryToken, ok := metadata.ResourceData.GetOk("repository_token"); ok {
state.RepositoryToken = repositoryToken.(string)
}

state.PublicNetworkAccess = !strings.EqualFold(pointer.From(props.PublicNetworkAccess), helpers.PublicNetworkAccessDisabled)
}

Expand Down Expand Up @@ -454,6 +496,12 @@ func (r StaticWebAppResource) Update() sdk.ResourceFunc {
}
}

if metadata.ResourceData.HasChanges("repository_url", "repository_branch", "repository_token") {
model.Properties.RepositoryURL = pointer.To(config.RepositoryUrl)
model.Properties.Branch = pointer.To(config.RepositoryBranch)
model.Properties.RepositoryToken = pointer.To(config.RepositoryToken)
}

return nil
},
}
Expand Down
7 changes: 7 additions & 0 deletions internal/services/cdn/cdn_frontdoor_profile_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
Expand All @@ -35,6 +36,8 @@ func dataSourceCdnFrontDoorProfile() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"response_timeout_seconds": {
Type: pluginsdk.TypeInt,
Computed: true,
Expand Down Expand Up @@ -81,6 +84,10 @@ func dataSourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface
d.Set("sku_name", string(pointer.From(skuName)))
}

if identity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity); err == nil {
d.Set("identity", identity)
}

if props := model.Properties; props != nil {
d.Set("response_timeout_seconds", int(pointer.From(props.OriginResponseTimeoutSeconds)))

Expand Down
75 changes: 75 additions & 0 deletions internal/services/cdn/cdn_frontdoor_profile_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,51 @@ func TestAccCdnFrontDoorProfileDataSource_basic(t *testing.T) {
})
}

func TestAccCdnFrontDoorProfileDataSource_basicWithSystemIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test")
d := CdnFrontDoorProfileDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basicWithSystemIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"),
check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned"),
),
},
})
}

func TestAccCdnFrontDoorProfileDataSource_basicWithUserIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test")
d := CdnFrontDoorProfileDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basicWithUserIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"),
check.That(data.ResourceName).Key("identity.0.type").HasValue("UserAssigned"),
),
},
})
}

func TestAccCdnFrontDoorProfileDataSource_basicWithSystemAndUserIdentity(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_cdn_frontdoor_profile", "test")
d := CdnFrontDoorProfileDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basicWithSystemAndUserIdentity(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("sku_name").HasValue("Standard_AzureFrontDoor"),
check.That(data.ResourceName).Key("identity.0.type").HasValue("SystemAssigned, UserAssigned"),
),
},
})
}

func (CdnFrontDoorProfileDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand All @@ -37,3 +82,33 @@ data "azurerm_cdn_frontdoor_profile" "test" {
}
`, CdnFrontDoorProfileResource{}.complete(data))
}

func (CdnFrontDoorProfileDataSource) basicWithSystemIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_cdn_frontdoor_profile" "test" {
name = azurerm_cdn_frontdoor_profile.test.name
resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name
}
`, CdnFrontDoorProfileResource{}.basicWithSystemIdentity(data))
}

func (CdnFrontDoorProfileDataSource) basicWithUserIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_cdn_frontdoor_profile" "test" {
name = azurerm_cdn_frontdoor_profile.test.name
resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name
}
`, CdnFrontDoorProfileResource{}.basicWithUserIdentity(data))
}

func (CdnFrontDoorProfileDataSource) basicWithSystemAndUserIdentity(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_cdn_frontdoor_profile" "test" {
name = azurerm_cdn_frontdoor_profile.test.name
resource_group_name = azurerm_cdn_frontdoor_profile.test.resource_group_name
}
`, CdnFrontDoorProfileResource{}.basicWithSystemAndUserIdentity(data))
}
30 changes: 30 additions & 0 deletions internal/services/cdn/cdn_frontdoor_profile_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/identity"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/cdn/2024-02-01/profiles"
Expand Down Expand Up @@ -50,6 +51,8 @@ func resourceCdnFrontDoorProfile() *pluginsdk.Resource {

"resource_group_name": commonschema.ResourceGroupName(),

"identity": commonschema.SystemAssignedUserAssignedIdentityOptional(),

"response_timeout_seconds": {
Type: pluginsdk.TypeInt,
Optional: true,
Expand Down Expand Up @@ -107,6 +110,15 @@ func resourceCdnFrontDoorProfileCreate(d *pluginsdk.ResourceData, meta interface
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

if v, ok := d.GetOk("identity"); ok {
i, err := identity.ExpandSystemAndUserAssignedMap(v.([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}

props.Identity = i
}

err = client.CreateThenPoll(ctx, id, props)
if err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
Expand Down Expand Up @@ -143,6 +155,15 @@ func resourceCdnFrontDoorProfileRead(d *pluginsdk.ResourceData, meta interface{}
d.Set("sku_name", string(pointer.From(skuName)))
}

identity, err := identity.FlattenSystemAndUserAssignedMap(model.Identity)
if err != nil {
return fmt.Errorf("flattening `identity`: %+v", err)
}

if err := d.Set("identity", identity); err != nil {
return fmt.Errorf("setting `identity`: %+v", err)
}

if props := model.Properties; props != nil {
d.Set("response_timeout_seconds", int(pointer.From(props.OriginResponseTimeoutSeconds)))

Expand Down Expand Up @@ -178,6 +199,15 @@ func resourceCdnFrontDoorProfileUpdate(d *pluginsdk.ResourceData, meta interface
props.Properties.OriginResponseTimeoutSeconds = pointer.To(int64(d.Get("response_timeout_seconds").(int)))
}

if d.HasChange("identity") {
i, err := identity.ExpandSystemAndUserAssignedMap(d.Get("identity").([]interface{}))
if err != nil {
return fmt.Errorf("expanding `identity`: %+v", err)
}

props.Identity = i
}

err = client.UpdateThenPoll(ctx, pointer.From(id), props)
if err != nil {
return fmt.Errorf("updating %s: %+v", *id, err)
Expand Down
Loading

0 comments on commit 71a62b3

Please sign in to comment.